I have the LongListSelector that's working as it should, I want only to enable the grouping now. Like it is in the PeopleHub and the JumpList too. How do I do that ? I have checked an example on MSDN but it's complicated and it didn't work for me, maybe I don't understand it right.
I don't fill the LongListSelector with xaml or C# code, but with xml parsing.
First I parse the xml:
XDocument xml = XDocument.Load("xmlfile.xml");
var data = from query in xml.Descendants("country")
select new Country
{
Name = (string)query.Element("name"),};
and set the itemsSource:
countriesList.ItemsSource = data.ToList();
// Set the data context of the listbox control to the sample data
DataContext = App.ViewModel;
}
I have the Country class:
public class Country
{
string name;
public string Name
{
get { return name; }
set { name = value; }
}}
Now I would like to group this countries by name. How can I do that ?
Thanks for your help.
In the sample they create a fancy-pants helper class called
AlphaKeyGroup<T>
. Really though, you just need a class to contain each grouping:Bind the
ItemsSource
to this:I'm guessing that the
LongListSelector
looks for a property called "Key" as the group header (magic strings!).Also, don't forget to set
IsGroupingEnabled="true"
on the control.