gpt4 book ai didi

.net - WPF 数据绑定(bind) - 从父级获取值

转载 作者:行者123 更新时间:2023-12-04 05:31:45 26 4
gpt4 key购买 nike

我有以下 .xaml:

<TreeView ItemsSource="{Binding EntityInstanceGroupings}">
<TreeView.ItemTemplate>
<DataTemplate>
<TreeViewItem ItemsSource="{Binding EntityInstances}">
<TreeViewItem.HeaderTemplate>
<DataTemplate>
<DockPanel LastChildFill="True">
<TextBlock Text="{Binding ...}" />
<Button Content="Add" DockPanel.Dock="Right" VerticalContentAlignment="Top">
...
</Button>
</DockPanel>
</DataTemplate>
</TreeViewItem.HeaderTemplate>
<TreeViewItem.ItemTemplate>
...
</TreeViewItem.ItemTemplate>
</TreeViewItem>
</DataTemplate>
</TreeView.ItemTemplate>
</TreeView>

在线:
<TextBlock Text="{Binding ...}" />

我正在尝试绑定(bind)到 EntityInstanceGroupings View 模型中的属性“GroupName”。我想不出这样做(如果可能的话)。任何帮助将不胜感激 :)

最佳答案

您应该能够使用 RelativeSource 来实现此目的。 .

<TextBlock Text="{Binding RelativeSource={RelativeSource AncestorType=TreeViewItem},
Path=DataContext.GroupName}" />

关于.net - WPF 数据绑定(bind) - 从父级获取值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12486357/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com