2010-10-15 39 views
0

當我把按鈕在網格,增加是的單擊動作:WPF關閉按鈕不工作時,在電網

this.Close(); 

它不工作。我希望能夠在退出前詢問用戶,所以我想使用Close()。我不想使用Application.Shutdown(); 如何解決它。

回答

1

剛剛測試過它,它工作正常!我創建了一個新的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版本等等......