How to display a flat list using LongListSelector phone control for WP8

In the LongListSelector toolbox, the IsFlatList property previously existed, for which you had to set true to display a flat list without any grouping. But in the LongListSelector provided on the phone, this property is missing. That's what I'm 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 a ListBox and delete the LongListSelector property, it will display my list.

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

+7
source share
2 answers

In Windows Phone 8, the LongListSelector LayoutMode to List and IsGroupingEnabled for false parameters should display your anchor data data as a flat list, as in the version of the WP7 Toolkit control.

For example,

Given the Entity class

 public class Entity { public string Name { get; set; } public string Info { get; set; } public int ID { get; set; } } 

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

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

Then I create 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> 
+3
source

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

+2
source

All Articles