wpf - 绑定到组合框验证。控件模板中的错误
问题描述
我有一个带有自定义的组合框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
属性绑定正确?谁能指出我正确的方向?
谢谢!
解决方案
推荐阅读
- django - 我的一个网址没有被翻译,给我一个 404 错误
- javascript - 从 CSS 样式 Javascript 中获取元素
- angular - 使用 Angular 6 向 Flask (Python) Web 服务上传文件
- office365 - 如何使用 Graph API 在 MS Team 中添加团队成员?
- c# - 带有两个参数的排序列表
- wordpress - Woocommerce结帐页面重定向到主页?
- time-complexity - 这是指数增长吗?
- web-scraping - 如何在 Ubuntu 16.04 的 Scrapy 中设置全局设置?
- data-structures - 什么指示字符串是否存在于 trie 中
- unity3d - 统一摩擦问题