绑定-关于RelativeSource

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的具体解释是: 指定与当前控件相对位置的控件作为数据绑定的源。

posted @ 2018-12-17 16:09  梦九龍  阅读(351)  评论(0编辑  收藏  举报