Reputation: 4344
I can get a button to appear and be clickable in the drop down list of a combo box, but I cannot get the selected combo box item (the drop list is closed) to have the button be clickable. It always skips the button click and just opens the drop down list. I basically want the Button_Click event handler that I setup to be called once it is clicked. Here is my sample combo box that shows the button but is not clickable once it is in the selected item:
<ComboBox x:Name="MyCombo" Width="200" Height="30" ItemsSource="{Binding ListCombo}">
<ComboBox.Resources>
<DataTemplate DataType="{x:Type local:ComboItemClass}">
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding Path=SampleText}" Width="120" />
<Button Width="20" Content="..." Click="Button_Click"/>
</StackPanel>
</DataTemplate>
</ComboBox.Resources>
</ComboBox>
Upvotes: 3
Views: 4203
Reputation: 16899
Putting buttons inside comboboxes is one of those really cool features that we now CAN do in WPF that we (me included) get really excited about, before we stop to consider if we SHOULD do this.
Having a button inside a combobox makes it very easy to confuse the heck out of your user. I would recommend that you bind the data from your comobox listitems to a button outside of the combobox, where your user will expect it. That way, you can still change the end result of the button being pressed by selecting an item from the combobox.
EDIT:
If you have the space for it, a listbox would work perfectly for what you want to do.
<ListBox>
<ListBoxItem>
<StackPanel Height="34" HorizontalAlignment="Left" Margin="12,16,0,0" VerticalAlignment="Top" Width="430" Orientation="Horizontal">
<Button Content="Edit" />
<Button Content="Delete" />
<TextBlock Text="Port Information here" VerticalAlignment="Center" Margin="20,0" />
</StackPanel>
</ListBoxItem>
<ListBoxItem>
<StackPanel Height="34" HorizontalAlignment="Left" Margin="12,16,0,0" VerticalAlignment="Top" Width="430" Orientation="Horizontal">
<Button Content="Edit" />
<Button Content="Delete" />
<TextBlock Text="Port Information here" VerticalAlignment="Center" Margin="20,0" />
</StackPanel>
</ListBoxItem>
<ListBoxItem>
<StackPanel Height="34" HorizontalAlignment="Left" Margin="12,16,0,0" VerticalAlignment="Top" Width="430" Orientation="Horizontal">
<Button Content="Edit" />
<Button Content="Delete" />
<TextBlock Text="Port Information here" VerticalAlignment="Center" Margin="20,0" />
</StackPanel>
</ListBoxItem>
Upvotes: 2