Skip to content

Commit

Permalink
Merge pull request #7615 from unoplatform/dev/cdb/reapply-theme
Browse files Browse the repository at this point in the history
feat(reapply_theme): Added the ability to reapply application theme
  • Loading branch information
carldebilly authored Dec 7, 2021
2 parents f7a8a40 + dc1a660 commit 669f4d3
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Uno.UI/UI/Xaml/Application.cs
Original file line number Diff line number Diff line change
@@ -326,7 +326,7 @@ private void SetRequestedTheme(ApplicationTheme requestedTheme)

internal void UpdateResourceBindingsForHotReload() => OnResourcesChanged(ResourceUpdateReason.HotReload);

private void OnRequestedThemeChanged() => OnResourcesChanged(ResourceUpdateReason.ThemeResource);
internal void OnRequestedThemeChanged() => OnResourcesChanged(ResourceUpdateReason.ThemeResource);

private void OnResourcesChanged(ResourceUpdateReason updateReason)
{
13 changes: 13 additions & 0 deletions src/Uno.UI/UI/Xaml/ApplicationHelper.cs
Original file line number Diff line number Diff line change
@@ -36,6 +36,19 @@ public static string RequestedCustomTheme
}
}

/// <summary>
/// Force all {ThemeResource} declarations to reevaluate its bindings.
/// </summary>
/// <remarks>
/// This could be useful if you manually changed the bound values in global
/// themed dictionary and you want to reapply them without having to toggle
/// dark/light and producing annoying flickering to user.
///
/// Only applications with dynamic color schemes should use this.
/// </remarks>
public static void ReapplyApplicationTheme()
=> Application.Current.OnRequestedThemeChanged();

public static bool IsLoadableComponent(Uri resource)
{
return Application.Current.IsLoadableComponent(resource);

0 comments on commit 669f4d3

Please sign in to comment.