Silverlight 4:ChildWindow 在 2 次查看/隐藏操作后禁用 UserControl

发布于 2024-12-01 18:58:08 字数 1087 浏览 0 评论 0原文

我面临一个非常不寻常的问题,我有一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

信仰 2024-12-08 18:58:08

关闭子窗口时,您是否取消订阅关闭事件?不确定这是否是您问题的原因。尝试取消订阅子窗口的关闭事件。

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.

思念绕指尖 2024-12-08 18:58:08

我在silverlight论坛上找到了这个帖子,我也遇到了这个问题。该线程解释了您的问题并给出了临时解决方案。这个修复对我有用。

如果您

Application.Current.RootVisual.SetValue(Control.IsEnabledProperty, True);

在关闭窗口后调用,父窗口将始终处于启用状态。这个修复对我有用,我希望它也对你有用。

但是,如果在您的情况下只有一个用户控件阻止(而不是整个应用程序),那么您可能需要调用类似的方法

this.SetValue(Control.IsEnabledProperty, True);

,或者如果您从子窗口内订阅关闭事件(如果您扩展它),那么您可能会考虑调用:

this.Parent.SetValue(Control.IsEnabledProperty, True);

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

Application.Current.RootVisual.SetValue(Control.IsEnabledProperty, True);

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

this.SetValue(Control.IsEnabledProperty, True);

Or if you subscribe to the close event from within the childwindow (if you extend it) then you might consider calling:

this.Parent.SetValue(Control.IsEnabledProperty, True);

I haven't tested any of those. But in my case the first worked. I hope this all helps you with your problem.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文