<TextBlock Text="{Binding ChildGroupName, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}, UpdateSourceTrigger=PropertyChanged,NotifyOnTargetUpdated=True,Mode=TwoWay}"
TargetUpdated="OnTextUpdated"/>
Here ChildGroupName
是子控件数据上下文属性。我要绑定ChildGroupName
父窗口的值。
你不能使用FindAncestor
将数据绑定到后代的数据...线索就在它的名称中。如果孩子UserControl
在与父级相同的 XAML 中定义,那么您可以为其提供名称,然后使用Binding.ElementName财产 https://msdn.microsoft.com/en-us/library/system.windows.data.binding.elementname(v=vs.110).aspx将数据绑定到其属性:
<TextBlock Text="{Binding ChildPropertyName, ElementName=NameOfChildUserControl,
UpdateSourceTrigger=PropertyChanged, NotifyOnTargetUpdated=True, Mode=TwoWay}"
TargetUpdated="OnTextUpdated" />
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)