How to set implicit binding validation rules.

Sep 28, 2010 at 1:18 PM

For attach to control  error presentation we need to put, at XAML a ValidationRules section to Binding Object like:

...

<TextBox Name="field"  Style="{StaticResource textStyleTextBox}">
  <TextBox.Text>
    <Binding Path="value">
      <Binding.ValidationRules>
        <ExceptionValidationRule />
      </Binding.ValidationRules>
    </Binding>
  </TextBox.Text>
</TextBox>
....

For display at View the Exception Throws for the Binding Object, but Caliburn.Micro sets the implicit Binding so write

<TextBox Name="field"  Style="{StaticResource textStyleTextBox}">
  <TextBox.Text>
    <Binding>
      <Binding.ValidationRules>
        <ExceptionValidationRule />
      </Binding.ValidationRules>
    </Binding>
  </TextBox.Text>
</TextBox>
Generates a XAML syntax error.

The question is how can I add code to Caliburn.Micro fo add the default behavior for implicit binding ?

Thank you in advance and sorry for my poor english.

 

Coordinator
Sep 28, 2010 at 2:22 PM

Replace the delegate ConventionManager.ApplyValidation  In your implementation, you should determine whether validation should be turned on and set any/all related properties on the binding object. The current implementation looks like this:

        public static Action<Binding, Type, PropertyInfo> ApplyValidation = (binding, viewModelType, property) => {
#if SILVERLIGHT && !WP7
            if(typeof(INotifyDataErrorInfo).IsAssignableFrom(viewModelType))
                binding.ValidatesOnNotifyDataErrors = true;
#endif
#if !WP7
            if(typeof(IDataErrorInfo).IsAssignableFrom(viewModelType))
                binding.ValidatesOnDataErrors = true;
#endif
        };

So, you would take this code and augment it by adding the validation rules. Let me know if this works for you.

Sep 29, 2010 at 10:57 AM

Thanks, with this code I understand I have to implement the IDataErrorInfo at my VM for do implicit system validaton!!! Only I need a good template error and it is all.