【发布时间】:2010-10-15 05:41:32
【问题描述】:
当我将 Button 放在网格中并添加到 is 的点击操作时:
this.Close();
它不工作。我希望能够在退出前询问用户,所以我想使用 Close()。我不想使用 Application.Shutdown(); 如何解决。
【问题讨论】:
当我将 Button 放在网格中并添加到 is 的点击操作时:
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 版本等...
【讨论】: