绑定-关于RelativeSource

原文链接: http://www.cnblogs.com/mengjiulong/p/10132129.html

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

猜你喜欢

转载自blog.csdn.net/weixin_30438813/article/details/94845087
今日推荐