Switching between light theme and dark theme

Refer to the following example code to switch between light and dark themes in Syncfusion® Maui controls.

  • C#
  • void UpdateTheme(object sender, System.EventArgs e)
    {
        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)
                {
                    theme.VisualTheme = SfVisuals.MaterialLight;
                }
                else
                {
                    theme.VisualTheme = SfVisuals.MaterialDark;
                }
            }
         }
    }

    The complete theme switch sample is available in this link.