[英]XAML - Binding Group Header In Group Header Style
Not trying to post a duplicate of this thread: WPF - Binding to current item from within group header style 不尝试发布此线程的副本: WPF-从组标题样式内绑定到当前项目
I got the binding working. 我使绑定生效。 I'm stil unclear why it works.
我还不清楚它为什么起作用。 This part of the XAML sets up the group item and binds the Texbox to the text.
XAML的这一部分设置了组项目,并将Texbox绑定到文本。 What I don't understand is the Binding to the 'Name' property.
我不了解的是绑定到“名称”属性。 What is 'Name' a property of?
“名称”是什么属性? The group header?
组头? Until I found the linked thread I was trying to bind to a property on the items in the data grid.
在找到链接线程之前,我一直试图绑定到数据网格中各项的属性。
<ControlTemplate TargetType="{x:Type GroupItem}">
<Expander IsExpanded="True"
Background="#FF112255"
BorderBrush="#FF002255"
Foreground="#FFEEEEEE"
BorderThickness="1,1,1,5">
<Expander.Header>
<StackPanel Orientation="Horizontal">
<TextBlock FontWeight="Bold"
Text="SVC Node: "/>
<TextBlock FontWeight="Bold"
Text="{Binding Name}"/>
</StackPanel>
</Expander.Header>
<Expander.Content>
<ItemsPresenter />
</Expander.Content>
</Expander>
</ControlTemplate>
Name
refers to the property of the System.Windows.Data.CollectionViewGroup object that gets created by WPF and being set as the DataContext
of a GroupItem
. Name
是指由WPF创建并被设置为GroupItem
的DataContext
的System.Windows.Data.CollectionViewGroup对象的属性。
This property returns the value of the property that you group the source collection by. 此属性返回对源集合进行分组的属性的值。 So if you for example group a source collection of
Person
objects by a property called Sex
, the Name
property of the CollectionViewGroup
would return something like "Male" or "Female". 因此,例如,如果您通过名为
Sex
的属性对Person
对象的源集合进行分组,则CollectionViewGroup
的Name
属性将返回类似“ Male”或“ Female”的内容。 This Name
property is not a property of your custom model class. 此
Name
属性不是您的自定义模型类的属性。
The CollectionViewGroup
class also has a an Items
property that returns the collection of objects, for example all Person
objects where the Sex
property returns "Male", that belongs to the specific group. CollectionViewGroup
类还具有一个Items
属性,该属性返回对象的集合,例如,属于特定组的所有Sex
属性返回“ Male”的Person
对象。
Hope that makes sense. 希望有道理。
if your model contains the Name property and also GroupItem's DataContext contains same model object then Name property visible and able to access inside the control template. 如果您的模型包含Name属性,并且GroupItem的DataContext也包含相同的模型对象,则Name属性可见并且可以在控件模板内部访问。 So that name property binding works in TextBlock.
因此,名称属性绑定在TextBlock中起作用。
Updated: based on my analysis , corresponding grouped property has assigned internally into group item's Name property, SO that it automatically derived to its childs, 更新:根据我的分析,相应的分组属性已在内部分配给组项目的Name属性,因此它会自动派生给其子项,
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.