C# 绑定到同一DataTemplate中的另一个控件
我有一个C# 绑定到同一DataTemplate中的另一个控件,c#,wpf,xaml,binding,datatemplate,C#,Wpf,Xaml,Binding,Datatemplate,我有一个列表框,它的数据模板包含一个按钮和标签: <ListBox.ItemTemplate> <DataTemplate> <DockPanel> <Button DockPanel.Dock="Left" Command="{Binding DataContext.AddToBoxCmd, RelativeSource={RelativeSource FindAnce
列表框
,它的数据模板
包含一个按钮和标签:
<ListBox.ItemTemplate>
<DataTemplate>
<DockPanel>
<Button DockPanel.Dock="Left" Command="{Binding DataContext.AddToBoxCmd, RelativeSource={RelativeSource FindAncestor, AncestorType=UserControl, AncestorLevel=1}}"
CommandParameter=???/> <--How to bind command parameter here to Label's content below
<Label x:Name="PartNumberLabel" Content="{Binding Path=Element[PartNumber].Value}"/>
是不是CommandParameter=“{Binding Content,ElementName=PartNumberLabel}”
不起作用?还是CommandParameter=“{Binding Path=Element[PartNumber].Value}”
?嗯,奇怪的是这些不起作用,但我认为它们应该起作用。似乎我的CommandParameter根本就没有抓住任何东西……我觉得自己是个傻瓜,因为我一开始就没有检查这两个绑定短语。尝试使用Relativesource:CommandParameter=“{binding Content,Relativesource={Relativesource FindAncestor,AncestorType={x:Type Label}}}”
@Tico,这不管用,但我认为这是正确的方向。还有其他建议吗?我将尝试添加一个级别/etc