Category / Section
How to set style for ComboBox of the GridComboBoxColumn in WPF DataGrid(SfDataGrid)?
1 min read
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.
XAML
<Window.Resources> <Style TargetType="ComboBox" x:Key="comboBoxStyle"> <Setter Property="Foreground" Value="Blue"/> </Style> </Window.Resources>
C#
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; } }
Take a moment to peruse the documentation, where you can find about GridComboBoxColumn in SfDataGrid, with code examples.
You can download the example from GitHub