Popout window issue for WPF
Now, I got a Installation Window, which have a cancel button to 1) pause the storyboarding 2) popout my Cancel Window
For Cancel Window, there will be an "OK" button for me to be prompte开发者_开发知识库d to Failed Window.
So now I want to know how to track when the User closes the window (X) button, so I can close the Cancel Window and thus returning to Installation Window and resume my storyboarding.
So far, I've done this
private void cancel_btn_Click(object sender, RoutedEventArgs e)
{
Storyboard SB = (Storyboard)FindResource("Install");
SB.Pause();
popout_Cancel MyApp = new popout_Cancel();
MyApp.Show();
if (MyApp.OK.IsMouseCaptured == false)
{
MyApp.Close();
SB.Resume();
}
}
You can show the window as a model dialog and use DialogResult to get the result.
If I understand you correctly, you want to know if the user pressed cancel vs if they just closed the window? I'm not sure if this is what your asking, but if you just want to show a confirmation dialog, and get the result, here's how:
In your cancel window:
private void CancelWindow_OnOkClickedobject sender, RoutedEventArgs e)
{
this.Close();
}
private void CancelWindow_OnCancelClickedobject sender, RoutedEventArgs e)
{
this.DialogResult = true;
this.Close();
}
Then, when you want to show this window:
popout_Cancel MyApp = new popout_Cancel();
bool? result = MyApp.ShowDialog();
If the user presses cancel, result will be set to true. If the user hits the X button, or presses OK, result will be set to false.
Once you have the result, you can resume your storyboard. So the code would look like this:
Storyboard SB = (Storyboard)FindResource("Install");
SB.Pause();
popout_Cancel MyApp = new popout_Cancel();
bool? result = MyApp.ShowDialog();
if (result == null || result == false)
SB.Resume();
else
//they really want to cancel, terminate the app
Edited: ShowDialog() returns a Nullable, although ShowDialog() apparently only returns true or false
精彩评论