如何在wpf中的组标题中显示属性名称
<!-- GroupHeaderStyle -->
<Style x:Key="GroupHeaderStyle" TargetType="{x:Type GroupItem}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type GroupItem}">
<Expander IsExpanded="False" Margin="15,0,0,0">
<Expander.Header>
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding ????????????}"/>
<TextBlock Text="-->"/>
<TextBlock Text="{Binding Name}"/>
</StackPanel>
</Expander.Header>
<ItemsPresenter />
</Expander>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
在上面的代码中,我希望显示其分组所依据的属性名称。 例如性别-->男生 ;性别-->女孩。
public class Test
{
string gender;
public string Gender
{
get { return gender; }
set { gender = value; }
}
}
我应该提供什么?????????????在上面的xaml中?
另外,如果有任何好的书籍或链接可以解释 ListCollectionView
中分组的内部细节,请告诉我。
<!-- GroupHeaderStyle -->
<Style x:Key="GroupHeaderStyle" TargetType="{x:Type GroupItem}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type GroupItem}">
<Expander IsExpanded="False" Margin="15,0,0,0">
<Expander.Header>
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding ????????????}"/>
<TextBlock Text="-->"/>
<TextBlock Text="{Binding Name}"/>
</StackPanel>
</Expander.Header>
<ItemsPresenter />
</Expander>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
In the above code I wish to display the property name by which it is grouped.
E.g. Gender --> Boy ; Gender --> Girl.
public class Test
{
string gender;
public string Gender
{
get { return gender; }
set { gender = value; }
}
}
What should i provide for ???????????? in the above xaml?
Also, please let me know if there is any good book or link which explains the internal details of grouping in ListCollectionView
.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
DataContext
应该是 CollectionViewGroup,它将其Name
属性设置为“group”(即 Gender 的值)。但是 CollectionViewGroup 和它来自哪个属性之间没有关联。从技术上讲,该属性可能有多个层次。唯一好的选择是对另一个拥有您所需的所有信息的房产进行排序。
CollectionViewGroup.Name
属性是一个对象,而不是字符串。所以你可以这样做:然后像这样访问它:
这是基本想法,但你可以使 GenderGroup 更通用。因此,您可以传递具有参数的参数,而不是硬编码“Gender”。
The
DataContext
should be an instance of CollectionViewGroup, which will have it'sName
property set to the "group" (i.e. the value of Gender). But there is no correlation between the CollectionViewGroup and what property it came from. Technically, the property could be multiple levels deep.The only good alternative is to sort on another property that has all the information you need. The
CollectionViewGroup.Name
property is an object, not a string. So you could do something like:And then access it like this:
That's the basic idea, but you could make GenderGroup more generic. So instead of hard-coding
"Gender"
you could pass that has a parameter.