2012-06-04 97 views
1

我需要显示启动屏幕和图像&进度条。使用MVVM和WPF显示百分比闪屏和进度条

  1. 在我的应用程序启动我有代码如下显示主窗口。

     SplashScreenWindowViewModel vm = new SplashScreenWindowViewModel(); 
        AutoResetEvent ev = new AutoResetEvent(false); 
         Thread uiThread = new Thread(() => 
        { 
         vm.Dispatcher = Dispatcher.CurrentDispatcher; 
         ev.Set(); 
    
         Dispatcher.CurrentDispatcher.BeginInvoke((Action)delegate() 
         { 
          SplashScreenWindow splashScreenWindow = new SplashScreenWindow(); 
          splashScreenWindow = new SplashScreenWindow(); 
          splashScreenWindow.Show(); 
          splashScreenWindow.DataContext = vm; 
          vm.InstigateWorkCommand.Execute(null); 
    
         }); 
    
         Dispatcher.Run(); 
        }); 
         uiThread.SetApartmentState(ApartmentState.STA); 
         uiThread.IsBackground = true; 
         uiThread.Start(); 
         ev.WaitOne(); 
    
  2. 以我主视图模型我有代码如下

    类MainviewModel:viewmodelbase { rivate串_message; 私人对象内容; private readonly BackgroundWorker worker; private readonly ICommand instigateWorkCommand;

    ​​

    }

    MY UI具有进度条和一个溅主窗口中的一个的用户控制。 当我的长时间运行操作完成时,我的主窗口(主应用程序)被打开。 //用户控制

     <ProgressBar Height="27" Value="{Binding CurrentProgress, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}" Margin="53,162,57,0" Name="progressBar" Grid.Row="1" 
          Maximum="{Binding Path=ProgressMax, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}" Visibility="{Binding ProgressVisibility}" /> 
    

    // SplashWindow

    <localView:usercontrol/> 
    

我的问题是

ProgressChangedevent不点火和%完成未示出在向上文本块。请帮助

回答

1

您尚未注册完整的处理程序,并且您没有正确调用进度。 来自MSDN的这个示例涵盖了这一切。

BackGroundWorker

+0

布拉姆你好我mainviewmodel构造我已经注册了所有的事件处理程序。唯一缺少的是backgroundWorker1_RunWorkerCompleted。做到了,但没有进展。 –

+0

不清楚。如此完整的工作?你是否确定了进展的呼声?请用当前的代码更新问题。 – Paparazzi