I am having a problem with a custom ComboxBox firing events. The idea is to have the combobox bound to a collection of items with an Edit and Delete button in-line with each item. I can make the click event work using code-behind, but the command binding seems to do nothing.
<ComboBox SelectedIndex="0">
<ComboBox.ItemTemplate>
<DataTemplate>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="200"/>
<ColumnDefinition Width="auto"/>
</Grid.ColumnDefinitions>
<TextBlock Text="{Binding Name}"/>
<StackPanel Grid.Column="1"
Orientation="Horizontal"
HorizontalAlignment="Right">
<Button Content="Edit"
Margin="0,0,5,0"
Command="{Binding EditConnectionCommand}"
CommandParameter="{Binding ID}"/>
<Button Content="Delete"
Command="{Binding DeleteConnectionCommand}"
CommandParameter="{Binding ID}"/>
</StackPanel>
</Grid>
</DataTemplate>
</ComboBox.ItemTemplate>
<ComboBox.ItemsSource>
<CompositeCollection>
<ComboBoxItem IsEnabled="False" Visibility="Collapsed">Select a database connection...</ComboBoxItem>
<CollectionContainer Collection="{Binding Source={StaticResource ConnectionsBridge}}" />
<ComboBoxItem>...New Connection...</ComboBoxItem>
</CompositeCollection>
</ComboBox.ItemsSource>
</ComboBox>
Your binding looks for the commands in the items, not in the ViewModel of the window.
To change this, fix your binding like this:
For this to work, you need to add
Name="root"to yourUserControlorWindow.