public ProgressWindowView(ProgressViewModel model)
     : this()
 {
     DataContext = model;
 }
Exemplo n.º 2
0
 public static void ExecuteAsyncOperation(Func<Action<OperationState>, Action, CancellationTokenSource> asyncOperation)
 {
     CancellationTokenSource cancelationToken = null; ;
     ProgressViewModel model = new ProgressViewModel(() =>
     {
         if (cancelationToken != null)
         {
             cancelationToken.Cancel();
         }
     });
     ProgressWindowView progressWindow = new ProgressWindowView(model);
     progressWindow.Loaded += (s, e) =>
     {
         cancelationToken = asyncOperation(
             state => App.AppContext.Dispatcher.BeginInvoke(new Action(() =>
             {
                 if (state.Exception != null) {
                     progressWindow.Close();
                     throw state.Exception;
                 }
                 model.OperationState = state;
             })),
             () => App.AppContext.Dispatcher.BeginInvoke(new Action(progressWindow.Close)));
     };
     progressWindow.SetCurrentWindowAsOwner();
     progressWindow.ShowDialog();
 }