Skip to content

9629976110/how-to-set-style-for-combobox-of-the-gridcomboboxcolumn-in-wpf-data-grid

 
 

Repository files navigation

How to set style for ComboBox of the GridComboBoxColumn in WPF DataGrid(SfDataGrid)?

About the sample

This example illustrates how to set style for ComboBox of the GridComboBoxColumn in WPF DataGrid(SfDataGrid).

WPF DataGrid (SfDataGrid) doesn’t have direct support to set style for the ComboBox in the GridComboBoxColumn. However, you can achieve this by creating custom GridCellComboBoxRenderer.

<Window.Resources>
    <Style TargetType="ComboBox" x:Key="comboBoxStyle">
        <Setter Property="Foreground" Value="Blue"/>
    </Style>
</Window.Resources>
public MainWindow()
{
    InitializeComponent();

    this.dataGrid.CellRenderers["ComboBox"] = new CustomComboBoxCellRenderer();
}


public class CustomComboBoxCellRenderer : GridCellComboBoxRenderer
{
    public override void OnInitializeEditElement(DataColumnBase dataColumn, ComboBox uiElement, object dataContext)
    {
        base.OnInitializeEditElement(dataColumn, uiElement, dataContext);
        uiElement.Style = App.Current.MainWindow.Resources["comboBoxStyle"] as Style;
    }
}

ComboBox Style

Requirements to run the demo

Visual Studio 2015 and above versions.

About

How to set style for ComboBox of the GridComboBoxColumn in WPF DataGrid(SfDataGrid)?

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C# 100.0%