C# 使用另一个类的EventAggregator刷新窗口的ViewModel中的属性

C# 使用另一个类的EventAggregator刷新窗口的ViewModel中的属性,c#,.net,wpf,prism,eventaggregator,C#,.net,Wpf,Prism,Eventaggregator,所以。。我有一些核心课程。当它加载一些模块时,我试图用EventAggregator.GetEvent().Publish()向状态窗口发送一些通知。 状态窗口显示: private Core() { SystemManager.EventAggregator.GetEvent<StartProgressWindow>().Publish(null); this.InitializeCore(); }

所以。。我有一些核心课程。当它加载一些模块时,我试图用EventAggregator.GetEvent().Publish()向状态窗口发送一些通知。 状态窗口显示:

private Core()
        {
            SystemManager.EventAggregator.GetEvent<StartProgressWindow>().Publish(null);
            this.InitializeCore();
        } 
绑定:

<Label Content="{Binding Status, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}"/>

事实上,问题是:

属性随我发送到的所有状态而更改。但它并没有反映在UI上,而是forzen。我在ViewModel类的构造函数中将Status属性的值设置为“Some string”,当然,它反映得很好。 我做错了什么? 谢谢
帕维尔

您是否尝试过确保在UI线程上订阅

eventAggregator.GetEvent<ChangeProgressStatus>().Subscribe((message) =>
                {
                    this.Status = message;
                }, ThreadOption.UIThread);
eventAggregator.GetEvent().Subscribe((消息)=>
{
状态=消息;
},ThreadOption.UIThread);

您是否尝试过确保在UI线程上订阅

eventAggregator.GetEvent<ChangeProgressStatus>().Subscribe((message) =>
                {
                    this.Status = message;
                }, ThreadOption.UIThread);
eventAggregator.GetEvent().Subscribe((消息)=>
{
状态=消息;
},ThreadOption.UIThread);

我怀疑这是因为所有事件都与
InitializeCore()
方法同时处理,因此在所有事件和
InitializeCore()
方法完成之前,它实际上不会呈现任何内容

尝试在低于
渲染
的位置启动
StartProgressWindow
事件,例如
DispatcherPriority.Background

private Core()
{
    this.Dispatcher.BeginInvoke(DispatcherPriority.Background,
        new Action(delegate 
        { 
            SystemManager.EventAggregator.GetEvent<StartProgressWindow>().Publish(null);
        }));

    this.InitializeCore();
} 
private Core()
{
this.Dispatcher.BeginInvoke(DispatcherPriority.Background,
新操作(委派)
{ 
SystemManager.EventAggregator.GetEvent().Publish(null);
}));
this.InitializeCore();
} 

我怀疑这是因为所有事件都与
InitializeCore()
方法同时处理,因此在所有事件和
InitializeCore()
方法完成之前,它实际上不会呈现任何内容

尝试在低于
渲染
的位置启动
StartProgressWindow
事件,例如
DispatcherPriority.Background

private Core()
{
    this.Dispatcher.BeginInvoke(DispatcherPriority.Background,
        new Action(delegate 
        { 
            SystemManager.EventAggregator.GetEvent<StartProgressWindow>().Publish(null);
        }));

    this.InitializeCore();
} 
private Core()
{
this.Dispatcher.BeginInvoke(DispatcherPriority.Background,
新操作(委派)
{ 
SystemManager.EventAggregator.GetEvent().Publish(null);
}));
this.InitializeCore();
} 

我不认为上面的代码阻塞了UI线程,可能是其他线程导致了问题。把你的断点放在订阅服务器上,看看发生了什么。我也是这么想的!而且已经这么做了。我不认为上面的代码阻塞了UI线程,可能是其他线程导致了这个问题。把你的断点放在订阅服务器上,看看发生了什么。我也是这么想的!而且已经这么做了。订阅服务器中的一切都很好。我尝试了这一点,正如我所料,发布事件ChangeProgressStatus订阅服务器未被触发@shtpavel尝试使用
Dispatcher
来发布
ChangeProgressStatus
消息,而不是
StartProgressWindow
消息。同样只是为了验证,您的代码中只有一份
EventAggregator
,对吗?您没有使用两个独立的
EventAggregator实例
?EventAggregator是一个单例^)谢谢您的帮助!我会很快尝试它,我会写它的工作与否!我尝试了这一点,正如我所料,发布事件ChangeProgressStatus订阅者不会被触发@shtpavel尝试使用
Dispatcher
来发布
ChangeProgressStatus
消息,而不是
StartProgressWindow
消息。同样只是为了验证,您的代码中只有一份
EventAggregator
,对吗?您没有使用两个独立的
EventAggregator实例
?EventAggregator是一个单例^)谢谢您的帮助!我会很快尝试它,我会写它的工作与否!
private Core()
{
    this.Dispatcher.BeginInvoke(DispatcherPriority.Background,
        new Action(delegate 
        { 
            SystemManager.EventAggregator.GetEvent<StartProgressWindow>().Publish(null);
        }));

    this.InitializeCore();
}