2
應用程序的窗口沒有邊界,所以右邊沒有退出按鈕,我怎樣才能以正確的方式關閉它?這是正確的方式關閉棱鏡應用程序沒有默認退出按鈕?
這是我的方式,將fisrt綁定到自定義退出按鈕的命令。
<Button Content="Exit" HorizontalAlignment="Left" Margin="327,198,0,0" VerticalAlignment="Top" Width="75" Command="{Binding ExitCommand}"/>
當點擊按鈕時在ViewModel中拋出異常。
class ViewModel:NotificationObject
{
public ViewModel()
{
this.ExitCommand = new DelegateCommand(new Action(this.ExecuteExitCommand));
}
public DelegateCommand ExitCommand { get; set; }
public void ExecuteExitCommand()
{
throw new ApplicationException("shutdown");
}
}
漁獲應用類
public partial class App : Application
{
protected override void OnStartup(StartupEventArgs e)
{
base.OnStartup(e);
Bootstrapper bootstrapper = new Bootstrapper();
AppDomain.CurrentDomain.UnhandledException += AppDomainUnhandledException;
try
{
bootstrapper.Run();
}
catch (Exception ex)
{
HandleException(ex);
}
}
private static void AppDomainUnhandledException(object sender, UnhandledExceptionEventArgs e)
{
HandleException(e.ExceptionObject as Exception);
}
private static void HandleException(Exception ex)
{
if (ex == null)
return;
Environment.Exit(1);
}
}