Google WindowsPhone 8 LongListSelector: Scrollable List Items With Fixed Header's(C#-XAML) | SubramanyamRaju Xamarin & Windows App Dev Tutorials

Friday, 11 April 2014

WindowsPhone 8 LongListSelector: Scrollable List Items With Fixed Header's(C#-XAML)


Its very interesting requirement is "Making Fixed header visibility until its items scrollable and it will be stick to top when another header items touch and scroll top up. Because from the user perspective it is best practices for showing header until its items scrollable and it make-sense good thought.
Note: Before this sample Please read about LongListSelector  


To begin using LongListSelector first  add a reference to  the Microsoft.Phone.Controls.Toolkit.dll  assembly which is installed with the toolkit and
You will also need to add the "phone" prefix declaration. Make sure that your page declaration includes the "phone" namespace:
 The sample code should look like:
 <phone:LongListSelector Grid.Row="2" BorderThickness="2" BorderBrush="Blue" 
                                        ItemsSource="{Binding GroupedItems}" 
                                        ItemTemplate="{StaticResource ItemTemplate}"                      
                                        GroupHeaderTemplate="{StaticResource GroupHeader}" 
                                        JumpListStyle="{StaticResource JumpListStyle}"  
 Note:This sample is targeted on windows phone 8 os. So that this downloaded sample is not working with below versions


Lets start to understand this requirement

Sticky headers:

The native Windows Phone grouped list has the headers stick to the top as you scroll. The LongListSelector control in Windows Phone 8 has the same smooth effect.
Note the headers in the following screenshots.
Figure 1 - Notice group header "a"  
Figure 2 - Scrolling up, notice how "a" sticks to top  
Figure 3 - Notice how the group header "b" pushes "a" 
So that LongListSelector control is best fit for our requirement .Lets start now with few steps
The sample follows MVVM design pattern
  • Model - DataItem.cs
  • ViewModel - DataItemsViewModel.cs
  • Services - DataService.cs
  • View - MainPage.xaml - Thing to note here is how JumpListStyle Property is being used to modify the look and feel of the JumpList. LayoutMode of JumpListStyle - List and LayoutMode of LongListSelector - Grid
  • Helpers - KeyedList.cs - This class highlights how to prepare your grouped data in a data structure(IList of IList) bindable with LongListSelector.ItemsSource
The helper class - KeyedList.cs 
public class KeyedList<TKey, TItem> : List<TItem> 
        public TKey Key { protected setget; } 
        public KeyedList(TKey key, IEnumerable<TItem> items) 
            : base(items) 
            Key = key; 
        public KeyedList(IGrouping<TKey, TItem> grouping) 
            : base(grouping) 
            Key = grouping.Key; 
GroupedItems property on the DataItemsViewModel
 public class DataItemsViewModel 
        public List<KeyedList<string, DataItem>> GroupedItems 
                var ItemsList = DataService.GetItems(); 
                var GroupedItems = 
                    from data in ItemsList 
                    orderby data.TimeStamp 
                    group data by data.TimeStamp.ToString("y") into ItemsByMonth 
                    select new KeyedList<string, DataItem>(ItemsByMonth); 
                return new List<KeyedList<string, DataItem>>(GroupedItems); 
 MainPage.xaml - LongListSelector's ItemsSource property binding
<phone:LongListSelector Name="PhotoHubLLS" Margin="13,-30,0,0" 
                                        ItemsSource="{Binding GroupedPhotos}" 
                                        ItemTemplate="{StaticResource ItemTemplate}"                      
                                        GroupHeaderTemplate="{StaticResource GroupHeader}" 
                                        JumpListStyle="{StaticResource JumpListStyle}"  
JumpListStyle property along with the background converters from the platform to enable/disable groupheaders with items or not
  <phone:JumpListItemBackgroundConverter x:Key="BackgroundConverter"/> 
        <phone:JumpListItemForegroundConverter x:Key="ForegroundConverter"/> 
        <Style x:Key="JumpListStyle" TargetType="phone:LongListSelector"> 
            <Setter Property="LayoutModeValue="List" /> 
            <Setter Property="MarginValue="12,12,0,0"/> 
            <Setter Property="ItemTemplate"> 
                        <Border Background= 
                                "{Binding Converter={StaticResource BackgroundConverter}}"  
                            <TextBlock Text="{Binding Key}" 
                                       "{Binding Converter={StaticResource ForegroundConverter}}"                                        
                                       FontFamily="{StaticResource PhoneFontFamilySemiBold}" 

Note: Please share your thoughts,what you think about this post,Is this post really helpful for you?otherwise it would be very happy ,if you have any thoughts for to implement this requirement in any another way?I always welcome if you drop comments on this post and it would be impressive.

Follow me always at  

Have a nice day by  :)


  1. Hi..I tried the way you have told in this tutorial to proceed. But when I tap on header in the JumpList it is not jumping to that category.

    1. Can you share your working sample with full source file on onedrive.And send me that link,so that i can directly working on your sample.It may helpful for reproduce best result for your issue.

    2. Hi Akanksha,

      I think you are asked same question at MSDN forum

      Here in this forum i answered the your question.Please take look at.

  2. hi how to get the newly added item in loglist selector, currently i am using ItemRealized event but the probelm is at the time of loading also its fired .is there any way to realize if any new items added after initial loading.


Search Engine Submission - AddMe