Created
September 15, 2013 09:16
-
-
Save Stephanvs/6569108 to your computer and use it in GitHub Desktop.
Windows Phone 8 LongListSelector
Found at: http://codepaste.net/2xycf8
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<Grid x:Name="LayoutRoot" Background="Transparent"> | |
<phone:Pivot> | |
<phone:PivotItem Header="Flat List"> | |
<phone:LongListSelector | |
HideEmptyGroups="True" | |
IsGroupingEnabled="False" | |
LayoutMode="List" | |
ItemsSource="{Binding Items}" | |
ListHeaderTemplate="{StaticResource MyListHeaderTemplate}" | |
ListFooterTemplate="{StaticResource MyListFooterTemplate}" | |
GroupHeaderTemplate ="{StaticResource MyGroupHeaderTemplate}" | |
GroupFooterTemplate ="{StaticResource MyGroupFooterTemplate}" | |
ItemTemplate="{StaticResource MyParentItemTemplate}"> | |
</phone:LongListSelector> | |
</phone:PivotItem> | |
<phone:PivotItem Header="Flat Grid"> | |
<phone:LongListSelector | |
HideEmptyGroups="True" | |
IsGroupingEnabled="False" | |
LayoutMode="List" | |
ItemsSource="{Binding Items}" | |
ListHeaderTemplate="{StaticResource MyListHeaderTemplate}" | |
ListFooterTemplate="{StaticResource MyListFooterTemplate}" | |
GroupHeaderTemplate ="{StaticResource MyGroupHeaderTemplate}" | |
GroupFooterTemplate ="{StaticResource MyGroupFooterTemplate}" | |
ItemTemplate="{StaticResource MyParentItemTemplate}"> | |
</phone:LongListSelector> | |
</phone:PivotItem> | |
<phone:PivotItem Header="Grouped List"> | |
<phone:LongListSelector | |
HideEmptyGroups="True" | |
IsGroupingEnabled="True" | |
LayoutMode="List" | |
ItemsSource="{Binding Items}" | |
ListHeaderTemplate="{StaticResource MyListHeaderTemplate}" | |
ListFooterTemplate="{StaticResource MyListFooterTemplate}" | |
GroupHeaderTemplate ="{StaticResource MyGroupHeaderTemplate}" | |
GroupFooterTemplate ="{StaticResource MyGroupFooterTemplate}" | |
ItemTemplate="{StaticResource MyChildItemTemplate}"> | |
<phone:LongListSelector.JumpListStyle> | |
<Style TargetType="phone:LongListSelector"> | |
<Setter Property="Margin" Value="20" /> | |
<Setter Property="LayoutMode" Value="Grid" /> | |
<Setter Property="GridCellSize" Value="200,200" /> | |
<Setter Property="ItemTemplate" | |
Value="{StaticResource MyLongListSelector}" /> | |
</Style> | |
</phone:LongListSelector.JumpListStyle> | |
</phone:LongListSelector> | |
</phone:PivotItem> | |
<phone:PivotItem Header="Grouped Grid"> | |
<phone:LongListSelector | |
HideEmptyGroups="True" | |
IsGroupingEnabled="True" | |
LayoutMode="Grid" | |
GridCellSize="100,100" | |
ItemsSource="{Binding Items}" | |
ListHeaderTemplate="{StaticResource MyListHeaderTemplate}" | |
ListFooterTemplate="{StaticResource MyListFooterTemplate}" | |
GroupHeaderTemplate ="{StaticResource MyGroupHeaderTemplate}" | |
GroupFooterTemplate ="{StaticResource MyGroupFooterTemplate}" | |
ItemTemplate="{StaticResource MyChildItemTemplate}"> | |
<phone:LongListSelector.JumpListStyle> | |
<Style TargetType="phone:LongListSelector"> | |
<Setter Property="Margin" Value="20" /> | |
<Setter Property="LayoutMode" Value="List" /> | |
<Setter Property="ItemTemplate" | |
Value="{StaticResource MyLongListSelector}" /> | |
</Style> | |
</phone:LongListSelector.JumpListStyle> | |
</phone:LongListSelector> | |
</phone:PivotItem> | |
</phone:Pivot> | |
</Grid> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Parent | |
{ | |
public int Id { get; set; } | |
public string Name { get; set; } | |
public List<Child> Children { get; set; } | |
} | |
public class Child | |
{ | |
public int Id { get; set; } | |
public string Name { get; set; } | |
} | |
public class KeyedList<K, I> : List<I> | |
{ | |
public K Key { protected set; get; } | |
public KeyedList(K key, IEnumerable<I> items) | |
: base(items) | |
{ Key = key; } | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MyViewModel | |
{ | |
public List<KeyedList<Parent, Child>> Items | |
{ | |
get | |
{ | |
// generate fake data | |
var _Parents = Enumerable.Range(1, 5).Select(x => new Parent | |
{ | |
Id = x, | |
Name = string.Format("Parent {0}", x), | |
Children = Enumerable.Range(1, 5).Select(y => new Child { Id = y, Name = string.Format("Child {0}", y) }).ToList(), | |
}); | |
var _Keys = _Parents.Select(x => new KeyedList<Parent, Child>(x, x.Children)); | |
var _List = new List<KeyedList<Parent, Child>>(_Keys); | |
// include one empty parent | |
_List.Insert(3, new KeyedList<Parent, Child>(new Parent { Name = "Empty Parent"}, new List<Child>())); | |
return _List; | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<phone:PhoneApplicationPage.Resources> | |
<phone:JumpListItemBackgroundConverter x:Key="BackgroundConverter"/> | |
<phone:JumpListItemForegroundConverter x:Key="ForegroundConverter"/> | |
<DataTemplate x:Name="MyListHeaderTemplate"> | |
<Border Background="Orange" Padding="10" Margin="5"> | |
<TextBlock>List Header</TextBlock> | |
</Border> | |
</DataTemplate> | |
<DataTemplate x:Name="MyListFooterTemplate"> | |
<Border Background="Blue" Padding="10" Margin="5"> | |
<TextBlock>List Footer</TextBlock> | |
</Border> | |
</DataTemplate> | |
<DataTemplate x:Name="MyGroupHeaderTemplate"> | |
<Border Background="Red" Padding="10" Margin="5"> | |
<TextBlock>Group Header <Run Text="{Binding Key.Name}" /></TextBlock> | |
</Border> | |
</DataTemplate> | |
<DataTemplate x:Name="MyGroupFooterTemplate"> | |
<Border Background="Red" Padding="10" Margin="5"> | |
<TextBlock>Group Footer <Run Text="{Binding Key.Name}" /></TextBlock> | |
</Border> | |
</DataTemplate> | |
<DataTemplate x:Name="MyParentItemTemplate"> | |
<Border Background="Gray" Padding="10" Margin="5"> | |
<TextBlock>Parent Item <Run Text="{Binding Key.Name}" /></TextBlock> | |
</Border> | |
</DataTemplate> | |
<DataTemplate x:Name="MyChildItemTemplate"> | |
<Border Background="Gray" Padding="10" Margin="5"> | |
<TextBlock TextWrapping="Wrap">Child Item <Run Text="{Binding Name}" /></TextBlock> | |
</Border> | |
</DataTemplate> | |
<DataTemplate x:Name="MyLongListSelector"> | |
<Border Background="{Binding Converter={StaticResource BackgroundConverter}}" Padding="10" Margin="5"> | |
<TextBlock FontSize="28" Text="{Binding Key.Name}" Foreground="{Binding Converter={StaticResource ForegroundConverter}}" /> | |
</Border> | |
</DataTemplate> | |
</phone:PhoneApplicationPage.Resources> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment