WPF Close button not working when in Grid
When I place Button in grid and add to is's click action:
this.Close();
It's not working. I want to be able to ask user before exit so I w开发者_运维知识库ant to use Close(). I don't want to use Application.Shutdown(); How to solve it.
Just tested it and it works fine! I created a new WPF application and a basic window:
<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>
and then added the following to the code-behind
private void closeButton_Click(object sender, RoutedEventArgs e)
{
if (MessageBox.Show("Are you sure?", "Application", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
{
this.Close();
}
}
And it works 100%... Can you post more code to see if something else is wrong? What .NET version are you using, etc...
精彩评论