I my project I have the MainForm with 2 UserControls. The UserControl1 have a button that makes the UserControl2 Visible.
Here's what I did:
USERCONTROL1
private void Button1_MouseLeftButtonUp(object sender, System.Windows.Input.MouseButtonEventArgs e)
{
MainWindow mw = new MainWindow();
mw.CallMethod();
}
MAINWINDOW
public void CallMethod()
{
USERCONTROL2 UC2 = new USERCONTROL2();
UC2.Visibility = Visibility.Visible;
grid.Children.Add(UC2);
}
...but when I click the UserControl1's button, nothing is happening.
Declare in your background code following:
Don't forget to add
INotifyPropertyChanged
to your classThen you bind your UserControl's visibility to vis_UC2.
In Constructor set starting visibility such as following
and finally under your button click you only say the following: