I don't think there is any supported way to do this in haml itself. In your code, you set the local value to ContextValidationMessagesProperty . The style organizers that you included would have a lower priority for the dependency property , and even if they were evaluated, they would set the value based on the specified value - do not clear it. Perhaps instead of setting a binding in the code, you might have a default style setter for the OmniBox that sets this property - for example,
<Setter Property="ContextValidationMessages" Value="{Binding ValidationMessages}" />
If you need to conditionally set the binding, you can create a custom IValueConverter that checks the specified type (passed as a parameter). eg.
public class IsAssignableFromConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { Type typeParameter = parameter as Type; if (typeParameter == null) return DependencyProperty.UnsetValue; return value != null && typeParameter.IsAssignableFrom(value.GetType()); } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { return DependencyProperty.UnsetValue; } }
Then you can use it as follows:
<local:IsAssignableFromConverter x:Key="isAssignableConverter" /> <Style TargetType="ui:OmniBox"> <Style.Triggers> <DataTrigger Binding="{Binding Converter={StaticResource isAssignableConverter}, ConverterParameter={x:Type ui:BindingObjectBaseExtended}}" Value="True"> <Setter Property="ContextValidationMessages" Value="{Binding ValidationMessages}" /> </DataTrigger> </Style.Triggers> </Style>
In the case when you do not want this property to be applied, you can set the style for this OmniBox instance to a new style and make sure to set the OverridesDefaultStyle property to true .
I believe another option is to create another dependency property that will call ClearValue in the ContextValidationMessages property, but it looks like this might be a maintenance issue.
source share