SimpleLongListSelector Control

This control is used to replace the existing LongListSelector in the Silverlight Toolkit for the Windows Phone 7. In fact it derives from that control. The problem that this control is solving is that the LongListSelector requires you create a lot of templates and custom data structures to work well. While this is often going to be the right way, this derived version has default values to show a standard look and feel for the control. You can use the control in your XAML without using any templates by default:


<my:SimpleLongListSelector x:Name="longList" />

Along with a default look and feel of a Grouped LongListSelector, it allows you to pass in a standard LINQ "group by" query as the data instead of creating custom classes:


var qry = from g in games
          orderby g.Genre, g.Name
          group g.Name by g.Genre into genre
          select genre;

longList.SetGroupingItemsSource<string>(qry.ToList());

The SetGroupItemsSource method allows you to specify the type of object to use for the display objects in the selector. Using 'string' makes it easy to create a selector that works with a simple string->string group. You can see what the control (with the lookup popup shown) here:

SimpleLongListSelector.jpg

Since the control is just derived from the LongListSelector you can use templates to override the individual parts of the design you want to take over (instead of needing all the templates by default):


<my:SimpleLongListSelector x:Name="longList">
  <my:SimpleLongListSelector.ItemTemplate>
    <DataTemplate>
      <StackPanel Orientation="Horizontal">
        <Image Source="{Binding ImageUrl}"
                Height="75" />
        <TextBlock Style="{StaticResource PhoneTextNormalStyle}"
                    Text="{Binding Name}" />
      </StackPanel>
    </DataTemplate>
  </my:SimpleLongListSelector.ItemTemplate>
</my:SimpleLongListSelector>

The data binding then can use the complex object instead of a simple string:


// For Complex Object and ItemTemplate
var qry = from g in games
          orderby g.Genre, g.Name
          group g by g.Genre into genre
          select genre;

longList.SetGroupingItemsSource<Game>(qry.ToList());

And the result looks like so:

ItemTemplate.jpg

Last edited Mar 13, 2011 at 7:21 AM by TheADOGuy, version 2

Comments

eibrahim Mar 24, 2011 at 4:36 AM 
How does it bind to the complex object? If I call SetGroupingItemsSource<Game>, I get the exception

Argument 1: cannot convert from 'System.Collections.Generic.List<System.Linq.IGrouping<string,string>>' to 'System.Collections.Generic.IEnumerable<System.Linq.IGrouping<string,Game>>'