我使用附加事件Validation.Error的TextBox。
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
}发布于 2013-07-01 10:11:16
基于你发布的链接,
类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>应该没问题的
https://stackoverflow.com/questions/17401082
复制相似问题