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

前端 未结 1 363
半阙折子戏
半阙折子戏 2021-01-19 09:50

I\'m using a Messenger class in order to send data between view models. There is an AppView that hosts two main views in a content control, and up until now hav

1条回答
  •  盖世英雄少女心
    2021-01-19 10:34

    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();
        }
    }
    

    0 讨论(0)
提交回复
热议问题