验证ListBoxItem而不是ListBox [英] Validating a ListBoxItem rather than a ListBox

查看:73
本文介绍了验证ListBoxItem而不是ListBox的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个ListBox绑定到实现IDataErrorInfo的对象列表.我在ListBox上将ValidatesOnDataErrors属性设置为True.如果我选择了无效的项目,则列表框周围会出现一个红色边框.如何修改我的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中的Binding上设置ValidatesOnDataErrors,该Binding将绑定项目的属性绑定到显示该项目的控件.那应该使该控件周围出现红色边框.除此之外,如果边框仍在整个列表框上显示,则可以在列表框上设置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周围,则可以尝试设置列表框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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆