当有多个项目时,GroupStyle 总和不会更新
我已成功应用此处解释的技巧。 但我还有一个问题。
快速回顾:我在 ListView 中显示用户。 用户按国家/地区重新分组,并在 GroupStyle DataTemplate 中使用转换器显示所有组相关的 Users.Total 的总和。 但UI用户可以通过模态窗口更改Users的“Total”属性值。
当组中只有一项时,显示的用户总数和总和都会正确更新。 但是,当组中有多个项目时,仅更新用户总计(通过绑定),但甚至不会调用应该进行求和的转换器(TotalSumConverter)!
你知道它来自哪里吗? 我是否应该使用某种触发器来确保在项目发生修改时调用转换器?
I have successfully applied the trick explained here. But I still have one problem.
Quick recap : I display users in a ListView. Users are regrouped by Country, and in the GroupStyle DataTemplate I display the sum of all group related Users.Total, using a Converter. But UI users can change the "Total" property value of Users through a modal window.
When there is only one item in the Group, both the User Total displayed and the sum are properly updated. But when there are multiple items in the group, only the User Total is updated (through binding) but the Converter that's supposed to make the sum (TotalSumConverter) is not even called!
Do you have any idea where it could come from? Should I use some kind of a trigger to make sure the Converter is called when there is a modification in the items?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
问题在于,当项目更改时,计算组中所有项目总和的值转换器不会运行,因为没有更改项目的通知。 一种解决方案是绑定到其他东西,您可以控制它如何执行通知并在需要时通知组标头。
下面是一个工作示例。 您可以在文本框中更改用户的计数,并重新计算总计。
XAML:
隐藏代码:
The problem is that the value converter that calculates the sum for all the items in a group don't run when an item is changed, since there's no notification for changed items. One solution is to bind to something else that you can control how it does notifications and notify the group header when needed.
Below is a working example. You can change the count for a user in the text box and totals gets recalculated.
XAML:
Code behind:
您使用的技巧将组页脚绑定到 ListView.Items ,这不会像 DependencyObject 那样自动更新您的视图。 相反,在每次更新 Total 后强制刷新,如下所示:
The trick you are using databinds the group footer to ListView.Items which will not update your view automatically, like a DependencyObject does for example. Instead force a refresh after each update to Total like this:
刷新视图的问题在于它完全刷新了它,并且我有用于分组的扩展器,即使用户关闭它们,它也会扩展回其原始状态。 所以,是的,这是一种可能的解决方法,但并不完全令人满意。
另外,您的 DependencyObject 解释也很有趣,但是,为什么当我的组中只有一项时它还能工作呢?
The problem with refreshing the view is that it completely refreshes it, and I have expanders for my grouping, that will expand back to their original state, even if the user closed them. So yes it's a possible workaround, but it's not completely satisfying.
Also your DependencyObject explanation is interesting, but then, why is it working when I have only one item in my group?