How to change colors and input background theme in .NET MAUI DataGrid (SfDataGrid) ?
In this article, we will demonstrate how to change the colors of the checkbox and input background based on the light and dark theme mode in the .NET MAUI DataGrid.
C#
The following code illustrates how to change the colors of the checkBox and input background depending on the light and dark theme mode in DataGrid.
public MainPage()
{
InitializeComponent();
ICollection<ResourceDictionary> mergedDictionaries = Application.Current.Resources.MergedDictionaries;
if (mergedDictionaries != null)
{
var theme = mergedDictionaries.OfType<SyncfusionThemeResourceDictionary>().FirstOrDefault();
if (theme != null)
{
if (theme.VisualTheme is SfVisuals.MaterialDark)
{
sfGrid.DefaultStyle.GetType().GetRuntimeProperties().FirstOrDefault(x => x.Name == "CheckBoxColor").SetValue(sfGrid.DefaultStyle, Colors.Yellow);
sfGrid.DefaultStyle.GetType().GetRuntimeProperties().FirstOrDefault(x => x.Name == "InputBackgroundColor").SetValue(sfGrid.DefaultStyle, Colors.SkyBlue);
}
else
{
sfGrid.DefaultStyle.GetType().GetRuntimeProperties().FirstOrDefault(x => x.Name == "CheckBoxColor").SetValue(sfGrid.DefaultStyle, Colors.Orange);
sfGrid.DefaultStyle.GetType().GetRuntimeProperties().FirstOrDefault(x => x.Name == "InputBackgroundColor").SetValue(sfGrid.DefaultStyle, Colors.Green);
}
}
else
{
sfGrid.DefaultStyle.GetType().GetRuntimeProperties().FirstOrDefault(x => x.Name == "CheckBoxColor").SetValue(sfGrid.DefaultStyle, Colors.Orange);
sfGrid.DefaultStyle.GetType().GetRuntimeProperties().FirstOrDefault(x => x.Name == "InputBackgroundColor").SetValue(sfGrid.DefaultStyle, Colors.Green);
}
}
}
Light Theme
Dark Theme
Download the complete sample from GitHub
Conclusion
I hope you enjoyed learning how to change colors and input background themes in .NET MAUI DataGrid (SfDataGrid).
You can refer to our .NET MAUI DataGrid feature tour page to learn about its other groundbreaking feature representations. Explore our Documentation to understand how to present and manipulate data.
For current customers, check out our components on the License and Downloads page. If you are new to Syncfusion®, try our 30-day free trial to check out our other controls.
Please let us know in the comments section if you have any queries or require clarification. You can also contact us through our support forums, Direct-Trac, or the feedback portal. We are always happy to assist you!