Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/318.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何从IEventAggregator中的事件初始化ViewModel中的属性?_C#_Wpf_Prism - Fatal编程技术网

C# 如何从IEventAggregator中的事件初始化ViewModel中的属性?

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

如果我有Microsoft.Practices.Prism.Events.IEventAggregator实例:

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);
  }
}