Enough is enough – I’ve just spent an hour searching around trying to find out how to read the ListViewSubItem values (if that’s correct terminology in XAML) from a ListView. Here’s a little ListView:
<ListView x:Name="CreatableAccounts" ItemsSource="{Binding Processable}" Margin="10,0">
<ListView.View>
<GridView>
<GridViewColumn Header="Site Name" DisplayMemberBinding="{Binding SiteName}"/>
<GridViewColumn Header="From Package" DisplayMemberBinding="{Binding FiCodeDLL.Name}"/>
</GridView>
</ListView.View>
</ListView>
and here’s my attempt to read the values which is clearly not going to work:
private void CreateAccounts_Click(object sender, RoutedEventArgs e)
{
ListViewItem selected = CreatableAccounts.SelectedItem;
selected.Ite // no Items, Text or similar property
}
Can anyone point me in the right direction? Grazie in advance for your help!
The ListView has a dependency property “SelectedItem” to which you can bind an instance of your collection child item, thus:
Now you can create a ViewModel that exposes an ObservableCollection filled with your items, and a single instance of an item which is your SelectedItem…
something like:
Hope this helps 🙂
Ian