WPF How to make the background of DataGridComboBoxColumn to be the same as DataGridTextBoxColumn

StackOverflow https://stackoverflow.com/questions/15535449

문제

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>
도움이 되었습니까?

해결책

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top