C# 如何从Prism EventAggregator更改属性

C# 如何从Prism EventAggregator更改属性,c#,prism,C#,Prism,目前,Prism的EventAggregator只接受一个操作,即: _eventAggregator.GetEvent<Message>().Subscribe(Method); public void Method(string s) { Property = s; } \u eventAggregator.GetEvent().Subscribe(方法); 公共void方法(字符串s){Property=s;} 我如何让它改变一个属性,而不是调用一个方法来改变它 您不能,

目前,Prism的EventAggregator只接受一个操作,即:

_eventAggregator.GetEvent<Message>().Subscribe(Method);

public void Method(string s) { Property = s; }
\u eventAggregator.GetEvent().Subscribe(方法);
公共void方法(字符串s){Property=s;}

我如何让它改变一个属性,而不是调用一个方法来改变它

您不能,它需要通过设计调用一个方法。您可能可以使用lambda来模拟设置属性的效果(现在不是在机器前面,我不能尝试),但它仍然在幕后调用一个方法

_eventAggregator.GetEvent<Message>().Subscribe(s => Property=s));
\u eventAggregator.GetEvent().Subscribe(s=>Property=s));

使用
事件完成消息处理程序后注销它们也是一种很好的做法。Unsubscribe()
根据

返回一个可用于取消订阅的
IDisposable
。@Haukinger我不知道,谢谢!每天都是上学的日子…值得一提。也谢谢@Haukinger