1

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.

eran otzap
  • 12,293
  • 20
  • 84
  • 139
  • I don't think you can do `Validation.Error` as Caliburn.Micro might not find it. Not sure if the attached properties is supported when doing `Message.Attach`. – 123 456 789 0 Mar 12 '14 at 18:39
  • i'm not sure either .. – eran otzap Mar 12 '14 at 18:41
  • What are you trying to do anyway? Why you wanna handle ErrorsChanged? – 123 456 789 0 Mar 12 '14 at 18:44
  • yes , but the validation error is raised from inner workings of a custom control in my view , it has nothing to do with any property in my ViewModel , all i wan't is to notify my ViewModel that Validation.Error event was raised and pass the args, i can think of ways to do this but i hoped this simple way to work. – eran otzap Mar 12 '14 at 18:49
  • May be something of use here: https://caliburnmicro.codeplex.com/discussions/243212 or here: http://www.redmountainsw.com/wordpress/2012/12/21/tutorial-validating-data-with-caliburn-micro/ or this chap's fixed sample: https://github.com/tibel/Caliburn.Micro.Extras/tree/master/samples/Samples.Validation – Chris Mar 14 '14 at 19:34

1 Answers1

2

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""

Community
  • 1
  • 1
Igor S
  • 98
  • 2
  • 9
  • 1
    I'm actually not using that any more , WPF validation's well i'll use the word Suck. but thanks i believe what you've done would work , all the problems with Message.Attach seem to occur using the Shorted syntax. – eran otzap Jul 02 '14 at 13:07
  • I'm agree with you. It's some kind of delirium. I had spent couple of days to determine why does textbox validation works " almost well", but datagrid column validation doesn't works in proper way. More over, each new knowladge I get will be useless for next task. – Igor S Jul 02 '14 at 14:12