Example:
<ListBox Name="List"
ItemsSource="{Binding Items}"
SelectedIndex="{Binding SelectedIndex}">
<ListBox.ItemTemplate>
<DataTemplate>
<DockPanel >
<Button DockPanel.Dock="Left" Content="Show" Command="{Binding ShowCommand}" CommandParameter="{Binding}"/>
<TextBlock Text="{Binding }"/>
</DockPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
Clicking the button does nothing. I tried to bind the command to a button outside the DataTemplate
and it works. I also tried to register the button in the DataTemplate
to a Click_event
and this did work.
Why is the command not working inside the DataTemplate?