Bra*_*onS 21 data-binding wpf selected listboxitem
我有一个WPF ListBox控件,我将其设置ItemsSource为项目对象的集合.如何将对象的IsSelected属性绑定ListBoxItem到Selected相应项对象的属性,而不将对象的实例设置为Binding.Source?
Anv*_*aka 41
只需覆盖ItemContainerStyle:
<ListBox ItemsSource="...">
<ListBox.ItemContainerStyle>
<Style TargetType="{x:Type ListBoxItem}">
<Setter Property="IsSelected" Value="{Binding Selected}"/>
</Style>
</ListBox.ItemContainerStyle>
</ListBox>
Run Code Online (Sandbox Code Playgroud)
哦,对了,我想你想从dr.WPF这美妙的文章:ItemsControl中:A到Z.
希望这可以帮助.