我有一个应用程序,我们在分组网格视图中显示数据。获得分组网格视图的每个组的小计的最佳方法是什么?
发布于 2016-06-30 13:50:16
可以用组的项数更改每个组的标题文本。
假设你有一个GroupStyle
<GroupStyle>
<GroupStyle.HeaderTemplate>
<DataTemplate>
<TextBlock Text='{Binding Key}' Foreground="{StaticResource ApplicationForegroundThemeBrush}" Margin="5" FontSize="18" FontFamily="Segoe UI" FontWeight="Light" />
DataTemplate>
</GroupStyle.HeaderTemplate>
</GroupStyle>
在使用分组数据创建列表时,可以在键的文本中添加组的总数。
public List<ItemList> CreateGroupedData()
{
if (ReceivedList!= null)
{
var result =
from t in ReceivedList
group t by t.GroupField into g
orderby g.Key
select new { Key = g.Key, Items = g };
List<ItemList> lists = new List<ItemList>();
foreach (var i in result)
{
ItemList list = new ItemList();
list.Key = $"{i.Key.ToString)} [{i.Items.Count.ToString()}]";
lists.Add(list);
}
return lists;
}
}
https://stackoverflow.com/questions/38123310
复制相似问题