C# 使用MVVM模式在WPF中的不同视图中设置变量
当用户在不同的视图之间移动时,我想在屏幕上始终可见的视图中打开加载程序。 页脚我添加了加载器,我会通过变量“出现”和“消失”来完成它,通过我的模型实例化。 但它不起作用。在调试模型中,真假值正确的模型,但不考虑页脚。要帮忙吗?还是按事件?有可能吗 页脚XAMLC# 使用MVVM模式在WPF中的不同视图中设置变量,c#,wpf,asynchronous,mvvm,model,C#,Wpf,Asynchronous,Mvvm,Model,当用户在不同的视图之间移动时,我想在屏幕上始终可见的视图中打开加载程序。 页脚我添加了加载器,我会通过变量“出现”和“消失”来完成它,通过我的模型实例化。 但它不起作用。在调试模型中,真假值正确的模型,但不考虑页脚。要帮忙吗?还是按事件?有可能吗 页脚XAML <StackPanel DataContext="{StaticResource vmp}" Orientation="Horizontal" DockPanel.Dock="Bottom" Height="40" Backgro
<StackPanel DataContext="{StaticResource vmp}" Orientation="Horizontal" DockPanel.Dock="Bottom" Height="40" Background="#eeeeee">
<ContentControl prism:RegionManager.RegionName="FooterRegion" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"/>
<TextBlock Text="eStart Enterprise 2.13.15" VerticalAlignment="Center" HorizontalAlignment="Left" FontSize="12" Margin="25,0,0,0"></TextBlock>
<!-- my loader is progressbar here, default is false -->
<ProgressBar Width="200" Margin="885, 0, 0, 0" Visibility="{Binding Path=model.Loader, Mode=TwoWay, Converter={StaticResource booleanToVisibilityConverter}}" HorizontalAlignment="Right" VerticalAlignment="Center" IsIndeterminate="True" Value="100" />
</StackPanel>
如何修复它,使加载程序上或下的所有视图始终位于该变量上?您使用prism,因此可以使用IEventAggregator 为事件创建数据模型
public class ChangeLoaderEventDataModel
{
}
创建事件
public class ChangeLoaderEvent: PubSubEvent<ChangeLoaderEventDataModel>
{
}
public类ChangeLoaderEvent:PubSubEvent
{
}
下一个订阅控件中的事件,该控件包含加载程序
_eventAggregator.GetEvent<ChangeLoaderEvent>().Subscribe(ShowLoaderMethod);
\u eventAggregator.GetEvent().Subscribe(ShowLoaderMethod);
之后,您可以在需要的时候和地点触发事件
_eventAggregator.GetEvent<ChangeLoaderEvent>().Publish(new ChangeLoaderEventDataModel());
\u eventAggregator.GetEvent().Publish(新的ChangeLoaderEventDataModel());
_eventAggregator.GetEvent<ChangeLoaderEvent>().Publish(new ChangeLoaderEventDataModel());