问题描述
我有一个 ListBox 绑定到实现 IDataErrorInfo 的对象列表.我已将 ListBox 上的 ValidatesOnDataErrors 属性设置为 True.如果我选择了一个无效的项目,我的 ListBox 周围会出现一个红色边框.如何修改我的 ItemContainerStyle 以使红色边框出现在所选项目而不是实际的 ListBox 周围?
I have a ListBox bound to a list of objects that implement IDataErrorInfo. I have set the ValidatesOnDataErrors property to True on my ListBox. If I select an invalid item, a red border appears around my ListBox. How can I modify my ItemContainerStyle such that the red border appears arround the selected item rather than the actual ListBox?
推荐答案
您可以直接在ListBox的ItemTemplate中设置ValidatesOnDataErrors,在Binding上,将绑定项的属性绑定到显示它的控件上.这应该使红色边框出现在相关控件周围.如果除此之外,边框仍然显示在整个 ListBox 上,您可以在 ListBox 上设置 Validation.ErrorTemplate="{x:Null}".
You can set ValidatesOnDataErrors in the ListBox's ItemTemplate directly, on the Binding which binds the bound item's property to the control that displays it. That should make the red border show up around the control in question. If, in addition to that, the border still shows up on the ListBox as a whole, you can set Validation.ErrorTemplate="{x:Null}" on the ListBox.
如果您不希望边框围绕 ItemTemplate 中的一个控件显示,而是围绕整个 Item,您可以尝试设置 Listboxes ItemBindingGroup.
If you don't want the border to show around one control in the ItemTemplate, but around the whole Item, you could try setting the Listboxes ItemBindingGroup.
这篇关于验证 ListBoxItem 而不是 ListBox的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!


大气响应式网络建站服务公司织梦模板
高端大气html5设计公司网站源码
织梦dede网页模板下载素材销售下载站平台(带会员中心带筛选)
财税代理公司注册代理记账网站织梦模板(带手机端)
成人高考自考在职研究生教育机构网站源码(带手机端)
高端HTML5响应式企业集团通用类网站织梦模板(自适应手机端)