2012-02-07 6 views
0

My EventToCommandの定義には、イベントが発生したときに自動的に更新される(バインド値を最新にする)ための高度なCommandParameterが含まれています。 EventToCommandを使用してこの動作を達成する方法はありますか? 私はElementNameにバインドされ、ValueConverterを持つCommandParameterバインディングを持っています。 ValueConverterはマウスの位置を取得します:EventToCommand Update CommandParameter

Mouse.GetPosition(element) 

ValueConverterはコマンドが実行される直前に更新する必要があります。

私はPassEventArgsToCommandがこの問題を解決できると知っていますが、私はこの解決策が嫌いです。

+0

おそらく、あなたはあなたのコマンドXAMLとのViewModelを示すコードサンプルを投稿することができますか? – Rachel

+0

CommandParameterを「更新」することによって何を意味するのかを記述することもできます。通常、これはビューモデル内の値にバインドされ、コマンドに渡されます。 – AxelEckenberger

答えて

1

私はMVVM Lightソースコードをダウンロードし、UpdateCommandParameterBeforeExecutingを導入しました。これはtrueに設定されているため、コマンド実行前にCommandParameterPropertyを明示的に更新します。ここで

は、ソースコードである:

... 
/// <summary> 
/// Specifies whether CommandParameter property should be updated before Command execution 
/// </summary> 
public bool UpdateCommandParameterBeforeExecuting 
{ 
    get; 
    set; 
} 
... 
protected override void Invoke(object parameter) 
{ 
    ... 
    var command = GetCommand(); 

    if (UpdateCommandParameterBeforeExecuting) 
    { 
     BindingOperations.GetBindingExpression(this, CommandParameterProperty).UpdateTarget(); 
    } 

    var commandParameter = CommandParameterValue; 
    ... 
} 
... 
関連する問題