2016-04-14 20 views
0

görüntülemek için navigasyon değil ve ben şu ViewModel ile Durum Modülü vardır:Yöntem ateş ama prizma kullanıyorum

_statusQuery.SetStatus(new StatusContext(string.Format("Cargando datos del servidor {0}", server.NombreInstancia),StatusType.Informative, 
        () => 
        { 
         var targetUri = new Uri("SqlMasterView", UriKind.Relative); 
         var navParameters = new NavigationParameters(); 
         navParameters.Add("selectedServer", server); 
         _regionManager.RequestNavigate(RegionNames.ServerInfoBarRegion, targetUri, navParameters); 
        })); 
: Ben benzeri statü ateşlendiğinde, Yani

public class StatusViewModel : WorkSpaceViewModel, IStatusQueryViewModel 
{ 
    private bool _isActive; 
    private StatusContext _context;   

    public StatusViewModel(IEventAggregator eventAggregator) 
    { 
     eventAggregator.GetEvent<StatusEvent>() 
      .Subscribe(x => UpdateStatus(x), ThreadOption.UIThread, true); 
     IsActive = false; 
    } 

    public bool IsActive 
    { 
     get { return _isActive; } 
     set { SetProperty(ref _isActive, value); } 
    } 

    public StatusContext Context 
    { 
     get { return _context; } 
     set { SetProperty(ref _context, value); } 
    } 

    private void UpdateStatus(StatusContext context) 
    { 
     if (context != null) 
     { 
      Context = context; 
      IsActive = true; 

      if (Context.Callback != null) 
      { 
       Timer t = new Timer(x => 
       { 
        Context.Callback.Invoke(); 
        IsActive = false; 
       }, null, 3000, 0); 
      } 
     } 
    } 
} 

kod StatusViewModel içinde callback.invoke sonra çalıştırılıyor ama hiçbir şey, okur debuger içinde, poping görüntüleyemezsiniz olmuyorsa:

A first chance exception of type 'System.InvalidOperationException' occurred in PresentationCore.dll 
A first chance exception of type 'System.InvalidOperationException' occurred in Microsoft.Practices.Unity.dll 
A first chance exception of type 'Microsoft.Practices.Unity.ResolutionFailedException' occurred in Microsoft.Practices.Unity.dll 
A first chance exception of type 'Microsoft.Practices.ServiceLocation.ActivationException' occurred in Microsoft.Practices.ServiceLocation.dll 
A first chance exception of type 'System.InvalidOperationException' occurred in Prism.Wpf.dll 
Bu konularda arada

, bilmiyorum ama statusQuery başka callback'inde içine sarılır:

_dialogQuery.Publish(
      new DialogContext(DialogType.Prompt, 
       String.Format("Desea cargar los datos del servidor {0}?", server.NombreInstancia), null, x => 
     { 
      bool b = x == DialogResult.Ok; 
      if (b) 
      { 
       _statusQuery.SetStatus(new StatusContext(string.Format("Cargando datos del servidor {0}", server.NombreInstancia),StatusType.Informative, 
        () => 
        { 
         var targetUri = new Uri("SqlMasterView", UriKind.Relative); 
         var navParameters = new NavigationParameters(); 
         navParameters.Add("selectedServer", server); 
         _regionManager.RequestNavigate(RegionNames.ServerInfoBarRegion, targetUri, navParameters); 
        })); 
      } 
     })); 

Belki parçacığı ile bir ilgisi vardır? kod ince

EDIT 2 çalışıyordu statusQuery kullanmadan önce:

DÜZENLEME teşekkür ederiz Ben System.Timers.Timer ve İlk Şans istisnalar kimse eğer atmak zaten

cevap

0

Tamam olmak uğraş Burada aynı sorunla birlikte, Dispatcher bunu çözdü:

Application.Current.Dispatcher.BeginInvoke((System.Windows.Threading.DispatcherPriority.Normal), 
       (Action)(() => 
       { 
        Context.Callback.Invoke(); 
        IsActive = false; 
        Dispose(); 
       } 
      )); 
İlgili konular