|
|
|
@ -10,12 +10,18 @@ internal class ColorPaletteResourcesCollection : AvaloniaDictionary<ThemeVariant |
|
|
|
public ColorPaletteResourcesCollection() : base(2) |
|
|
|
{ |
|
|
|
this.ForEachItem( |
|
|
|
(_, x) => |
|
|
|
(key, x) => |
|
|
|
{ |
|
|
|
if (Owner is not null) |
|
|
|
{ |
|
|
|
x.PropertyChanged += Palette_PropertyChanged; |
|
|
|
} |
|
|
|
|
|
|
|
if (key != ThemeVariant.Dark && key != ThemeVariant.Light) |
|
|
|
{ |
|
|
|
throw new InvalidOperationException( |
|
|
|
$"{nameof(FluentTheme)}.{nameof(FluentTheme.Palettes)} only supports Light and Dark variants."); |
|
|
|
} |
|
|
|
}, |
|
|
|
(_, x) => |
|
|
|
{ |
|
|
|
@ -30,22 +36,15 @@ internal class ColorPaletteResourcesCollection : AvaloniaDictionary<ThemeVariant |
|
|
|
public bool HasResources => Count > 0; |
|
|
|
public bool TryGetResource(object key, ThemeVariant? theme, out object? value) |
|
|
|
{ |
|
|
|
if (theme is not null) |
|
|
|
if (theme == null || theme == ThemeVariant.Default) |
|
|
|
{ |
|
|
|
if (base.TryGetValue(theme, out var themePaletteResources) |
|
|
|
&& themePaletteResources.TryGetResource(key, theme, out value)) |
|
|
|
{ |
|
|
|
return true; |
|
|
|
} |
|
|
|
theme = ThemeVariant.Light; |
|
|
|
} |
|
|
|
|
|
|
|
if (theme != ThemeVariant.Default) |
|
|
|
if (base.TryGetValue(theme, out var themePaletteResources) |
|
|
|
&& themePaletteResources.TryGetResource(key, theme, out value)) |
|
|
|
{ |
|
|
|
if (base.TryGetValue(ThemeVariant.Default, out var defaultPaletteResources) |
|
|
|
&& defaultPaletteResources.TryGetResource(key, ThemeVariant.Default, out value)) |
|
|
|
{ |
|
|
|
return true; |
|
|
|
} |
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
|
value = null; |
|
|
|
|