tags:

views:

23

answers:

1

I have a editable combobox that text is bound to an object property. I have associated a exceptionsValidationrule with the text property and it is working and turning the control red. I need to also disable a button but I can't seam to find how to check the validation.haserrors in this case

my XAML for the combo box

<ComboBox Margin="0,3,0,3"  Width="40" Name="CATCODE" IsEditable="True" >
    <ComboBox.Text>
       <Binding Path="CategoryCode" >
           <Binding.ValidationRules>
                <ExceptionValidationRule >

                </ExceptionValidationRule>
           </Binding.ValidationRules>
       </Binding>
    </ComboBox.Text>
</ComboBox>

The data trigger

<Style x:Key="DisbleOnValidation"  TargetType="Button">
    <Style.Triggers>
        <DataTrigger Binding="{Binding Path=Validation.HasError, ElementName=CATCODE}" Value="True" >
            <Setter Property="IsEnabled" Value="False"/>
        </DataTrigger>
    </Style.Triggers>
</Style>
+1  A: 

Try to change Path from Validation.HasError to (Validation.HasError)

<Style x:Key="DisbleOnValidation"  TargetType="Button">
    <Style.Triggers>
        <DataTrigger Binding="{Binding Path=(Validation.HasError), ElementName=CATCODE}" Value="True" >
            <Setter Property="IsEnabled" Value="False"/>
        </DataTrigger>
    </Style.Triggers>
</Style>

When Binding to Attached Properties, one should always include the '('...')'. Like

{Binding Path=(Grid.Row), ElementName=SomeElement}
{Binding Path=(Canvas.Left), ElementName=SomeOtherElement}
Meleak