Заставка не работает в wpf с помощью mvvm - PullRequest
0 голосов
/ 09 мая 2018

Я пытаюсь отобразить заставку (т. Е.) Я отдельно создал заставку и вид для этого. Я управляю его видимостью с помощью подписчиков и издателей 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);
}

HowIRegister

<ContentControl prism:RegionManager.RegionName="{x:Static inf:RegionNames.SplashScreenView}"></ContentControl>

_innerRegionManager.RegisterViewWithRegion(RegionNames.SplashScreenView, typeof(SplashScreenView));

Пожалуйста, дайте мне знать, где я не прав и почему у меня не работает заставка.

1 Ответ

0 голосов
/ 09 мая 2018

Я просмотрел код и думаю, что проблема может быть в вызове RaisePropertyChanged.

Попробуйте указать название объекта:

RaisePropertyChanged("EnableSplash")

Кроме того, я думаю, вам не нужно принудительно устанавливать Mode = TwoWay в свойстве Visibility.

...