Category / Section
How to change the default theme color of Xamarin.Forms SfDataGrid?
1 min read
By default, the SfDataGrid does not have a direct property to change the default theme color. But you can change the color of the default theme by using the QueryCellStyle event of the SfDataGrid.
<?xml version="1.0" encoding="utf-8" ?> <ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:local="clr-namespace:DataGridDemo" xmlns:sfgrid="clr-namespace:Syncfusion.SfDataGrid.XForms;assembly=Syncfusion.SfDataGrid.XForms" xmlns:sfPager="clr-namespace:Syncfusion.SfDataGrid.XForms.DataPager;assembly=Syncfusion.SfDataGrid.XForms" x:Class="DataGridDemo.MainPage"> <ContentPage.BindingContext> <local:ViewModel /> </ContentPage.BindingContext> <Grid> <sfgrid:SfDataGrid x:Name="dataGrid" RowHeight="70" AllowGroupExpandCollapse="True" AllowResizingColumn="True" AllowSorting="True" AutoGenerateColumns="True" ItemsSource="{Binding OrdersInfo}"> </sfgrid:SfDataGrid> </Grid> </ContentPage>
public partial class MainPage : ContentPage { public MainPage() { InitializeComponent(); dataGrid.QueryCellStyle += DataGrid_QueryCellStyle; } private void DataGrid_QueryCellStyle(object sender, QueryCellStyleEventArgs e) { ICollection<ResourceDictionary> mergedDictionaries = Application.Current.Resources.MergedDictionaries; var darkTheme = mergedDictionaries.OfType<DarkTheme>().FirstOrDefault(); if (darkTheme != null) { e.Style.ForegroundColor = Color.FromHex("#FFFFFFFF"); e.Handled = true; } } }