Silverlight 4:ChildWindow 在 2 次查看/隐藏操作后禁用 UserControl
我面临一个非常不寻常的问题,我有一个 UserControl,它显示 ChildWindow 在此 ChildWindow 上执行一些操作,我在完成操作后将其关闭,然后(比如说)再次打开它,它工作正常,但是一旦我关闭在此 ChildWindow 中,UserControl 被禁用。
我的应用程序上的所有 ChildWindows 都会发生这种情况,即,如果我打开(例如)ChildWindow01,然后关闭它,然后打开 ChildWindow02 并关闭它,则基本 UserControl 将被禁用。
它是一个 MVVM 应用程序,但我从 UserControl.xaml.cs、按钮单击事件打开这些 ChildWindows。
PS 我正在为我的应用程序使用 Galasoft MVVM 框架。
请建议。
编辑
UserControl XAML
<StackPanel Style="{StaticResource QuizEditorStackPanelStyle}">
<HyperlinkButton x:Name="lnkSetting" Content="Settings"
Command="{Binding QuizSettingCommand}" CommandParameter="{Binding SettingId}"/>
</StackPanel>
调用 ViewModel -> RelayCommand,它打开一个子窗口(这是虚拟机中的私有属性),因为
private ChildWindow QuizSettingWindow {
get {
return new QuizSetting(this.QuizSettingId);
}
}
子窗口通过
private void OpenQuizSettingScreen(long quizSettingId) {
this.QuizS ettingWindow.Show();
}
自身的按钮事件关闭子窗口打开
I am facing a very unusual problem, i have a UserControl which shows ChildWindow to perform some operation on this ChildWindow, i close it when done with my operations and the (say) open it again, it works fine, but as soon as i close this ChildWindow, the UserControl becomes disabled.
This happens for all the ChildWindows on my application i.e, if i open (say) ChildWindow01 and then close it and then open ChildWindow02 and close it, the base UserControl becomes disabled.
Its a MVVM application but i am opening these ChildWindows from UserControl.xaml.cs, button click events.
P.S. I am using Galasoft MVVM framework for my application.
Please suggest.
Edit
UserControl XAML
<StackPanel Style="{StaticResource QuizEditorStackPanelStyle}">
<HyperlinkButton x:Name="lnkSetting" Content="Settings"
Command="{Binding QuizSettingCommand}" CommandParameter="{Binding SettingId}"/>
</StackPanel>
calls ViewModel -> RelayCommand, which opens a child window (which is a private property in VM) as
private ChildWindow QuizSettingWindow {
get {
return new QuizSetting(this.QuizSettingId);
}
}
Child Window opens by
private void OpenQuizSettingScreen(long quizSettingId) {
this.QuizS ettingWindow.Show();
}
Child window close on button event of self
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
关闭子窗口时,您是否取消订阅关闭事件?不确定这是否是您问题的原因。尝试取消订阅子窗口的关闭事件。
On closing the child window are you unsubscribing the closing event or not? Not sure if that could be the reason for your problem. Try unsubscribing from the closing event of child window.
我在silverlight论坛上找到了这个帖子,我也遇到了这个问题。该线程解释了您的问题并给出了临时解决方案。这个修复对我有用。
如果您
在关闭窗口后调用,父窗口将始终处于启用状态。这个修复对我有用,我希望它也对你有用。
但是,如果在您的情况下只有一个用户控件阻止(而不是整个应用程序),那么您可能需要调用类似的方法
,或者如果您从子窗口内订阅关闭事件(如果您扩展它),那么您可能会考虑调用:
I还没有测试过其中任何一个。但就我而言,第一个有效。我希望这一切都能帮助您解决问题。
I have found this thread on the silverlight forums, I also had this problem. The thread explains your problem and gives it a temporary fix. This fixed worked for me.
If you call
After you closed the window the parent will always be enabled. This fix worked for me and I hope it will work for you too.
But if in your case only one user control blocks (and not the entire app) then you might want to call something like
Or if you subscribe to the close event from within the childwindow (if you extend it) then you might consider calling:
I haven't tested any of those. But in my case the first worked. I hope this all helps you with your problem.