4

Validation.ErrorTextBox の添付イベントで使用します。

Validation.Error

にバインドしたいEventToCommand

通常は機能しません:

 <TextBox Height="20" Width="150" Text="{Binding MyProperty,NotifyOnValidationError=True,ValidatesOnDataErrors=True}" ><!--Validation.Error="TextBox_Error"-->
     <i:Interaction.Triggers>
        <i:EventTrigger EventName="Validation.Error">
           <mvvm:EventToCommand Command="{Binding MyCmd}" PassEventArgsToCommand="True" ></mvvm:EventToCommand>
        </i:EventTrigger>
     </i:Interaction.Triggers>
  </TextBox>

それで、私はそれを行う方法を見つけました、あなたは以下のリンクでそれを見ることができます:

添付イベントにコマンドへの mvvm イベントを添付

しかし、私はエラーが発生します:

RoutedEventConverter cannot convert from System.String.

ここに画像の説明を入力

誰でも助けることができますか?

編集 :

私のコマンドViewModel

  public MyViewModel()
    {
        MyCmd = new RelayCommand<RoutedEventArgs>(Valid);
    }

    public RelayCommand<RoutedEventArgs> MyCmd { get; set; }

    private void Valid(RoutedEventArgs args)
    {
        //Do something
    }
4

1 に答える 1

4

あなたが投稿したリンクに基づいて、

クラスは a をRoutedEventTrigger想定してRoutedEventおり、xaml は文字列Validation.Errorを必要な型に変換できません。

だから切り替える

<i:Interaction.Triggers>
  <view_model:RoutedEventTrigger RoutedEvent="Validation.Error">
    <mvvm:EventToCommand Command="{Binding MyCmd}" PassEventArgsToCommand="True" />
  </view_model:RoutedEventTrigger>
</i:Interaction.Triggers>

<i:Interaction.Triggers>
  <view_model:RoutedEventTrigger RoutedEvent="{x:Static Validation.ErrorEvent}">
    <mvvm:EventToCommand Command="{Binding MyCmd}" PassEventArgsToCommand="True" />
  </view_model:RoutedEventTrigger>
</i:Interaction.Triggers>

そしてそれはうまくいくはずです

于 2013-07-01T10:11:16.503 に答える