Silverlight 4 : ChildWindow Disables UserControl After 2 View/Hide Operations
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
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.
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.
精彩评论