需求:需要在许多子窗体中关闭整个程序(WPF)
winform实现:Application.Exit();
WPF实现:
App.xaml文件:
<Application x:Class="pc.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
StartupUri="Windows1.xaml" ShutdownMode="OnExplicitShutdown">
Windows1.xaml文件(部分):
<Button Margin="37,0,15,15" Style="{DynamicResource btn_Exit}" Content="Button" Grid.Column="2" Grid.Row="3" Height="41" VerticalAlignment="Bottom" Width="100" x:Name="btn_Exits" Click="btn_Exits_Click" />
Windows1.xaml.cs文件(部分):
private void btn_Exits_Click(object sender, RoutedEventArgs e)
{
Application.Current.Shutdown();
}
十分简单!此后只需在按钮事件中加入Application.Current.Shutdown(),即可退出程序