views:

303

answers:

2

I want to bind a command to a comboboxitem much like a typical command (either application or custom) is bound to a button. I can't seem to find an example.

EDIT:

The ComboBoxItem exists as part of a ContentControl that also contains a button. The button has an associated command that works well. How can I bind a command, in a similar way, to the ComboBoxItem?

<!--    Line -->
<Button x:Name="Line"
    Style="{DynamicResource Button_Title}"
    Grid.Row="1"
    Grid.RowSpan="3"
    Grid.Column="0"
    Content="Line"
    Command="{x:Static local:Ribbon_AC.Custom_RoutedUICommand}"
    CommandParameter="Line"
    Tag="{DynamicResource Line_32}"/>

    <!-- Arc -->
    <ContentControl x:Name="ArcSplit"
            Template="{DynamicResource Control_SplitSmall}"
            Tag="{DynamicResource Arc_20}"
            Grid.Row="1"
            Grid.Column="1">

    <ComboBox Name="ComboBox_Arc"
        Style="{DynamicResource ComboBox_Small}"
        Width="{DynamicResource Width_DropDown}">

        <!-- Arc_0 -->
        <ComboBoxItem    x:Name="Arc_0"
                Style="{DynamicResource ComboBoxItem_Large}"
                Tag="{DynamicResource Arc0_32}"
                Content="Arc 0">

        </ComboBoxItem>
+1  A: 
<ComboBox>
    <ComboBox.Resources>
        <Style TargetType="ComboBoxItem">
            <EventSetter Event="Foo" Handler="Bar"/>
        </Style>
    </ComboBox.Resources>
</ComboBox>
CannibalSmith
Thanks Cannibal. Turns out it was a scope issue.
Brad
+1  A: 

As one of the options you can consider putting a Button into the ComboBox's ItemTemplate and change the Button's template to make it look "not like a button at all".

But that is dirty. Maybe you can use Menu instead of ComboBox?

arconaut
I tried to do exactly that but there were other considerations. I think your menu idea may end up being the way to go, again, for any number of reasons.
Brad