How to bind the Command of the Button "myCmdButton" to the ParameterVariableList, like the "addBtn" do. The "addBtn" works like expected. I want the other button command to my ParameterVariableList class too.
Here's the 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>
I expected this to work, but it doesn't:
Command="{Binding RemoveEntryCmd, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type locale:ParameterVariableList}}}"
Error: System.Windows.Data Error: 4 : Cannot find source for binding with reference 'RelativeSource FindAncestor, AncestorType='hmi.ParameterVariableList', AncestorLevel='1''. BindingExpression:Path=RemoveEntryCmd; DataItem=null; target element is 'Button' (Name=''); target property is 'Command' (type 'ICommand')