Text="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorLevel=1, AncestorType={x:Type Grid}}, Path=Name}"
数据绑定之RelativeSource
<TextBlockWidth="{Binding RelativeSource={RelativeSource Self}, Path=Parent.ActualWidth}"/>
这其中的RelativeSource是指定了Width属性绑定的是Self.Parent.ActualWidth(TextBlock父窗口的实际大小),表示该TextBlock的宽度与父窗口的宽度一致。
RelativeSource有四种Mode,包括FindAncestor,Self,TemplateParent,PriviousData.
RelativeSource的具体解释是: 指定与当前控件相对位置的控件作为数据绑定的源。
转载于:https://www.cnblogs.com/mengjiulong/p/10132129.html