Select ListView GroupStyle Items

295 views Asked by At

I have a ListView with GroupStyle in UWP like in the example here. I have the following HeaderTemplate:

<GroupStyle.HeaderTemplate>
  <DataTemplate x:DataType="data:GroupInfoList">
    <Grid Tapped="Header_Tapped">
        <TextBlock Text="{x:Bind Key}" />
    </Grid>
  </DataTemplate>
</GroupStyle.HeaderTemplate>

and I can get the selected Key by

private void Header_Tapped(object sender, Windows.UI.Xaml.Input.TappedRoutedEventArgs e)
{
  var selItem = (sender as Grid).DataContext as GroupInfoList;
  var selKey = selItem.Key;
}

Now my problem is that despite knowing the selected Key, I cannot access the Items from it. In Debug, I can see the Count Property and it is equal to the number of elements, that are inside the Group, but I do not know, how to iterate through it.

I would very much like to iterate through all Items, that have the same Key as selKey and set a boolean property called _isVisible for all those items. What is a good/fast/effective way to accomplish this?

1

There are 1 answers

1
Jay Zuo On BEST ANSWER

GroupInfoList is derived from List<object>. It contains all the Contact with the same Key. When you get selItem, you can use following code to iterate through it like iterate through a List.

foreach (var item in selItem)
{
    var contact = item as Contact;
    //suppose you have add a _isVisible property in Contact
    contact._isVisible = true;
}