Skip to content
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

docs: Add SystemThemeHelper page #1330

Merged
merged 2 commits into from
Jan 30, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion doc/controls-styles.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ The `Uno.Toolkit.UI` library adds the following controls:

The `Uno.Toolkit.UI` library adds the following helper classes:

- `SystemThemeHelper`: Provides a set of helper methods to check the current operating system theme, and manipulate the application dark/light theme.
- [`AncestorBinding` and `ItemsControlBinding`](helpers/ancestor-itemscontrol-binding.md): These markup extensions provides relative binding based on ancestor type. If you are familiar with WPF, they are very similar to `{RelativeSource Mode=FindAncestor}`.
- [`CommandExtensions`](helpers/command-extensions.md): Provides Command/CommandParameter attached properties for common scenarios.
- [`InputExtensions`](helpers/input-extensions.md): Provides various attached properties for _input controls_, such as `TextBox` and `PasswordBox`.
- [`ItemsRepeaterExtensions`](helpers/itemsrepeater-extensions.md): Provides selection support for ItemsRepeater.
- [`StatusBar`](helpers/StatusBar-extensions.md): Provides two attached properties on `Page` to controls the visual of the status bar on mobile platforms.
- [`SystemThemeHelper`](helpers/SystemThemeHelper.md): Provides a set of helper methods to check the current operating system theme, and manipulate the application dark/light theme.
morning4coffe-dev marked this conversation as resolved.
Show resolved Hide resolved
- [`TabBarItemExtensions`](helpers/TabBarItem-extensions.md): Provides additional features for `TabBarItem`.
- [`VisualStateManagerExtensions`](helpers/VisualStateManager-extensions.md): Provides a way of manipulating the visual states of Control with attached property.

Expand Down
57 changes: 57 additions & 0 deletions doc/helpers/SystemThemeHelper.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
---
uid: Toolkit.Helpers.SystemThemeHelper
---

# SystemThemeHelper

Provides utilities for managing and retrieving the current theme of the operating system and the application.

## Theme Retrieval

### Methods

| Method | Return Type | Description |
|------------------------------|-------------------------|---------------------------------------------------------------------------------------------------------------|
| `GetCurrentOsTheme()` | `ApplicationTheme` | Retrieves the current theme of the operating system. |
| `GetApplicationTheme()` | `ApplicationTheme` | **[Obsolete]** Retrieves the current theme of the application. Will be removed in future versions. |
| `GetRootTheme(XamlRoot?)` | `ApplicationTheme` | Gets the `ApplicationTheme` of the provided `XamlRoot`, or falls back to the operating system theme. |
| `IsAppInDarkMode()` | `bool` | **[Obsolete]** Returns `true` if the application is currently in dark mode, otherwise `false`. |
| `IsRootInDarkMode(XamlRoot)` | `bool` | Determines if the provided `XamlRoot` is in dark mode. |

### Usage

Example of retrieving the current OS theme:

```csharp
var osTheme = SystemThemeHelper.GetCurrentOsTheme();
Console.WriteLine($"Current OS Theme: {osTheme}");
```

Retrieve the application theme:

```csharp
var xamlRoot = someElement.XamlRoot;
var appTheme = SystemThemeHelper.GetRootTheme(xamlRoot);
Console.WriteLine($"Current App Theme: {appTheme}");
```

## Theme Management

### Methods

| Method | Description |
|-------------------------------------|----------------------------------------------------------------------------------------------|
| `SetApplicationTheme(bool)` | **[Obsolete]** Sets the application theme to dark mode if `darkMode` is `true`, otherwise light mode. Will be removed in future versions. |
| `SetRootTheme(XamlRoot?, bool)` | Sets the theme for the provided `XamlRoot` based on the `darkMode` parameter. |
| `SetApplicationTheme(XamlRoot?, ElementTheme)` | Sets the `ElementTheme` (`Light` or `Dark`) for the provided `XamlRoot`. |
| `ToggleApplicationTheme()` | **[Obsolete]** Toggles the application theme between light and dark modes. Will be removed in future versions. |

### Usage

Set the theme for a specific `XamlRoot`:

```csharp
var xamlRoot = someElement.XamlRoot;
SystemThemeHelper.SetApplicationTheme(xamlRoot, ElementTheme.Light);
Console.WriteLine("XamlRoot theme set to Light Mode.");
```
2 changes: 2 additions & 0 deletions doc/toc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@
href: helpers/Selector-extensions.md
- name: StatusBar Extensions
href: helpers/StatusBar-extensions.md
- name: SystemThemeHelper
href: helpers/SystemThemeHelper.md
- name: TabBarItem Extensions
href: helpers/TabBarItem-extensions.md
- name: VisualStateManager Extensions
Expand Down
Loading