How to register message handler prior to ShowDialog() blocking call?

痴心易碎 提交于 2019-12-01 19:54:04

You could solve the problem a few ways:

  1. Don't use ShowDialog(). Use Show(), and make the dialog window TopMost and parented to the main window.
  2. Register the ProductView in the constructor of the DialogService (do you really need a new ProductView each time anyway?)

  3. Make the DialogService (or a utility class inside of it) register at construction time for the message, and then pass the message on to any displayed ProductViews

Personally I like #2- since you are using ShowDialog, it implies that only one ProductView is ever needed at a time. For example:

class DialogService : IDialogService
{
    Window productView = null;
    ProductView _productView;

    public DialogService()
    {
         _productView = new ProductView();
    }

    public void ShowDetailDialog()
    {
        _productView.ShowDialog();
    }
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!