-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSettingsPage.xaml.cs
39 lines (34 loc) · 1.03 KB
/
SettingsPage.xaml.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
using Microsoft.Maui.Controls;
namespace LearningApp;
public partial class SettingsPage : ContentPage
{
public SettingsPage()
{
InitializeComponent();
var savedTheme = Preferences.Get("AppTheme", "Light");
ApplyTheme(savedTheme);
themePicker.SelectedItem = savedTheme;
}
private void OnThemeChanged(object sender, EventArgs e)
{
var selectedTheme = themePicker.SelectedItem?.ToString();
if (selectedTheme != null)
{
Preferences.Set("AppTheme", selectedTheme);
ApplyTheme(selectedTheme);
}
}
private void ApplyTheme(string theme)
{
if (theme == "Dark")
{
Application.Current.Resources.MergedDictionaries.Clear();
Application.Current.Resources.MergedDictionaries.Add(new DarkTheme());
}
else
{
Application.Current.Resources.MergedDictionaries.Clear();
Application.Current.Resources.MergedDictionaries.Add(new LightTheme());
}
}
}