用Eventaggregator发送字符串
本文关键字:字符串 Eventaggregator | 更新日期: 2023-09-27 18:06:06
如何使用事件聚合器在两个模块(两个文本框之间)之间发送字符串?如何调用我的输入文本绑定到第一个模块文本框到第二个模块文本框,我需要一个类的字符串属性实现我的geteevent ?我使用WPF Prism
在您希望更新的视图模型中,您需要订阅事件。下标时提供一个。在这里,您需要更新您希望更新的文本框绑定到的属性。
public class SourceViewModel
{
public string SourceText { ... }
// Publish SendString event on SourceText changes...
}
public class DestinationViewModel
{
private IEventAggregator _aggregator;
// Bind DestinationText to your destination text box...
public string DestinationText { .. }
public DestinationViewModel(IEventAggregator eventAggregator)
{
...
_aggregator.GetEvent<SendStringEvent>().Subscribe(StringAction2,
ThreadOption.UIThread, false, i => DestinationText = i.Text);
}
}
这里有一个很好的Prism EventAggregator示例