0

I want to disable the validation of a ComboBox or a TextBox when their visibility is collapsed. Can I realize this within the XAML code?

            <ComboBox Name="XYZCb" ItemsSource="{Binding XYZ}" Visibility="{Binding IsVisible, Converter={StaticResource BoolToVisibilityConverter}}">
                <ComboBox.Text>
                    <Binding Path="xyz" UpdateSourceTrigger="PropertyChanged">
                        <Binding.ValidationRules>
                            <valid:ValidationRule ValidatesOnTargetUpdated="True"/>
                        </Binding.ValidationRules>
                    </Binding>
                </ComboBox.Text>
            </ComboBox>

Button property binding:

<Button.IsEnabled>
    <MultiBinding Converter="{StaticResource InverseAndBooleansToBooleanConverter}"
                  Mode="TwoWay">
        <Binding ElementName="XYZCb" Path="(Validation.HasError)"/> 
    </MultiBinding>
<Button.IsEnabled>
2
  • 1
    Does this answer your question? Stop ValidationRule if ComboBox is Collapsed
    – Andy
    Commented Sep 5, 2021 at 17:46
  • I think this is a misunderstanding here @Andy . From my understanding collapsed is refered to the visibility of the whole combobox, not to the expander. Commented Sep 5, 2021 at 18:03

1 Answer 1

2

If I understand correctly what you need:

    <Button>
        <Button.Style>
            <Style TargetType="Button">
                <Style.Triggers>
                    <MultiDataTrigger>
                        <MultiDataTrigger.Conditions>
                            <Condition Binding="{Binding Path=(Validation.HasError), ElementName=XYZCb}" Value="True"/>
                            <Condition Binding="{Binding Visibility, ElementName=XYZCb}" Value="Visible"/>
                        </MultiDataTrigger.Conditions>
                        <Setter Property="IsEnabled" Value="False"/>
                    </MultiDataTrigger>
                </Style.Triggers>
            </Style>
        </Button.Style>
    </Button>

Don't forget to remove your <Button.IsEnabled> binding.

1
  • Thank you so much. That's what I was looking for!
    – patrickgc
    Commented Sep 5, 2021 at 20:08

Not the answer you're looking for? Browse other questions tagged or ask your own question.