【发布时间】:2016-05-09 20:06:44
【问题描述】:
如何将按钮“myCmdButton”的命令绑定到ParameterVariableList,就像“addBtn”一样。 “addBtn”按预期工作。 我也想要我的 ParameterVariableList 类的其他按钮命令。
这是 XAML:
<DataTemplate DataType="{x:Type locale:ParameterVariableList}" >
<StackPanel Orientation="Vertical">
<TextBlock Text="{Binding Description}"/>
<Button Content="add" Command="{Binding AddEntryCmd}" Name="addBtn" />
<ListBox ItemsSource="{Binding ItemList, UpdateSourceTrigger=PropertyChanged}" HorizontalAlignment="Stretch" >
<ListBox.ItemTemplate>
<ItemContainerTemplate>
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding}" />
<Button Width="{Binding ActualHeight, RelativeSource={RelativeSource Self}}" Command="{Binding RemoveEntryCmd, ???}" Name="myCmdButton" >
<Image Source="Resources/trash_16x16.png" Stretch="None" VerticalAlignment="Center" HorizontalAlignment="Center" />
</Button>
</StackPanel>
</ItemContainerTemplate>
</ListBox.ItemTemplate>
</ListBox>
</StackPanel>
</DataTemplate>
我希望这会起作用,但它没有:
Command="{Binding RemoveEntryCmd, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type locale:ParameterVariableList}}}"
错误: System.Windows.Data 错误:4:找不到与引用'RelativeSource FindAncestor,AncestorType='hmi.ParameterVariableList',AncestorLevel='1''的绑定源。 BindingExpression:Path=RemoveEntryCmd;数据项=空;目标元素是 'Button' (Name='');目标属性是“Command”(输入“ICommand”)
【问题讨论】:
标签: c# wpf xaml data-binding