How to change the default style of DataGridComboBoxColumn? #3019
-
How can i style a DataGridComboBoxColumn with AutoGenerateColumns set to True?
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
@Diyari-Kurdi When you let the My assumption from your sample is that the underlying data source for the "Continents" column is an <DataGrid AutoGenerateColumns="True"
AutoGeneratingColumn="DataGrid_OnAutoGeneratingColumn"
... /> Then in your code-behind you can implement the hook in a manner like this: private void DataGrid_OnAutoGeneratingColumn(object sender, DataGridAutoGeneratingColumnEventArgs e)
{
if (e.PropertyType.IsEnum)
{
e.Column = new MaterialDesignThemes.Wpf.DataGridComboBoxColumn { Header = e.Column.Header, ItemsSource = Enum.GetValues(e.PropertyType) };
}
} There may still be some things with data binding and such that you need to iron out. This is just ensuring that you visually get the MDIX style for the For more information on the topic, you can go here: |
Beta Was this translation helpful? Give feedback.
@Diyari-Kurdi When you let the
DataGrid
auto-generate columns rather than explicitly defining them in XAML, you're effectively cutting specialized MDIX columns out of the loop. However, there is still a hook you can use to obtain what I believe you're going for.My assumption from your sample is that the underlying data source for the "Continents" column is an
enum
. If so, you can attach the hook to your data grid like this:Then in your code-behind you can implement the hook in a manner like this: