Possible Duplicate:
Updating One Form After Event Occurs in Another Form
Relevant info: Using WPF Application, C#, Visual Studio 2010, .Net 4
I have two windows: Window1 and MainWindow. In Window1 I have a checkbox, that when checked, will set a label1 in MainWindow to not visible. How would I go about this?
I can’t do MainWindow newWindow = new MainWindow() because I’m not trying to make a new main window. I tried the following code but I get a exception thrown: {“Object reference not set to an instance of an object.”}`.
private void checkBox4_Checked(object sender, RoutedEventArgs e)
{
if (checkBox4.IsChecked == true)
{
(Application.Current.MainWindow as MainWindow).label1.Visibility =
Visibility.Hidden;
}
else
{
(Application.Current.MainWindow as MainWindow).label1.Visibility =
Visibility.Visible;
}
}
What would be the best way to go about this? Thanks in advanced.
Add an event to
Window1:When the checkbox is checked raise that event:
Then add an event handler from the main form: