views:

69

answers:

2

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 prompted 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();
    }
}
A: 

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

mattjf
Hello, I tried using your code and when I debug, tt prompt me this error: Cannot implicitly convert type 'bool?' to 'bool'. An explicit conversion exists (are you missing a cast?)
BabyChar
Had a couple more typos that I missed in the edit. I had just gotten up when I wrote that, so I'm sure there are other minor problems. See the article here: http://msdn.microsoft.com/en-us/library/bb384091.aspxThe problem is bool? is a Nullable<bool> which means it can be true, false, or null. Which line do you get the exception on?
mattjf
Hello. the above code can debug, if I press X of the window it works perfectly.. and yes that's what i wanted.. but when I debug, popout out, and if I press the X, the SB yes is continued. but till the end of the SB, it will prompt me to Finish page, but I couldn't click on any.. meaning it hangs..
BabyChar
and to answer your qns the line that got that exception is bool result = MyApp.ShowDialog()
BabyChar
I'm not sure without seeing all your code. The code above was just a sample, so it probably needs more work to be ready for production.Just a note, you should clean up the naming so people can follow easier. For example: popout_Cancel MyApp should be more like: ConfirmationDialog confirmDialog = new ConfirmationDialog();I would just debug it and check to see what result holds. I did update the code from when I initially posted it, so there might be something that fixes it in there.
mattjf
A: 

Hi mattjif, thanks for your help ^^ I think it works perfectly fine when I use my school's computer, which I dun know why. haha, appreciated it =]

BabyChar
No problem. If the answer was helpful, can you accept it? That way anyone else looking at it can see that the solution worked. Just click the check mark next to my post. It should turn it green. Thanks a lot.
mattjf