1

I have this style defined in <UserControl.Resources>:

<Style x:Name="DropDownStyle" TargetType="{x:Type ComboBoxItem}">
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate>
                <StackPanel Orientation="Horizontal">
                    <TextBlock Margin="5,2,2,2" Text="{Binding ID, Mode=OneWay}" />
                    <TextBlock Margin="5,2,10,2" Text="{Binding Name, Mode=OneWay}" />
                </StackPanel>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

which is used to display the items of the ComboBoxItem as 1 Car, 2 Truck, etc.

I would like to know how to move this style within the DataGridComboBoxColumn item as this style is being applied to all my other DataGridComboBoxColumn.

I cannot figure out how to get down to the ComboBoxItem element of the DataGridComboBoxColumn to apply the style.

BrianKE
  • 4,035
  • 13
  • 65
  • 115
  • I guess you only want to apply that style to ComboBoxes in that specific DataGrid. In this case remove the `x:Name` of your style and move the style to the resources of the DataGrid ``. The drawback is it changes all ComboBoxes in all columns. – gomi42 Mar 27 '15 at 17:02
  • @gomi42 Thanks for the suggestion but the other DataGridComboBoxColumns are within the same DataGrid so moving the style within the DataGrid will not work in my case. – BrianKE Mar 27 '15 at 17:09

1 Answers1

1

I see. You can accomplish what you want in the following way. Keep the existing ComboBoxItem style where it is. Add another style for a Combobox, in the example below it is MyComboBoxStyle´ and refore to theEditingElementStyle´ in your DataGridComboBoxColumn.

<Style x:Key="MyComboboxStyle" TargetType="{x:Type ComboBox}">
    <Setter Property="ItemContainerStyle" Value="{StaticResource DropDownStyle}"/>
</Style>


<DataGridComboBoxColumn EditingElementStyle="{StaticResource MyComboboxStyle}" SelectedItemBinding="{Binding MySelectedItem}" ItemsSource="{StaticResource MyArray}">
gomi42
  • 2,449
  • 1
  • 14
  • 9