ale
ale

Reputation: 3431

How restart the Window?

WPF I need CLEAN and START again the window SetPathCharger.xaml when the user clic on "Yes" the message box, the problem is the application send a error InvalidOperationException.

public void ExitProgram(string message)
{
    var restart = MessageBox.Show("Do you want do it again?", 
                                  "Question", MessageBoxButton.YesNo, 
                                  MessageBoxImage.Question).ToString(); 
    if (restart == "Yes")
    {
        _setPathCharger.ShowDialog();
    }
    if (restart == "No")
    {
        Environment.Exit(0);
    }         
}

How can I do this?

Upvotes: 0

Views: 117

Answers (2)

Reed Copsey
Reed Copsey

Reputation: 564851

You should just create and show a new SetPathCharger window, instead of reusing the current one. Something like:

_setPathCharger = new SetPathCharger();
_setPathCharger.ShowDialog();

Upvotes: 2

Marino Šimić
Marino Šimić

Reputation: 7340

Assuming ExitProgram is in some outer scope and is triggered after closing _setPathCharger then I suppose you are trying to ShowDialog() a disposed object.

Try to:

_setPathCharger = new SetPathCharger();
_setPathCharger.ShowDialog();

Upvotes: 1

Related Questions