I have a UserControl userControl1 with button. When user click button i create new UserControl and show it:
private void Button_UserControl1_Click(object sender, RoutedEventArgs e) { Window window = new Window { Title = "Control2", Content = _control2 }; _control2= new UserControl2(ref window); window.ShowDialog(); } at UserControl2 when i desides to close myself (control2 window) (another button click):
private void btOk_Click(object sender, RoutedEventArgs e) { _parent.Close(); //_parent is ref window } But i can not close it!
Can you tell me: how to close created window (control2) by clicking to button on control2?
Thank you!
_control2at the time you createwindow? You assign a newUserControl2to_control2afterwards, but that won't change theContentofwindow.