Databind to DataTemplate.IsSelected to View Model
How do I databind to the D开发者_Python百科ataTemplate's IsSelected property to my view model?
I suppose your DataTemplate is within an ItemsControl or a control that derives from it, like ListBox, DataGrid etc. In that case you bind IsSelected in the ItemContainerStyle
Example for ListBox
<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>
加载中,请稍侯......
精彩评论