CannibalSmith
CannibalSmith

Reputation: 4820

How do I access ListViewItem?

The Items collection of a ListView contains the actual business objects. How do I obtain the corresponding ListViewItem given a business object (SelectedItem)?

Upvotes: 2

Views: 909

Answers (1)

Kent Boogaart
Kent Boogaart

Reputation: 178660

If you really need to, use the ListView's ItemsContainerGenerator property. However, you can often get away with not setting an ItemContainerStyle with Bindings:

<ListView>
    <ListView.ItemContainerStyle>
        <Style TargetType="ListViewItem">
            <Setter Property="IsSelected" Value="{Binding IsSpecial}"/>
        </Style>
    </ListView.ItemContainerStyle>
</ListView>

In the above XAML, the ListViewItems will be selected if the underlying bound object's IsSpecial property is true. Selecting/deselecting will update the IsSpecial property.

Upvotes: 4

Related Questions