Search code examples
windows-phone-7silverlight-toolkit

Simple way to use a LongListSelector to group a list alphabetically?


i want to use the LongListSelector to groupe a list of entries alphabetically. acutally i'm unsing a normal ListBox and it looks like:

  • Andhed
  • Bdihed
  • Cndie

I want to groupe all items like:

  • A
  • Andhed
  • B
  • Bdihed
  • C
  • Cndie

I know i can do it with the LongListSelector the problem is, that i dont want to change my data, its a simple List<String> is this possible? i dont want to add a additional structure like a groupe (e.g. A) which contains the items (e.g. Andhed).


Solution

  • With the LongListSelector you have to group your data before associating it with the control. This isn't so bad, especially if you use patterns such as Model-View-ViewModel.

    As an alternative, I have written a jump list control which is presented here:

    http://www.scottlogic.co.uk/blog/colin/2011/01/a-windows-phone-7-jump-list-control/

    With this control you use a CategoryProvider, which will group the data in your list:

      <!-- category provider - details how the items are grouped -->
      <l:JumpList.CategoryProvider>
        <l:AlphabetCategoryProvider PropertyName="Surname"/>
      </l:JumpList.CategoryProvider>