Reputation: 13
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
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
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