当用户通过单击关闭按钮(红色X按钮)取消我的对话框时,我想执行特定的操作



而不是由于其他操作而关闭表单时。我如何确定是否

private void Window_Closing(object sender, CancelEventArgs e)


按钮引发事件?

<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Height="60" Width="284" WindowStartupLocation="CenterScreen"
    BorderBrush="#FFCCCCCC"
    BorderThickness="2"
    Background="#FFE0E0E0"
    WindowStyle="SingleBorderWindow"
    ShowInTaskbar="False" ResizeMode="NoResize" Closing="Window_Closing">

最佳答案

    public MainWindow()
    {
        InitializeComponent();
        this.Closing+=new System.ComponentModel.CancelEventHandler(MainWindow_Closing);

    }
    private void MainWindow_Closing(object sender, EventArgs e)
    {
        MessageBox.Show("salman");

    }

关于c# - 在WPF窗口中确定关闭窗口的发送方,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/15877922/

10-12 00:29
查看更多