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

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

问题描述

我有一个 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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