0

I have a user control that contains a DataGrid:

        <DataGrid ItemsSource="{Binding SomeDataGrid}" Style="{StaticResource DataGridStyle}">
            <DataGrid.Columns>
                <DataGridTextColumn Header="ID" Binding="{Binding ID}" ElementStyle="{StaticResource TBColumn}"/>
                <DataGridComboBoxColumn Header="W" SelectedValueBinding="{Binding W[0]}">
                    <DataGridComboBoxColumn.ElementStyle>
                        <Style TargetType="ComboBox">
                            <Setter Property="ItemsSource" Value="{Binding W}" />
                        </Style>
                    </DataGridComboBoxColumn.ElementStyle>
                    <DataGridComboBoxColumn.EditingElementStyle>
                        <Style TargetType="ComboBox">
                            <Setter Property="ItemsSource" Value="{Binding W}" />
                            <Setter Property="IsDropDownOpen" Value="False" />
                        </Style>
                    </DataGridComboBoxColumn.EditingElementStyle>
                </DataGridComboBoxColumn>
            </DataGrid.Columns>
        </DataGrid>

For clarity, I have a rather simple style for a combobox

    <Style x:Key="ComboBoxColumn" TargetType="{x:Type ComboBox}">
        <Setter Property="Padding" Value="10 0 10 0"/>
    </Style>

that I want to apply to the the DataGridComboBoxColumn in addition to the styles set on the XAML code. I want to bind the ItemsSource property to a property from an item in an ObservableCollection, in this case W. And there will be about 8 more columns added, so I don't want to create a style for each of them, unless that's the only option.

Can those two styles be merged? I was thinking that maybe the style that I should be aiming to is the textbox within the DataGridComboBoxColumn. If so, how could I bind resource style to the DataGridComboBoxColumn that is applied to only the textblock inside?

ehtio
  • 179
  • 3
  • 11

0 Answers0