-
Couldn't load subscription status.
- Fork 57
Docs(theme service): add mvux state using sample #2749
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
d77915a
eb555c8
4ae05df
221aad7
b55486c
176d88a
272db34
4300f96
b7ce3bb
ad0cadf
1259fbd
540d4ee
b61211b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,6 +1,7 @@ | ||||||||||
| --- | ||||||||||
| uid: Uno.Extensions.ThemeService.Overview | ||||||||||
| --- | ||||||||||
| <!--markdownlint-disable MD051 --> | ||||||||||
| # How to use Theme Service | ||||||||||
|
|
||||||||||
| This topic explains how to use the `ThemeService` for runtime theme switching and persisting user theme preferences. | ||||||||||
|
|
@@ -12,13 +13,15 @@ This topic explains how to use the `ThemeService` for runtime theme switching an | |||||||||
|
|
||||||||||
| ## Step-by-step (Typical Usage with DI) | ||||||||||
|
|
||||||||||
| ### [MVVM](#tab/mvvm) | ||||||||||
|
|
||||||||||
| 1. **Consume ThemeService**: Inject the `ThemeService` into your view models or other services where you need to manipulate the theme. | ||||||||||
|
|
||||||||||
| ```csharp | ||||||||||
| public class SettingsViewModel | ||||||||||
| { | ||||||||||
| private readonly IThemeService _themeService; | ||||||||||
|
|
||||||||||
| public SettingsViewModel(IThemeService themeService) | ||||||||||
| { | ||||||||||
| _themeService = themeService; | ||||||||||
|
|
@@ -33,6 +36,67 @@ This topic explains how to use the `ThemeService` for runtime theme switching an | |||||||||
| } | ||||||||||
| ``` | ||||||||||
|
|
||||||||||
| ### [MVUX](#tab/mvux) | ||||||||||
|
|
||||||||||
| 1. **Consume ThemeService**: Inject the `ThemeService` into your models or other services where you need to manipulate the theme. | ||||||||||
| 2. **Bind to View**: Use a State or Command to bind your UI in your XAML. <!-- TODO: Add Links to each of the tabs --> | ||||||||||
|
|
||||||||||
| ### [Model](#tab/mvux/csharp) | ||||||||||
|
|
||||||||||
| In case you want to use it together with a State, e.g. to bind a control to the current theme trigger a Task with each Time, the Value changes, here is a simple example: | ||||||||||
|
|
||||||||||
| ```cssharp | ||||||||||
|
||||||||||
| ```cssharp | |
| ```csharp |
Copilot
AI
Sep 23, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing space after comma in parameter list. Should be 'bool item, CancellationToken ctk = default'.
| public async ValueTask SwitchThemeAsync(bool item,CancellationToken ctk = default) | |
| public async ValueTask SwitchThemeAsync(bool item, CancellationToken ctk = default) |
Copilot
AI
Sep 23, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The boolean logic is inverted. When item is true (toggle is on), it should set Dark theme, not Light theme. The switch cases should be reversed.
| true => await _themeService.SetThemeAsync(AppTheme.Light), | |
| false => await _themeService.SetThemeAsync(AppTheme.Dark) | |
| true => await _themeService.SetThemeAsync(AppTheme.Dark), | |
| false => await _themeService.SetThemeAsync(AppTheme.Light) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My suggestion here is that we don't include this as part of the ThemeService docs but we should create a Recipe Book docs entry for this usage in Chefs: https://github.com/unoplatform/uno.chefs/blob/198923fcd69d416fd3901be2fe4d58fecd74421b/Chefs/Presentation/SettingsModel.cs#L26-L38
https://platform.uno/docs/articles/external/uno.chefs/doc/RecipeBooksOverview.html
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that
ThemeChangedMessagein there is quite cool and the ISettingsService... Can we not get a SettingsService generally available in extensions? that would really be cool! to have just to call this to automatically switch theme or localization! is this think-able?