如何 运行 基于 if Validation.HasError = False 的 DataTrigger?
How to run a DataTrigger based on if Validation.HasError = False?
在我的 DataGridTextColumn
上,我想 运行 一个 DataTrigger
但只有当 Validation.HasError
是 False
这是我目前拥有的:
<DataGridTextColumn Header="Volts"
Binding="{Binding DcVolts, Converter={StaticResource StringToDecimalConverter}}"
Width="Auto">
<DataGridTextColumn.ElementStyle>
<Style TargetType="{x:Type TextBlock}"
BasedOn="{StaticResource DataGridTextColumnElementErrorStyle}">
<Style.Triggers>
<MultiDataTrigger>
<MultiDataTrigger.Conditions>
<Condition Binding="{Binding RelativeSource={RelativeSource Self}, Path=Validation.HasError}"
Value="False" />
<Condition Value="False">
<Condition.Binding>
<MultiBinding Converter="{StaticResource EqualityConverter}">
<Binding Path="DcVolts" />
<Binding Path="DcSpecVolts" />
</MultiBinding>
</Condition.Binding>
</Condition>
</MultiDataTrigger.Conditions>
<MultiDataTrigger.Setters>
<Setter Property="Background" Value="Orange" />
</MultiDataTrigger.Setters>
</MultiDataTrigger>
</Style.Triggers>
</Style>
</DataGridTextColumn.ElementStyle>
背后的想法是 Validation.HasError
必须是 False
才能使 MultiDataTrigger
将 BackGround
设置为 Orange
如果 EqualityConverter
是 False
这是因为如果 Validation.HasError
是 True
那么我想要我的 DataGridTextColumnElementErrorStyle
在 [=29] 上设置规则时提供的通常 Pink
背景=]失败。
我实际上更接近这个:
<DataGridTextColumn Header="Volts"
Binding="{Binding DcVolts, Converter={StaticResource StringToDecimalConverter}}"
Width="Auto">
<DataGridTextColumn.ElementStyle>
<Style TargetType="{x:Type TextBlock}" BasedOn="{StaticResource DataGridTextColumnElementErrorStyle}">
<Style.Triggers>
<DataTrigger Value="False">
<DataTrigger.Binding>
<MultiBinding Converter="{StaticResource EqualityConverter}" >
<Binding Path="DcVolts" />
<Binding Path="DcSpecVolts" />
</MultiBinding>
</DataTrigger.Binding>
<Setter Property="Background" Value="Orange" />
</DataTrigger>
<Trigger Property="Validation.HasError" Value="True">
<Setter Property="Background" Value="Pink" />
</Trigger>
</Style.Triggers>
</Style>
</DataGridTextColumn.ElementStyle>
但问题是 Validation.HasError
在 ToolTip
中提供的消息(根据我创建的规则)重复了。
非常感谢任何建议。
您应该在绑定路径周围添加括号,因为 Validation.HasError
是附加的 属性:
<Condition Binding="{Binding RelativeSource={RelativeSource Self}, Path=(Validation.HasError)}"
Value="True" />
在我的 DataGridTextColumn
上,我想 运行 一个 DataTrigger
但只有当 Validation.HasError
是 False
这是我目前拥有的:
<DataGridTextColumn Header="Volts"
Binding="{Binding DcVolts, Converter={StaticResource StringToDecimalConverter}}"
Width="Auto">
<DataGridTextColumn.ElementStyle>
<Style TargetType="{x:Type TextBlock}"
BasedOn="{StaticResource DataGridTextColumnElementErrorStyle}">
<Style.Triggers>
<MultiDataTrigger>
<MultiDataTrigger.Conditions>
<Condition Binding="{Binding RelativeSource={RelativeSource Self}, Path=Validation.HasError}"
Value="False" />
<Condition Value="False">
<Condition.Binding>
<MultiBinding Converter="{StaticResource EqualityConverter}">
<Binding Path="DcVolts" />
<Binding Path="DcSpecVolts" />
</MultiBinding>
</Condition.Binding>
</Condition>
</MultiDataTrigger.Conditions>
<MultiDataTrigger.Setters>
<Setter Property="Background" Value="Orange" />
</MultiDataTrigger.Setters>
</MultiDataTrigger>
</Style.Triggers>
</Style>
</DataGridTextColumn.ElementStyle>
背后的想法是 Validation.HasError
必须是 False
才能使 MultiDataTrigger
将 BackGround
设置为 Orange
如果 EqualityConverter
是 False
这是因为如果 Validation.HasError
是 True
那么我想要我的 DataGridTextColumnElementErrorStyle
在 [=29] 上设置规则时提供的通常 Pink
背景=]失败。
我实际上更接近这个:
<DataGridTextColumn Header="Volts"
Binding="{Binding DcVolts, Converter={StaticResource StringToDecimalConverter}}"
Width="Auto">
<DataGridTextColumn.ElementStyle>
<Style TargetType="{x:Type TextBlock}" BasedOn="{StaticResource DataGridTextColumnElementErrorStyle}">
<Style.Triggers>
<DataTrigger Value="False">
<DataTrigger.Binding>
<MultiBinding Converter="{StaticResource EqualityConverter}" >
<Binding Path="DcVolts" />
<Binding Path="DcSpecVolts" />
</MultiBinding>
</DataTrigger.Binding>
<Setter Property="Background" Value="Orange" />
</DataTrigger>
<Trigger Property="Validation.HasError" Value="True">
<Setter Property="Background" Value="Pink" />
</Trigger>
</Style.Triggers>
</Style>
</DataGridTextColumn.ElementStyle>
但问题是 Validation.HasError
在 ToolTip
中提供的消息(根据我创建的规则)重复了。
非常感谢任何建议。
您应该在绑定路径周围添加括号,因为 Validation.HasError
是附加的 属性:
<Condition Binding="{Binding RelativeSource={RelativeSource Self}, Path=(Validation.HasError)}"
Value="True" />