How to display flatlist using LongListSelector phone control of WP8
Asked Answered
H

2

7

In toolkit LongListSelector, there used to be a property IsFlatList which needed to be set to true to display flat list without any grouping. But in the LongListSelector provided in phone control, this property is missing. Here is what I am doing

<phone:LongListSelector Name="myList"  IsGroupingEnabled="False" LayoutMode="List" ItemsSource="{Binding Source ={StaticResource SortedList} }" CacheMode="BitmapCache"  >
                <phone:LongListSelector.ItemTemplate>
                    <DataTemplate>
                        <components:MyControl  CacheMode="BitmapCache" MyItem="{Binding}"/>
                    </DataTemplate>
                </phone:LongListSelector.ItemTemplate>
            </phone:LongListSelector>

If I change the control to ListBox and remove LongListSelector specific property then it display my list.

Can someone please tell me what I am missing? I am following this(Remarks) documentation of LongListSelector

Hogweed answered 8/1, 2013 at 8:7 Comment(0)
R
3

In the Windows Phone 8 Version of the LongListSelector setting LayoutMode to List and IsGroupingEnabled to false should display your databound data as a flat list like in the WP7 Toolkit version of the control.

For example,

Given an Entity class

public class Entity
{
    public string Name
    {
        get;
        set;
    }

    public string Info
    {
        get;
        set;
    }

    public int ID
    {
        get;
        set;
    }
}

All I need to do is create an ObservableCollection of Entity on my page and bind it to the itemsource of my LongListSelector (named list).

ObservableCollection<Entity> data = new ObservableCollection<Entity>();
list.ItemsSourdce = data;

Then I create the entities and add them to the collection.

Here is the XAML for my LongListSelector:

<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
        <phone:LongListSelector Name="list" HorizontalAlignment="Left" Height="609" VerticalAlignment="Top" Width="456" LayoutMode="List" IsGroupingEnabled="False" >
            <phone:LongListSelector.ItemTemplate>
                <DataTemplate>
                    <StackPanel VerticalAlignment="Top">
                        <TextBlock FontWeight="Bold"  Text="{Binding Name}" />
                        <TextBlock Text="{Binding Info}" />
                    </StackPanel>
                </DataTemplate>
            </phone:LongListSelector.ItemTemplate>
        </phone:LongListSelector>
    </Grid>
Richellericher answered 17/1, 2013 at 19:39 Comment(3)
Hmmmmmmm. After spending several hours playing with LongListSelector in WP8 and not having my data display I changed Grouping enabled to false and voilà the data appeared! Maybe something for other WP8 (XAML?) noobs to consider. I am setting ItemSources in code behind. Must be how I have structured data which is just a List<> of simple objects with no grouping.Rudiger
I showed in my example that isGroupingEnabled must be set to false if you want a normal "list" and not a grouped list.Richellericher
@SleepyBoBos, it says to do just that in the first sentence of this answer.Xenophobia
F
2

LayoutMode ="List" that's all you need.

Fortuneteller answered 17/1, 2013 at 23:21 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.