2017-09-08 5 views
0

が、私はこのコードを持っていると私はビューモデルに移動したいのです:私はこのような何かを設定する必要があります実現ビューモデルでasyncコマンドを呼び出すにはどうすればよいですか?

resetButton.Clicked += async (sender, e) => 
{ 
    if (App.totalPhrasePoints < 100 || await App.phrasesPage.DisplayAlert(
       "Reset score", 
       "You have " + App.totalPhrasePoints.ToString() + " points. Reset to 0 ? ", "Yes", "No")) 
     App.DB.ResetPointsForSelectedPhrase(App.cfs); 
}; 

私のXAMLコードで

<Button x:Name="resetButton" Text="Reset All Points to Zero" Command="{Binding ResetButtonClickedCommand}"/> 

そして、私のC#コードで:

private ICommand resetButtonClickedCommand; 

public ICommand ResetButtonClickedCommand 
{ 
    get 
    { 
     return resetButtonClickedCommand ?? 
     (resetButtonClickedCommand = new Command(() => 
     { 

     })); 

    } 

しかし、どのように私は、コマンドに非同期アクションに合うことができますか?

答えて

4

あなたはこのような何かを試すことができます:あなたはこのも書くことができます

(resetButtonClickedCommand = new Command(async() => await SomeMethod())); 

async Task SomeMethod() 
{ 
    // do stuff 
} 
0

: -

(resetButtonClickedCommand = new Command(DoSomething)); 

async void DoSomething() 
{ 
    // do something 
} 

注: - それはのsomeMethodで警告を示しています。

関連する問題