首页 > 解决方案 > 绑定到组合框验证。控件模板中的错误

问题描述

我有一个带有自定义的组合框ControlTemplate,我想BackgroundColor根据 ControlsValidation.Errors属性更改它,这是一个 WPF 验证概念。

我决定使用Trigger. 我ControlTemplate.Triggers的定义是这样的

<ControlTemplate.Triggers>
    <DataTrigger Binding="{Binding RelativeSource={RelativeSource Self}, Path=(Validation.Errors), Converter={StaticResource validationRequiredError}}" Value="True">
       <Setter Property="Background" TargetName="Border" Value="DeepPink"/>
    </DataTrigger>
</ControlTemplate.Triggers>

我的组合框如下所示:

<ComboBox Margin="0" Height="30" HorizontalAlignment="Stretch" VerticalContentAlignment="Center"
                    IsSynchronizedWithCurrentItem="True"
                    DisplayMemberPath="Description"
                    IsEditable="False"
                    Style="{StaticResource ValidateableCombobox}"
                    ItemsSource="{Binding Lists.EstimatedDurations}"
                    SelectedValue="{Binding Model.EstimatedDuration, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
                    SelectedValuePath="Duration"/>

我确定其中定义的验证FluentValidation已运行并添加到Errors集合中,但触发器中指定的转换器永远不会运行。

我还检查了输出以验证绑定错误,但没有显示。我是否需要添加一些特殊的东西来ControlTemplate确保Errors属性绑定正确?谁能指出我正确的方向?

谢谢!

标签: wpfwpf-controls

解决方案


推荐阅读