WPF 组合框 Validation.ErrorTemplate 错误 [英] WPF Combobox Validation.ErrorTemplate error
本文介绍了WPF 组合框 Validation.ErrorTemplate 错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个组合框,我需要编辑其错误模板以在出现验证错误时显示红色边框.
I have a combobox that i need to edit its error template to show a red border when there is a validation error.
我正在使用以下样式
<Style TargetType="{x:Type ComboBox}" >
<Setter Property="Validation.ErrorTemplate">
<Setter.Value>
<ControlTemplate>
<DockPanel>
<Border BorderBrush="Red" BorderThickness="3">
<AdornedElementPlaceholder />
</Border>
</DockPanel>
</ControlTemplate>
</Setter.Value>
</Setter>
<Setter Property="FontFamily" Value="Segoe UI" />
<Setter Property="FontSize" Value="12" />
<Setter Property="VerticalAlignment" Value="Center" />
</Style>
发生验证错误时,边框永远不会出现.任何提示出了什么问题?
The border never shows up when validation errors occur. Any tips what is going wrong?
推荐答案
您发布的 Style
作品.您应该检查您的绑定,您是否将 ValidatesOnDataErrors=True
和 ValidatesOnExceptions=True
添加到 SelectedValue
的绑定中?
The Style
you posted works. You should check your binding, did you add ValidatesOnDataErrors=True
and ValidatesOnExceptions=True
to the binding of SelectedValue
?
这篇关于WPF 组合框 Validation.ErrorTemplate 错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文