我正在尝试显示启动画面(即)我已经单独创建了一个启动视图和视图模型。我正在使用mvvm订阅者和发布者管理其可见性。
但目前我面临的问题是,任何任务开始时我的Splash屏幕都不可见。
启动画面视图
<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);
}
HowIRegister :
<ContentControl prism:RegionManager.RegionName="{x:Static inf:RegionNames.SplashScreenView}"></ContentControl>
_innerRegionManager.RegisterViewWithRegion(RegionNames.SplashScreenView, typeof(SplashScreenView));
请让我知道我错在哪里以及为什么我的闪屏不起作用。
答案 0 :(得分:0)
我查看了代码,我认为问题可能出在RaisePropertyChanged调用上。
尝试提供属性名称:
RaisePropertyChanged("EnableSplash")
另外,我认为您不需要在Visibility属性中强制使用Mode = TwoWay。