Alternative ShowDialog / DialogResult in Silverlight

In WPF, I often used this construct:

SomeChildWindow dlg = new SomeChildWindow();
dlg.ShowDialog();
...
//child window is closed either by "this.DialogResult = true;" or just by "Close();"    
//and in Parent window after Child window is closed we can use condition based on that
...

   if (dlg.DialogResult == true)
        {
           //do something
        }

But in Silverlight, this approach does not work.

What is the alternative for Silverlight for this? I mean, how is it supposed to get feedback from a child window in Silverlight?

+3
source share
2 answers

Silverlight does not support fully modal dialogs, which prevents the traditional approach for checking dialog results. Instead, you need to assign an event handler to the dialog that will handle the result of the dialog. Event ChildWindow.Closed.

Then you can get ChildWindow.DialogResultin the handler of this event accordingly.

private void OnDialogClosed(object sender, EventArgs args)
{
   var window = (ChildWindow)sender;
   if (window.DialogResult ?? false)
   {
   }
   else
   {
   }
}
+5

, :

SomeChildWindow dlg = new SomeChildWindow();

dlg.Closed += (s, eargs) =>
{
   if(dlg.DialogResult == true)
   {
      //do something
   }
};

dlg.Show();
+8

Source: https://habr.com/ru/post/1773686/


All Articles