標籤:des style blog http io ar 使用 for sp
初次瞭解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 分組顯示