Skip to content
Open
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
9 changes: 8 additions & 1 deletion src/Shared/HandyControl_Shared/Controls/Window/Window.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,14 @@ public class Window : System.Windows.Window

static Window()
{
StyleProperty.OverrideMetadata(typeof(Window), new FrameworkPropertyMetadata(ResourceHelper.GetResourceInternal<Style>(ResourceToken.WindowWin10)));
try
{
StyleProperty.OverrideMetadata(typeof(Window), new FrameworkPropertyMetadata(ResourceHelper.GetResourceInternal<Style>(ResourceToken.WindowWin10)));
}
catch
{
StyleProperty.OverrideMetadata(typeof(Window), new FrameworkPropertyMetadata(null));
}
}

public Window()
Expand Down
12 changes: 10 additions & 2 deletions src/Shared/HandyControl_Shared/Tools/Helper/ResourceHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ namespace HandyControl.Tools;
/// </summary>
public class ResourceHelper
{
private static readonly Lazy<ResourceDictionary> _themeLazy = new(GetStandaloneTheme);

private static ResourceDictionary _theme;

/// <summary>
Expand All @@ -29,11 +31,17 @@ public static T GetResource<T>(string key)

internal static T GetResourceInternal<T>(string key)
{
if (GetTheme()[key] is T resource)
var theme = GetTheme();
if (theme != null && theme[key] is T resource)
{
return resource;
}

if (Application.Current != null && Application.Current.TryFindResource(key) is T appResource)
{
return appResource;
}

return default;
}

Expand Down Expand Up @@ -72,7 +80,7 @@ public static ResourceDictionary GetSkin(Assembly assembly, string themePath, Sk
/// <summary>
/// get HandyControl theme
/// </summary>
public static ResourceDictionary GetTheme() => _theme ??= GetStandaloneTheme();
public static ResourceDictionary GetTheme() => _theme ??= _themeLazy.Value;

public static ResourceDictionary GetStandaloneTheme()
{
Expand Down