WPF CollectionViewSource 分组
我正在使用 CollectionViewSource
对我的数据进行分组。在我的数据中,我需要对 Property1
和 Property2
进行分组。
唯一的规定是我不想要另一个组的子组。因此,当我按这两个属性进行分组时,我不想将其作为 Property1
组的子组。
我想要这个的原因是因为我需要一个显示以下信息的标题:
标题:
<TextBlock.Text>
<MultiBinding StringFormat="Property1: {0}, Property2: {1}">
<Binding Path="Property1"/>
<Binding Path="Property2"/>
</MultiBinding>
</TextBlock.Text>
我已经用我的 CollectionViewSource 尝试过这个,但无法将组和子组“组合”在一起:
<CollectionViewSource x:Key="myKey" Source="{Binding myDataSource}">
<CollectionViewSource.GroupDescriptions>
<PropertyGroupDescription PropertyName="Property1" />
<PropertyGroupDescription PropertyName="Property2" />
</CollectionViewSource.GroupDescriptions>
</CollectionViewSource>
是否可以将两个分组属性在一起?像下面这样的东西?
<CollectionViewSource x:Key="myKey" Source="{Binding myDataSource}">
<CollectionViewSource.GroupDescriptions>
<PropertyGroupDescription PropertyName="Property1,Property2" />
</CollectionViewSource.GroupDescriptions>
</CollectionViewSource>
I'm using a CollectionViewSource
to group my data. In my data, I have Property1
and Property2
that I'm needing to group on.
The only stipulation is that I don't want sub-groups of another group. So, when I group by these two properties, I don't want to have it so that Property2
because a subgroup of Property1
's group.
The reason why I want this is because I need to have a header that shows the following information:
Header:
<TextBlock.Text>
<MultiBinding StringFormat="Property1: {0}, Property2: {1}">
<Binding Path="Property1"/>
<Binding Path="Property2"/>
</MultiBinding>
</TextBlock.Text>
I've tried this with my CollectionViewSource but was not able to "combine" the group and subgroup together:
<CollectionViewSource x:Key="myKey" Source="{Binding myDataSource}">
<CollectionViewSource.GroupDescriptions>
<PropertyGroupDescription PropertyName="Property1" />
<PropertyGroupDescription PropertyName="Property2" />
</CollectionViewSource.GroupDescriptions>
</CollectionViewSource>
Is it possible to group two properties together? Something like below?
<CollectionViewSource x:Key="myKey" Source="{Binding myDataSource}">
<CollectionViewSource.GroupDescriptions>
<PropertyGroupDescription PropertyName="Property1,Property2" />
</CollectionViewSource.GroupDescriptions>
</CollectionViewSource>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
实际上,您还可以在转换器上使用一些技巧,而不是在对象中创建另一个新属性。点('.')将整个对象传递到转换器中。因此,您可以在那里执行任何逻辑算法,而不是在原始对象中创建新属性。
在你的转换器上是这样的:
Instead of creating another new property in your object actually you can also have some tricks on the converter. Dot ('.') is pass the whole object into you converter. So you can do whatever logic algorithm over there instead of creating a new property in your original object.
At your converter something like this:
您可以将这些属性合并为数据对象的一个属性。例如:
You could combine the properties into one property on your data object. For instance: