0
votes

I have a combobox with a list of entries+actions as text and button:

[ Item #1 [Preview] v ]
| Item #2 [Preview]   |
| Item #3 [Preview]   |
| Item #4 [Preview]   |

The problem is user can only click buttons on the drop-down list, but not on selected item. Basically any click on ComboCox causes drop-down opened.

Is there any way to limit drop-down to only V button? Or somehow else make buttons in the selected item clickable?

Here is my XAML

<ComboBox ItemsSource="{Binding LayoutsList}" >
    <ComboBox.ItemTemplate>
        <DataTemplate>
            <StackPanel Orientation="Horizontal">
                <TextBlock Text="{Binding Name}" />
                <Button 
                    Command="{Binding PreviewCommand}" 
                    CommandParameter="{Binding}"
                    >Preview</Button>
            </StackPanel>
        </DataTemplate>
    </ComboBox.ItemTemplate>
</ComboBox>
1

1 Answers

1
votes

I think that may only be possible with overwriting the entire ComboBox.Template. The dropdown appears on MouseDown, and it seems to cancel any subsequent event handlers inside the item, such as your Button.Click event, so I don't think there's a way around it other than to override the Template.

As an alternative, you could try using the PreviewMouseLeftButtonDown to determine if the mouse is over the [Preview] button, and if so set e.Handled = true and show the Preview of the SelectedItem. I don't know of an easy way to do that though, and am not sure if investigating this route is worth it.