如何基于Validation.HasError = False来运行DataTrigger?

问题描述 投票:0回答:1

[在我的DataGridTextColumn上,我只想运行DataTrigger,但仅当Validation.HasErrorFalse

这是我目前所拥有的:

<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

这是因为如果FalseValidation.HasError,那么当我在True上设置的规则失败时,我希望Pink提供的通常的DataGridTextColumnElementErrorStyle背景。

我实际上与之接近:

Property

但是问题是<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中提供的消息(根据我创建的规则)。>

非常感谢任何建议。

在我的DataGridTextColumn上,我只想在Validation.HasError为False时运行一个DataTrigger,这是我目前所拥有的:

wpf datagrid datatrigger
1个回答
0
投票

由于ToolTip是附加属性,因此应在绑定路径周围添加括号:

© www.soinside.com 2019 - 2024. All rights reserved.