1

My LonglistSelector only displays GroupHeaderTemplate Data (ImageSource,Title) but ItemTemplate DataTemplate (SubItemTitle, Location) not displayed. How can i solve it?

public class Data
{
    public string Title { get; set; }
    public string ImageSource { get; set; }
    public List<SubItem> SubItems { get; set; }       
    public Data()
    {
        SubItems = new List<SubItem>();   
    }

}

public class SubItem
{
    public string SubItemTitle { get; set; }
    public string Location { get; set; }
}

<phone:LongListSelector ItemsSource="{Binding DataCollection}" Grid.Row="0" IsGroupingEnabled="True">
    <phone:LongListSelector.GroupHeaderTemplate>
        <DataTemplate>
            <StackPanel Orientation="Horizontal" Margin="10">
                <Image Source="{Binding ImageSource}"/>
                <TextBlock Text="{Binding Title}"/>
            </StackPanel>
        </DataTemplate>
    </phone:LongListSelector.GroupHeaderTemplate>
    <phone:LongListSelector.ItemTemplate>
        <DataTemplate>
            <StackPanel>
                <StackPanel Orientation="Horizontal">
                    <TextBlock Text="{Binding SubItemTitle}" Padding="5" FontSize="40"/>
                    <TextBlock Text="{Binding Location}" Padding="5" FontSize="40"/>
                </StackPanel>
            </StackPanel>
        </DataTemplate>
    </phone:LongListSelector.ItemTemplate>
</phone:LongListSelector>
Chubosaurus Software
  • 8,133
  • 2
  • 20
  • 26
Suzan Haque
  • 145
  • 1
  • 1
  • 7

2 Answers2

0

You have to convert whatever the class you are using to group the items from inheriting. Try using the List than the IEnumerator.

This one discusses the same longlistselector issue.

Grouped LongListSelector: headers appear, items don't

Hope it helps!

Community
  • 1
  • 1
Kulasangar
  • 9,046
  • 5
  • 51
  • 82
  • Thanks @Kulasangar, It is helpful; though it display only group key (Title) in header template, but i need to display "Title" and "ImageSource" in header template. how it possible if you know please show me the way. Thanks again. – Suzan Haque Sep 30 '14 at 05:20
0

This MSDN example helped me a lot when I had trouble understanding Grouping with LongListSelector

How to display data in a grouped list in LongListSelector for Windows Phone 8


It needs to be Grouped by a Key Value. Of all the of the examples I know of it's always something like this:

List<AlphaKeyGroup<your_data_type>> my_group_list;  // or
ObservableCollection<AlphaKeyGroup<your_data_type>> my_group_list;

Not a List that has a property that is a SubList.

AlphaKeyGroup is just a List<T>/ObservableCollection<T> with an extra property for a Key


Think of it this way, in your code how does the LongListSelector know that your "Title" is the group key rather than the "ImageSource"?

If the code on the MSDN page is too complicated to understand, you can always take the easier route and use LINQ using the GroupBy.

Here a SO example: Group by in LINQ

Community
  • 1
  • 1
Chubosaurus Software
  • 8,133
  • 2
  • 20
  • 26
  • Thanks @Chubosaurus Software. This process turn list into flat-list. Actually is it possible to make group not creating flat list??? – Suzan Haque Sep 05 '14 at 05:31
  • Not sure what you mean by flat. The return value from the group function should look like a directory-tree structure (or List of Lists, which the Key being the name of the parent tree). Here's a debug look at what it should output. http://i.imgur.com/jVd6KZk.png – Chubosaurus Software Sep 05 '14 at 05:52
  • Flat-List: If i create an Class with all property of SubItem class as well as "Title" and "ImageSource" property of Data Class and then I make a list of new class object that list is Flat-list. – Suzan Haque Sep 05 '14 at 13:18
  • You can't expect a control to work with your custom data and format . It is your job to convert your data to the format that it wants so it knows how to display it. In the example, he converts all his models into a Group Tree and then he passes it to the LLS. So you basically have to write a function that converts your data to a Group Tree as well if you want to use grouping. – Chubosaurus Software Sep 29 '14 at 19:12