locked
MVVMLight popup window RRS feed

  • Question

  • Register message in mainpage.

    Messenger.Default.Register<string>(this, "MainWindow", o =>
                {
                    var d = new NewCustomer();
                    d.Title = o;
                    d.ShowDialog();
                    
                });

    Register message in popup window.

    Messenger.Default.Register<Customer>(this, "ChildWindow", (o) =>
                {
                    this.DialogResult = true;
                });

    Send message in ViewModel.

    The problem is, the first time, mainpage accept the message and pop up the child window. Then the child window accept message and closed. Then the mainpage accept message again and pop up child window, child window accept message and get error when it close.

    Only after the Window is created and displayed as a dialog box, then I can set the DialogResult. Why?

    Thursday, July 16, 2015 2:00 PM

Answers

  • Hi LucusSyhone,

     

    According to your code, the "ChildWindow" has not been deregister which doesn't been released. Please UnRegister all message before you set DialogResult as below code. If you do not want the child window later, please consideration to dispose it. If there has anything related with it, it will be dispose automatically by system.

    Messenger.Default.Unregister(this);  




    Best Regards,
    Weiwei

    • Marked as answer by Weiwei Cai Friday, July 24, 2015 8:18 AM
    Friday, July 17, 2015 2:38 AM

All replies

  • Why are you registering for the message in the popup window?

    It won't be there until it's popped up to receive any message.
    Once it's there, it's job is to get input.

    If anything I would expect the childwindow to be sending a message with the result when you click ok or cancel or whatever it's doing.

    In the popup window the user clicks a yes or a no button.

    There's a command which sends yes or no in a message

    Messenger.Default.Send(new DialogResultMessage{Result="Yes"} );


    Thursday, July 16, 2015 3:03 PM
  • Hi LucusSyhone,

     

    According to your code, the "ChildWindow" has not been deregister which doesn't been released. Please UnRegister all message before you set DialogResult as below code. If you do not want the child window later, please consideration to dispose it. If there has anything related with it, it will be dispose automatically by system.

    Messenger.Default.Unregister(this);  




    Best Regards,
    Weiwei

    • Marked as answer by Weiwei Cai Friday, July 24, 2015 8:18 AM
    Friday, July 17, 2015 2:38 AM