C# 如何从IEventAggregator中的事件初始化ViewModel中的属性?
如果我有Microsoft.Practices.Prism.Events.IEventAggregator实例:C# 如何从IEventAggregator中的事件初始化ViewModel中的属性?,c#,wpf,prism,C#,Wpf,Prism,如果我有Microsoft.Practices.Prism.Events.IEventAggregator实例: eventAggregator.GetEvent<MyEvent>.Subscribe(SomeMethod); 我在ViewModel中有一个属性,我想使用MyEvent类中的成员初始化它,我如何才能做到这一点?Prism不会将属性从MyEvent类传递给SomeMethod。它将有效载荷作为DTO传递给: public class MyEvent: Composit
eventAggregator.GetEvent<MyEvent>.Subscribe(SomeMethod);
我在ViewModel中有一个属性,我想使用MyEvent类中的成员初始化它,我如何才能做到这一点?Prism不会将属性从MyEvent类传递给SomeMethod。它将有效载荷作为DTO传递给:
public class MyEvent: CompositePresentationEvent<MyEventArgs> {}
public class MyEventArgs { int MyIntValue; }
public class Subscriber
{
public Subscriber
{
eventAggregator.GetEvent<MyEvent>().Subscribe(SomeMethod);
}
public void SomeMethod(MyEventArgs e)
{
MessageBox.Show(e.MyIntValue);
}
}
public class Publisher
{
public void SendMinusOne()
{
var args = new MyEventArgs() { MyIntValue = -1 };
eventAggregator.GetEvent<MyEvent>().Publish(args);
}
}