我如何将数据绑定到我的视图模型的的IsSelected
属性?
<ListBox ItemsSource="{Binding MyCollection}">
<ListBox.ItemContainerStyle>
<Style TargetType="ListBoxItem">
<Setter Property="IsSelected" Value="{Binding Selected}"/>
</Style>
</ListBox.ItemContainerStyle>
<ListBox.ItemTemplate>
<DataTemplate>
<!-- ... -->
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
DataTemplate
都在一个ListBoxItem
容器中,而它是具有IsSelected
属性的容器。ListBoxItem
和DataTemplate
都具有相同的DataContext
。 - Fredrik Hedblad
DataTemplate
没有IsSelected
属性。请提供更多细节。 - Miklós Balogh