如果我有Microsoft.Practices.Prism.Events.IEventAggregator实例:
eventAggregator.GetEvent<MyEvent>.Subscribe(SomeMethod);
我在ViewModel中有一个属性,我想使用MyEvent类中的成员进行初始化,我该怎么做?
答案 0 :(得分:0)
Prism不会将MyEvent
类的属性传递给SomeMethod。它通过payloads
作为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);
}
}