Question

The following works and ErrorHandler in my code behind is called.

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)
  {
             ............ 
  }

Now i would like to transfer that to my ViewModel using Caliburn Micro's Message.Attach The delegated method is never called, any idea why ?

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: (In My ViewModel)

  private void OnErrorsChanged(ValidationErrorEventArgs e)
  {
       ............ this code is never reached.
  }

Edit : This also doesn't work

<i:Interaction.Triggers>
     <i:EventTrigger EventName="Validation.Error">
         <cal:ActionMessage MethodName="OnErrorsChanged" />         
     </i:EventTrigger>
 </i:Interaction.Triggers>

Thanks.

Was it helpful?

Solution

I had the same problem, and it seems that I found the answer

using attached events with caliburn micro Message.Attach

This is not exactly what you are looking for. But I belive, this should help.

EDIT:

Another one additional trick. Here is my code snippet:

<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)
{

}

So the trick is: "RoutedEvent="Validation.ValidationError""

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top