Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/260.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 绑定到同一DataTemplate中的另一个控件_C#_Wpf_Xaml_Binding_Datatemplate - Fatal编程技术网

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