开发者

"ShowDialog / DialogResult" alternative in Silverlight

In WPF I often used such a construction:

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.DialogRe开发者_StackOverflowsult == true)
        {
           //do something
        }

But in Silverlight this approach doesn't work.

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


You can do this by handling the close event:

SomeChildWindow dlg = new SomeChildWindow();

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

dlg.Show();


Silverlight doesn't 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 process the dialog result. The event is ChildWindow.Closed.

You can then obtain ChildWindow.DialogResult in that event handler to handle it accordingly.

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜