折叠可见性时如何禁用组合框元素的验证?
How to disable validation of a combox element when visibility is collapsed?
我想在 ComboBox 或 TextBox 的可见性折叠时禁用它们的验证。我可以在 XAML 代码中实现这一点吗?
<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.IsEnabled>
<MultiBinding Converter="{StaticResource InverseAndBooleansToBooleanConverter}"
Mode="TwoWay">
<Binding ElementName="XYZCb" Path="(Validation.HasError)"/>
</MultiBinding>
<Button.IsEnabled>
如果我没看错你需要什么:
<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>
别忘了删除您的 <Button.IsEnabled>
绑定。
我想在 ComboBox 或 TextBox 的可见性折叠时禁用它们的验证。我可以在 XAML 代码中实现这一点吗?
<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.IsEnabled>
<MultiBinding Converter="{StaticResource InverseAndBooleansToBooleanConverter}"
Mode="TwoWay">
<Binding ElementName="XYZCb" Path="(Validation.HasError)"/>
</MultiBinding>
<Button.IsEnabled>
如果我没看错你需要什么:
<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>
别忘了删除您的 <Button.IsEnabled>
绑定。