Question

I have a datagridCombox Column in datagrid. In order for the combobox to show like a combobox all the time (click or not) The combobox is implemented as this

xmlns:dg="http://schemas.microsoft.com/wpf/2008/toolkit"

                <dg:DataGridTemplateColumn Header="Time Unit" x:Name="timeUnit" >
                    <dg:DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <ComboBox SelectedValue="{Binding RelParams.TimeUnit}" 
                                      Background="White" BorderBrush="{x:Null}"
                                      ItemsSource ="{Binding TimeUnitList}" >
                            </ComboBox>
                        </DataTemplate>
                    </dg:DataGridTemplateColumn.CellTemplate>
                </dg:DataGridTemplateColumn>

Now the issue is the datagridrow has alternation background. I want the combobox in the datagridrow to use the same background as the textbox column in the datagridrow. Also when the datagridrow is selected, the combobox should be highlighted in the same color as the rest of the row. How to accomplish this? Thanks

<Style x:Key="DataGridCellStyle" TargetType="{x:Type dg:DataGridCell}">
    <Setter Property="ContextMenu" Value="{DynamicResource cellContextMenu}" />
</Style>
<Style x:Key="DataGridRowStyle"  TargetType="{x:Type dg:DataGridRow}">
    <Style.Triggers>
        <Trigger Property="AlternationIndex" Value="1" >
            <Setter Property="Background" Value="Beige" />
        </Trigger>
    </Style.Triggers>
    <Setter Property="Margin" Value="0 2 0 2" />            
</Style>
<Style x:Key="DataGridStyle" TargetType="{x:Type dg:DataGrid}">
    <Setter Property="AlternationCount" Value="2" />
    <Setter Property="RowStyle" Value="{StaticResource DataGridRowStyle}" />
    <Setter Property="CellStyle" Value="{StaticResource DataGridCellStyle}" />
</Style>
Was it helpful?

Solution

You can try setting the Background Property of the Combobox in your DataTemplate to Transparent.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top