我有一个应用程序,我们在分组的网格视图中显示数据。为每个组分组网格视图获取小计的最佳方法是什么?
答案 0 :(得分:2)
您可以使用组中的项目数更改每个组的标题文本。
假设你有一个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;
}
}