The Items
collection of a ListView
contains the actual business objects. How do I obtain the corresponding ListViewItem
given a business object (SelectedItem
)?
views:
235answers:
1
+1
A:
If you really need to, use the ListView
's ItemsContainerGenerator property. However, you can often get away with not setting an ItemContainerStyle
with Binding
s:
<ListView>
<ListView.ItemContainerStyle>
<Style TargetType="ListViewItem">
<Setter Property="IsSelected" Value="{Binding IsSpecial}"/>
</Style>
</ListView.ItemContainerStyle>
</ListView>
In the above XAML, the ListViewItem
s will be selected if the underlying bound object's IsSpecial
property is true
. Selecting/deselecting will update the IsSpecial
property.
HTH, Kent
Kent Boogaart
2009-06-26 11:48:03
ListView.ItemContainerGenerator.ContainerFromItem(ListView.SelectedItem)Got it! Thanks!
CannibalSmith
2009-06-26 12:22:28