Search code examples
c#wpfpopupresponsedialogresult

How to wait for a response from a wpf mvvm popup


I've searched but cannot find an answer to this question, and maybe that means there is a better way to do what I'm attempting.

In a WPF application, using MVVM design pattern: I've created a UserControl that is a box. This popup box has two options (buttons) on it, "Okay" and "Cancel". This user control has it's own view model to supply it's message data. Creating and showing this popup is simple enough. My trouble is I would like to wait for the users choice. Something similar to a DialogReponse? Ideally I would like to do something like this:

if (MyPopup.Show())
{
    //do something
}
else
{
    //do something else
}

Maybe there is a better approach to what I'm trying to do. I don't want to use a message box as I have the custom popup I've made. But maybe popup is the wrong control? Thanks ahead of time for any help.


Solution

  • If you want to have the functionality of a Window, why not use one?

    new MyCustomDialogWindow().ShowDialog();