noompp10
noompp10

Reputation: 13

How can i also pass parameter to new open window using Mvvm Light Toolkit

from this thread thread

i can open new window by using message this comment, but i also want to pass parameter to new open windows. Any idea for this?

Thank you.

Upvotes: 1

Views: 1808

Answers (2)

Chris
Chris

Reputation: 141

Use NotificationMessage<T>, there is no need to inherit from NotificationMessage.

e.g. (I'm using the Telerik Docking forms container in my project, so you can ignore the RadPane stuff - hopefully you get the idea)

using GalaSoft.MvvmLight.Messaging;

public MainWindow()
{

    InitializeComponent();
    Messenger.Default.Register<NotificationMessage<MyEntities.Company>>(this, (c) => NotificationMessageReceived(c.Notification, c.Content));
}

private void NotificationMessageReceived (string msg, MyEntities.Company c)
{
   if (msg == "ShowCompany") 
   {
      var CompanyPane = new RadDocumentPane();

      CompanyPane.Header = c.Name; // I use the  Name property of my company entity here

      CompanyPane.Content = new Views.CompanySummaryView(); 
      this.radPaneGroup.AddItem(CompanyPane, DockPosition.Center);
   }
}

In the View Model where I want to open my new Window I have this Method which I call from a Command. This just sends the message with the Company entity embedded.

public void EditCompany()
{
    Messenger.Default.Send<NotificationMessage<MyEntities.Company>>(new NotificationMessage<MyEntities.Company>(Companies.FirstOrDefault(), "ShowCompany"));
}

Upvotes: 2

yo chauhan
yo chauhan

Reputation: 12295

Create a custom class that inherits NotificationMessage and set what you want in it and pass it and then on view side cast it back to your custom class. I hope this will help.

Upvotes: 0

Related Questions