我在附加事件上使用Validation.Error
的文本框。
验证错误 http://msdn.microsoft.com/en-us/library/system.windows.controls.validation.error%28v=vs.100%29.aspx
我想将它绑定到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 事件附加到附加事件的命令 http://sergecalderara.wordpress.com/2012/08/23/how-to-attached-an-mvvm-eventtocommand-to-an-attached-event/
但我收到一个错误:
RoutedEventConverter cannot convert from System.String.
有人可以帮忙吗?
EDIT :
我的命令在ViewModel
public MyViewModel()
{
MyCmd = new RelayCommand<RoutedEventArgs>(Valid);
}
public RelayCommand<RoutedEventArgs> MyCmd { get; set; }
private void Valid(RoutedEventArgs args)
{
//Do something
}
根据您发布的链接,
班上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>
to
<i:Interaction.Triggers>
<view_model:RoutedEventTrigger RoutedEvent="{x:Static Validation.ErrorEvent}">
<mvvm:EventToCommand Command="{Binding MyCmd}" PassEventArgsToCommand="True" />
</view_model:RoutedEventTrigger>
</i:Interaction.Triggers>
应该没问题
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)