0
当我把按钮在网格,增加是的单击动作:WPF关闭按钮不工作时,在电网
this.Close();
它不工作。我希望能够在退出前询问用户,所以我想使用Close()。我不想使用Application.Shutdown(); 如何解决它。
当我把按钮在网格,增加是的单击动作:WPF关闭按钮不工作时,在电网
this.Close();
它不工作。我希望能够在退出前询问用户,所以我想使用Close()。我不想使用Application.Shutdown(); 如何解决它。
刚刚测试过它,它工作正常!我创建了一个新的WPF应用程序和基本窗口:
<Window x:Class="WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Grid>
<Button Content="Close" x:Name="closeButton" Click="closeButton_Click" />
</Grid>
</Window>
,然后添加下面的代码隐藏
private void closeButton_Click(object sender, RoutedEventArgs e)
{
if (MessageBox.Show("Are you sure?", "Application", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
{
this.Close();
}
}
和它的作品100%...你可以发布更多的代码来看看如果还有其他问题呢?你使用的是什么.NET版本等等......