0
我在WPF中創建了一個自定義對話框。我想,當用戶點擊X時,對話框將被打開,如果他想退出,請點擊「是」,否則應點擊「否」。WPF dialogBox不關閉應用程序
static public bool? close;
private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
this.Hide();
WindowClose windowClose = new WindowClose();
windowClose.ShowDialog();
close = windowClose.DialogResult;
if (close == true)
{
Application.Current.Shutdown();
}
else
{
//DONT CLOSE THE APPLICATION AND SHOW THE CURRENT WINDOW
}
}
對話框的代碼:
private void button1_Click(object sender, RoutedEventArgs e)
{
this.DialogResult = true;
this.Close();
}
private void button2_Click(object sender, RoutedEventArgs e)
{
this.DialogResult = false;
this.Close();
}
設置'CancelEventArgs.Cancel'到TRUE;以阻止對話框關閉。在這裏看到答案#2:http://stackoverflow.com/questions/23613694/wpf-mvvm-cancel-window-closing-event/23614197#23614197 –
好吧,我fount如何...我補充說:e.Cancel =真正; this.Show(); – user3590450
[隱藏窗口,直到它再次需要]的可能重複(http://stackoverflow.com/questions/16567818/hide-a-window-until-its-needed-again) –