Skip to content

Commit e55d78c

Browse files
authored
Merge pull request #68 from AvaloniaUtils/reworkColorsPicking
Replace MultiDynamicResourceExtension with ResourceProvider for Background lookup
2 parents 61f074f + cf8660f commit e55d78c

File tree

3 files changed

+58
-102
lines changed

3 files changed

+58
-102
lines changed

DialogHost.Avalonia/DialogHost.axaml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,8 @@
2525
<Setter Property="HorizontalAlignment" Value="Stretch" />
2626
<Setter Property="VerticalAlignment" Value="Stretch" />
2727
<Setter Property="DialogMargin" Value="8" />
28-
<Setter Property="OverlayBackground"
29-
Value="{utilities:MultiDynamicResource DefaultBrush=Black, ResourceKeys=SystemControlBackgroundBaseHighBrush}" />
30-
<Setter Property="Background"
31-
Value="{utilities:MultiDynamicResource DefaultBrush=Black, ResourceKeys=SystemControlBackgroundAltHighBrush;MaterialDesignPaper;MaterialPaperBrush}">
32-
</Setter>
28+
<Setter Property="OverlayBackground" Value="{DynamicResource DialogHostOverlayBackgroundMixinBrush}" />
29+
<Setter Property="Background" Value="{DynamicResource DialogHostBackgroundMixinBrush}" />
3330
<Setter Property="dialogHostAvalonia:DialogHostStyle.ClipToBounds" Value="False" />
3431
<Setter Property="dialogHostAvalonia:DialogHostStyle.CornerRadius" Value="2" />
3532
<Setter Property="Template">

DialogHost.Avalonia/DialogHostStyles.axaml.cs

Lines changed: 56 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1-
using Avalonia.Controls;
1+
using System.Collections.Generic;
2+
using Avalonia;
3+
using Avalonia.Controls;
24
using Avalonia.Markup.Xaml;
5+
using Avalonia.Media;
36
using Avalonia.Styling;
47

58
namespace DialogHostAvalonia {
@@ -19,7 +22,7 @@ namespace DialogHostAvalonia {
1922
/// &lt;/Application&gt;
2023
/// </code>
2124
/// </remarks>
22-
public class DialogHostStyles : Styles {
25+
public class DialogHostStyles : Styles, IResourceNode {
2326
/// <inheritdoc />
2427
public DialogHostStyles() {
2528
AvaloniaXamlLoader.Load(this);
@@ -29,5 +32,56 @@ public DialogHostStyles() {
2932
public DialogHostStyles(IResourceHost owner) : base(owner) {
3033
AvaloniaXamlLoader.Load(this);
3134
}
35+
36+
/// <summary>
37+
/// Lists of resource keys which will be used as defaults for DialogHost.Background property
38+
/// </summary>
39+
public static IReadOnlyList<string> BackgroundColorKeys { get; } = ["SystemControlPageBackgroundChromeLowBrush"];
40+
41+
/// <summary>
42+
/// Lists of resource keys which will be used as defaults for DialogHost.OverlayBackground property
43+
/// </summary>
44+
public static IReadOnlyList<string> OverlayBackgroundColorKeys { get; } =
45+
["SystemControlBackgroundAltHighBrush", "MaterialDesignPaper", "MaterialPaperBrush"];
46+
47+
bool IResourceNode.HasResources => true;
48+
49+
/// <summary>
50+
/// Tries to find a resource within the object.
51+
/// </summary>
52+
/// <param name="key">The resource key.</param>
53+
/// <param name="theme">Theme used to select theme dictionary.</param>
54+
/// <param name="value">
55+
/// When this method returns, contains the value associated with the specified key,
56+
/// if the key is found; otherwise, null.
57+
/// </param>
58+
/// <returns>
59+
/// True if the resource if found, otherwise false.
60+
/// </returns>
61+
bool IResourceNode.TryGetResource(object key, ThemeVariant? theme, out object? value) {
62+
if (key is "DialogHostBackgroundMixinBrush") {
63+
foreach (var colorKey in BackgroundColorKeys) {
64+
if (Application.Current!.TryGetResource(colorKey, theme, out value)) {
65+
return true;
66+
}
67+
}
68+
69+
value = Brushes.Black;
70+
return true;
71+
}
72+
73+
if (key is "DialogHostOverlayBackgroundMixinBrush") {
74+
foreach (var colorKey in OverlayBackgroundColorKeys) {
75+
if (Application.Current!.TryGetResource(colorKey, theme, out value)) {
76+
return true;
77+
}
78+
}
79+
80+
value = Brushes.Black;
81+
return true;
82+
}
83+
84+
return base.TryGetResource(key, theme, out value);
85+
}
3286
}
3387
}

DialogHost.Avalonia/Utilities/MultiDynamicResourceExtension.cs

Lines changed: 0 additions & 95 deletions
This file was deleted.

0 commit comments

Comments
 (0)