Validating a ListBoxItem rather than a ListBox

主宰稳场 提交于 2019-12-23 03:18:50

问题


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?


回答1:


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.

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.



来源:https://stackoverflow.com/questions/13457318/validating-a-listboxitem-rather-than-a-listbox

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!