【发布时间】:2018-05-09 05:50:39
【问题描述】:
我正在尝试显示启动画面(即)我为此分别创建了启动视图和视图模型。我正在使用 mvvm 订阅者和发布者管理其可见性。
但我目前面临的问题是,当任何任务开始时,我的启动画面都不可见。
启动画面视图:
<Grid>
<!--Splash Screen -->
<Border x:Name="Splashbrd" Style="{StaticResource SettingOuterBorderStyle}"
Visibility="{Binding EnableSplash,UpdateSourceTrigger=PropertyChanged,Mode=TwoWay}" >
<Border Style="{StaticResource ProgressBorderStyle}">
<StackPanel Margin="10" >
<ProgressBar Style="{StaticResource ProgressBarStyle}"/>
<TextBlock Text="{Binding SplashText,UpdateSourceTrigger=PropertyChanged,Mode=TwoWay}" FontFamily="Arial" FontSize="12"
Margin="5,5,5,0" TextAlignment="Center" TextWrapping="Wrap" />
</StackPanel>
</Border>
</Border>
</Grid>
SplashScreenViewModel
private void SubscribeSplashScreenEvent()
{
SubscriptionToken _subscribeSplashEvent = this._eventAggregator.GetEvent<PubSubEvent<ISplashScreenEvent>>().Subscribe(i =>
{
Showprogress(i.SplashVisibilty);
SplashText = i.SplashText;
});
}
#region SplashScreen
private Visibility _enablesplash = Visibility.Hidden;
public Visibility EnableSplash
{
get { return _enablesplash; }
set
{
if (_enablesplash != value)
{
_enablesplash = value;
RaisePropertyChanged();
}
}
}
private string _splashtext;
public string SplashText
{
get { return _splashtext; }
set
{
_splashtext = value;
RaisePropertyChanged();
}
}
public void Showprogress(bool bvisible)
{
EnableSplash = bvisible ? Visibility.Visible : Visibility.Hidden;
}
#endregion
ViewWhereIamUsing:
private void PublishSplashScreenEvent(bool _splashVisibilty, string _splashText = null)
{
var eventObj = new SplashScreenEvent
{
SplashVisibilty = _splashVisibilty,
SplashText = _splashText
};
eventAggregator.GetEvent<PubSubEvent<ISplashScreenEvent>>().Publish(eventObj);
}
BackgroundWorker impworker = new BackgroundWorker();
impworker.DoWork += test;
impworker.RunWorkerCompleted += OntestCompleted;
//void test()
{
PublishSplashScreenEvent(true, "testimg spash......");
}
void OntestCompleted()
{
PublishSplashScreenEvent(false);
}
如何注册:
<ContentControl prism:RegionManager.RegionName="{x:Static inf:RegionNames.SplashScreenView}"></ContentControl>
_innerRegionManager.RegisterViewWithRegion(RegionNames.SplashScreenView, typeof(SplashScreenView));
请让我知道我错在哪里以及为什么我的启动画面无法正常工作。
【问题讨论】:
标签: c# wpf xaml mvvm subscriber