如何绑定父级中的子级用户控件的数据上下文
TextBlock Text="{Binding ChildGroupName,
RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type
UserControl}},UpdateSourceTrigger=PropertyChanged,NotifyOnTargetUpdated=True,Mode=TwoWay}"
TargetUpdated="OnTextUpdated"/> 这里ChildGroupName是一个子控件的datacontext属性。 我想要将ChildGroupName值绑定到父窗口。
您不能使用FindAncestor将数据绑定到后代的数据......线索就是其名称。 如果子UserControl是在与父项相同的XAML中定义的,则可以为其提供一个名称,然后使用Binding.ElementName属性将数据绑定到其属性:
<TextBlock Text="{Binding ChildPropertyName, ElementName=NameOfChildUserControl,
UpdateSourceTrigger=PropertyChanged, NotifyOnTargetUpdated=True, Mode=TwoWay}"
TargetUpdated="OnTextUpdated" />
链接地址: http://www.djcxy.com/p/44623.html
上一篇: How to bind a child user control's data context in the parent
下一篇: How to implement IDataErrorInfo on string indexers databinding?
