2012-09-06 21 views
5

Kullanıcı onayı ile senk silme işlemini yürütmem gerekiyor. Böyle bir şey:Kullanıcı onayı ile eşzamansız komut yürütme

public ReactiveAsyncCommand DeleteCommand { get; protected set; } 
... 
DeleteCommand = new ReactiveAsyncCommand(); 
DeleteCommand.RegisterAsyncAction(DeleteEntity); 

... 

private void DeleteEntity(object obj) 
{ 
    if (MessageBox.Show("Do you really want to delete this entity?", "Confirm", MessageBoxButton.YesNo) == MessageBoxResult.Yes) 
    { 
     //some delete operations 
    } 
} 

sorun MessageBox çok uyumsuz yürütülür olduğunu. Kullanıcıya eşzamanlı olarak sormak ve sonra yöntemi eşzamansız olarak yürütmek için ReactiveUI'deki en iyi model hangisidir?

cevap

6

bu sadece iki komutları kullanmaktır yapmanın en kısa yolu:

public ReactiveCommand DeleteCommand { get; protected set; } 
private ReactiveAsyncCommand ExecuteDelete { get; protected set; } 

/* 
* In the Constructor 
*/ 

ExecuteDelete = new ReactiveAsyncCommand(); 
ExecuteDelete.RegisterAsyncAction(() => /* Do the delete */); 

DeleteCommand = new ReactiveCommand(ExecuteDelete.CanExecuteObservable); 
DeleteCommand 
    .Where(_ => MessageBox.Show("Delete?") == MessageBoxResult.Yes) 
    .InvokeCommand(ExecuteDelete);