我在自定义 ComboxBox 触发事件时遇到问题。这个想法是让组合框绑定到一组项目,每个项目都有一个编辑和删除按钮。我可以使用代码隐藏使点击事件工作,但命令绑定似乎什么都不做。
<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>