I'm new to Xamarin Forms and I' trying to add a theme control to my application
I found this post - https://www.syncfusion.com/forums/147666/applying-theme-to-control
on how to (Applying theme to control), but the problem is that I want to know how to do this in MVVM
When I fallow the sample project in the link above and apply's the code to my project, I get the error
>>> "Severity Code Description Project File Line Suppression State Error CS0234 The type or namespace name 'MergedDictionaries' does not exist in the namespace 'CykelStaden.Resources' (are you missing an assembly reference?)"
This is my ViewModel
public class SettingsViewModel : BaseViewModel {private bool toggleTheme;private bool isLightTheme = true;
public bool ToggleTheme { get { return toggleTheme; } set { toggleTheme = value; OnToggleTheme(); } }private void OnToggleTheme() { if (isLightTheme) { ICollection<ResourceDictionary> mergedDictionaries = Resources.MergedDictionaries; var lightTheme = mergedDictionaries.OfType<Themes.LightTheme>().FirstOrDefault(); if (lightTheme != null) { mergedDictionaries.Remove(lightTheme); } mergedDictionaries.Add(new Themes.DarkTheme()); isLightTheme = false; } else { ICollection<ResourceDictionary> mergedDictionaries = this.Resources.MergedDictionaries; var darkTheme = mergedDictionaries.OfType<Themes.DarkTheme>().FirstOrDefault(); if (darkTheme != null) { mergedDictionaries.Remove(darkTheme); } mergedDictionaries.Add(new Themes.LightTheme()); isLightTheme = true; } }}
How do I fix this please
Attachment:
SettingsViewModel_6c53d39f.zip