开发者

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>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜