List of list headings

So I'm trying, very simply, to display items in a Windows 10 view and then sort them into groups. Everything works fine, except I can't bind the group name.

Here is my current xaml:

<ListView ItemsSource="{Binding Source={StaticResource cvsEpisodes}}"/>
  <ListView.ItemTemplate>
    <DataTemplate>
      <Grid>
        <TextBlock Text="{Binding EpisodeNB}"/>
        <TextBlock Text="{Binding EpisodeTT}"/>
        <TextBlock Text="{Binding EpisodeDESC}"/>
      </Grid>
    </DataTemplate>
  </ListView.ItemTemplate>
  <ListView.GroupStyle>
    <GroupStyle>
      <GroupStyle.HeaderTemplate>
        <DataTemplate>
          <Grid>
            <TextBlock Text="{Binding SEASONNB}"/>
          </Grid>
        </DataTemplate>
      </GroupStyle.HeaderTemplate>
    </GroupStyle>
  </ListView.GroupStyle>
</ListView>
<Page.Ressources>
    <CollectionViewSource x:Name="cvsEpisodes" IsSourceGrouped="True"/>
</Page.Ressources>

      

And C # which is executed by the OnNavigatedTo event:

List < EPISODELST > Episodes = new List < EPISODELST > ();
var episodes = root.episodes.Select(m = >new EPISODELST {EpisodeTT = m.title, EpisodeNB = m.episode.ToString(), EpisodeDESC = m.overview, SEASONNB = m.season.ToString()}).ToList();

foreach(EPISODELST s in episodes) 
    {
        Episodes.Add(new EPISODELST {EpisodeTT = s.EpisodeTT, EpisodeDESC = s.EpisodeDESC, EpisodeNB = "EPISODE " + s.EpisodeNB, SEASONNB = s.SEASONNB });
    }

var result = from EPISODELST in Episodes group EPISODELST by EPISODELST.SEASONNB into grp orderby grp.Key select grp;
cvsEpisodes.Source = result;

      

(EPISODELST and episodes are two classes, but don't need to be inserted here)

I have seen various other options for grouped lists on the internet, but they are all more complex than this, and I guess this should work because I can tell the code can successfully sort all the data correctly. The problem is probably only related to the TextBlock binding, but I've tried various other things I've found on the internet like {Binding = Name} or {Binding Key.Name}, but nothing seems to work.

+3


source to share


1 answer


So in the end it was very easy. I found that the azer froze deep in the sample Microsoft UWP Github page . It must be attached to{Binding Key}

Inside GroupStyle:



<TextBlock Text="{Binding Key}"/>

      

+4


source







All Articles