我的代码后面的工作和ErrorHandler被调用。
XAML:
<Window Validation.Error="ErrorHandler">
<TextBox>
<TextBox.Text>
<Binding Path="SomeProperty" NotifyOnValidationError="True">
<local:MyValidationRule />
</Binding>
</TextBox.Text>
</TextBox>
</Window>
CS:
private void ErrorHandler(object sender, ValidationErrorEventArgs e)
{
............
}
现在我想使用Caliburn Micro的 Message.Attach 将其传输到我的ViewModel 委托方法永远不会被调用,任何想法为什么?
XAML:
<Window cal:Message.Attach="[Event Validation.Error] = [Action OnErrorsChanged($eventArgs)]">
<TextBox>
<TextBox.Text>
<Binding Path="SomeProperty" NotifyOnValidationError="True">
<local:MyValidationRule />
</Binding>
</TextBox.Text>
</TextBox>
</Window>
CS :(在我的ViewModel中)
private void OnErrorsChanged(ValidationErrorEventArgs e)
{
............ this code is never reached.
}
编辑:这也不起作用
<i:Interaction.Triggers>
<i:EventTrigger EventName="Validation.Error">
<cal:ActionMessage MethodName="OnErrorsChanged" />
</i:EventTrigger>
</i:Interaction.Triggers>
感谢。
答案 0 :(得分:2)
我遇到了同样的问题,似乎我找到了答案
using attached events with caliburn micro Message.Attach
这并不是您想要的。但我相信,这应该有所帮助。
编辑:
另外一个额外的技巧。这是我的代码片段:
<TextBox Grid.Row="2" >
<i:Interaction.Triggers>
<ui:RoutedEventTrigger RoutedEvent="Validation.ValidationError">
<cal:ActionMessage MethodName="OnTextboxError">
<cal:Parameter Value="$source" />
<cal:Parameter Value="$eventArgs" />
</cal:ActionMessage>
</ui:RoutedEventTrigger>
</i:Interaction.Triggers>
<TextBox.Text>
<Binding Path="TTT" NotifyOnValidationError="True" >
<Binding.ValidationRules>
<ui:TextValidationRule ValidationStep="UpdatedValue" />
</Binding.ValidationRules>
</Binding>
</TextBox.Text>
</TextBox>
public void OnTextboxError(object sender, ValidationErrorEventArgs e)
{
}
所以诀窍是:“RoutedEvent =”Validation.ValidationError“”