首页 > 代码库 > windows phone 8.1 listbox 分组显示
windows phone 8.1 listbox 分组显示
初次了解list分组的朋友可以先看看,如下链接!
http://www.cnblogs.com/linzheng/archive/2014/09/28/3999217.html
链接的内容 只是介绍了基本雏形,我下面把我个人的一些修改加了进去,
希望能对大家有所帮助! 如果发现我哪有不足,请提出,相互交流才可以更好的进步
.xaml 代码
- <!--分组 缩略list 背景颜色-->
- <Page.Resources>
- <prim:JumpListItemBackgroundConverter x:Key="BackgroundConverter" Enabled="#FF0086D0" Disabled="{ThemeResource ContentDialogDimmingThemeBrush}"/>
- <prim:JumpListItemForegroundConverter x:Key="ForegroundConverter"/>
- </Page.Resources>
- <Grid>
- <Grid.Resources>
- <!--创建数据源对象,注意ItemContent属性就是数据源中真正的基础数据的列表的属性,必须设置该属性的值数据源才能定位到实际绑定的数据实体对象-->
- <CollectionViewSource x:Name="itemcollectSource" IsSourceGrouped="true" ItemsPath="InternalList" />
- </Grid.Resources>
- <SemanticZoom x:Name="semanticZoom">
- <SemanticZoom.ZoomedInView>
- <!-- 在这里放置GridView(或ListView)以表示放大视图 -->
- <ListView x:Name="inView">
- <ListView.GroupStyle>
- <GroupStyle HidesIfEmpty="True">
- <!--用于显示列表头的数据项的模板-->
- <GroupStyle.HeaderTemplate >
- <DataTemplate>
- <Border Background="#FF0086D0" Height="50" Width="50">
- <TextBlock Text="{Binding Key}" FontSize="37.333" Foreground="White" HorizontalAlignment="Center" VerticalAlignment="Center"/>
- </Border>
- </DataTemplate>
- </GroupStyle.HeaderTemplate>
- </GroupStyle>
- </ListView.GroupStyle>
- <!--用于显示列表的数据项的模板-->
- <ListView.ItemTemplate>
- <DataTemplate>
- <StackPanel>
- <TextBlock Text="{Binding Title}" Height="40" FontSize="30"></TextBlock>
- </StackPanel>
- </DataTemplate>
- </ListView.ItemTemplate>
- </ListView>
- </SemanticZoom.ZoomedInView>
- <SemanticZoom.ZoomedOutView>
- <!-- 在这里放置GridView(或ListView)以表示缩小视图 -->
- <GridView x:Name="outView" Background="#7F000000" Margin="0,10,0,0">
- <!--用于显示弹出的分组列表视图的数据项的模板-->
- <GridView.ItemTemplate>
- <DataTemplate>
- <Grid Width="90" Height="90">
- <Border Background="{Binding Converter={StaticResource BackgroundConverter}}" Margin="0,10,10,0" >
- <TextBlock Text="{Binding Group.Key}" FontSize="37.333" HorizontalAlignment="Left" VerticalAlignment="Bottom"
- Foreground="{Binding Converter={StaticResource ForegroundConverter}}"/>
- </Border>
- </Grid>
- </DataTemplate>
- </GridView.ItemTemplate>
- </GridView>
- </SemanticZoom.ZoomedOutView>
- </SemanticZoom>
- </Grid>
,cs 代码
- public void fun()
- {
- this.InitializeComponent();
- // 先创建一个普通的数据集合
- List<Item> mainItem = new List<Item>();
- for (int i = 0; i < 10; i++)
- {
- mainItem.Add(new Item { Content = "A", Title = "Test A" + i });
- mainItem.Add(new Item { Content = "B", Title = "Test B" + i });
- mainItem.Add(new Item { Content = "C", Title = "Test C" + i });
- mainItem.Add(new Item { Content = "D", Title = "Test A" + i });
- mainItem.Add(new Item { Content = "F", Title = "Test B" + i });
- mainItem.Add(new Item { Content = "G", Title = "Test C" + i });
- mainItem.Add(new Item { Content = "C", Title = "Test C" + i });
- mainItem.Add(new Item { Content = "C", Title = "Test C" + i });
- mainItem.Add(new Item { Content = "C", Title = "Test C" + i });
- mainItem.Add(new Item { Content = "H", Title = "Test A" + i });
- mainItem.Add(new Item { Content = "I", Title = "Test B" + i });
- mainItem.Add(new Item { Content = "M", Title = "Test C" + i });
- mainItem.Add(new Item { Content = "N", Title = "Test A" + i });
- mainItem.Add(new Item { Content = "O", Title = "Test B" + i });
- mainItem.Add(new Item { Content = "P", Title = "Test C" + i });
- mainItem.Add(new Item { Content = "Q", Title = "Test A" + i });
- mainItem.Add(new Item { Content = "R", Title = "Test B" + i });
- mainItem.Add(new Item { Content = "S", Title = "Test C" + i });
- mainItem.Add(new Item { Content = "T", Title = "Test A" + i });
- mainItem.Add(new Item { Content = "W", Title = "Test B" + i });
- mainItem.Add(new Item { Content = "V", Title = "Test C" + i });
- mainItem.Add(new Item { Content = "U", Title = "Test A" + i });
- mainItem.Add(new Item { Content = "X", Title = "Test B" + i });
- mainItem.Add(new Item { Content = "Y", Title = "Test C" + i });
- mainItem.Add(new Item { Content = "Z", Title = "Test C" + i });
- }
- // 使用LINQ语法把普通的数据集合转换成分组的数据集合
- //List<ItemInGroup> Items = (from item in mainItem group item by item.Content into newItems select new ItemInGroup { Key = newItems.Key, ItemContent = newItems.ToList() }).ToList();
- List<AlphaKeyGroup<Item>> Items = AlphaKeyGroup<Item>.CreateGroups(
- mainItem,
- (Item s) => { return s.Title; },
- true);
- // 设置CollectionViewSource对象的数据源
- this.itemcollectSource.Source = Items;
- // 分别对两个视图进行绑定
- outView.ItemsSource = itemcollectSource.View.CollectionGroups;
- inView.ItemsSource = itemcollectSource.View;
- }
- }
- // 分组的实体类,也就是分组的数据集合最外面的数据项的实体类
- public class ItemInGroup
- {
- // 分组的组头属性
- public string Key { get; set; }
- // 分组的数据集合
- public List<Item> ItemContent { get; set; }
- }
- // 列表的数据实体类
- public class Item
- {
- public string Title { get; set; }
- public string Content { get; set; }
- }
windows phone 8.1 listbox 分组显示
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。