简体   繁体   English

如何关闭WPF用户控制窗口

[英]How to close WPF User Control window

I have a question about closing a User Control Window. 我有一个有关关闭用户控制窗口的问题。

In this application the main window will have a button to open the User control Window. 在此应用程序中,主窗口将具有一个用于打开用户控制窗口的按钮。 In the User Control Window there are two buttons: one is to save and the other is to cancel. 在用户控制窗口中,有两个按钮:一个是保存,另一个是取消。 In the cancel click event, the user control alone needs to get closed and get back to the main window. 在cancel click事件中,仅用户控件需要关闭并返回主窗口。

This code is closing the main window, too. 该代码也关闭了主窗口。

private void btnCancel_Click(object sender, RoutedEventArgs e)
{
    var mywindow = Window.GetWindow(this);
    mywindow.Close();
}

Can you try: 你能试一下吗:

private void btnCancel_Click(object sender, RoutedEventArgs e)
    {
        var mywindow = Window.GetWindow(this);
        this.Close();
    }

I guess mywindow is your main window 我想mywindow是你的主窗口

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM