将ListBoxItem的IsSelected属性绑定到该对象上的属性 [英] Binding the IsSelected property of ListBoxItem to a property on the object from it's source
本文介绍了将ListBoxItem的IsSelected属性绑定到该对象上的属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个WPF ListBox
控件,我正在将其 ItemsSource
设置为项目对象的集合。如何将 ListBoxItem
的 IsSelected
属性绑定到已选择$ c $没有将对象的实例设置为
Binding.Source
?
I have a WPF ListBox
control and I'm setting its ItemsSource
to a collection of item objects. How can I bind the IsSelected
property of the ListBoxItem
to a Selected
property of a corresponding item object without having an instance of the object to set as a Binding.Source
?
推荐答案
只需覆盖ItemContainerStyle:
Just override ItemContainerStyle:
<ListBox ItemsSource="...">
<ListBox.ItemContainerStyle>
<Style TargetType="{x:Type ListBoxItem}">
<Setter Property="IsSelected" Value="{Binding Selected}"/>
</Style>
</ListBox.ItemContainerStyle>
</ListBox>
哦,顺便说一下,我想你会喜欢dr.WPF的这篇精彩的文章: a href =http://drwpf.com/blog/itemscontrol-a-to-z/ =noreferrer> ItemsControl:A到Z 。
Oh, by the way, I think you'd like this wonderful articles from dr.WPF: ItemsControl: A to Z.
希望这有帮助。
这篇关于将ListBoxItem的IsSelected属性绑定到该对象上的属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文