1
- using Avalonia . Controls ;
1
+ using System . Collections . Generic ;
2
+ using Avalonia ;
3
+ using Avalonia . Controls ;
2
4
using Avalonia . Markup . Xaml ;
5
+ using Avalonia . Media ;
3
6
using Avalonia . Styling ;
4
7
5
8
namespace DialogHostAvalonia {
@@ -19,7 +22,7 @@ namespace DialogHostAvalonia {
19
22
/// </Application>
20
23
/// </code>
21
24
/// </remarks>
22
- public class DialogHostStyles : Styles {
25
+ public class DialogHostStyles : Styles , IResourceNode {
23
26
/// <inheritdoc />
24
27
public DialogHostStyles ( ) {
25
28
AvaloniaXamlLoader . Load ( this ) ;
@@ -29,5 +32,56 @@ public DialogHostStyles() {
29
32
public DialogHostStyles ( IResourceHost owner ) : base ( owner ) {
30
33
AvaloniaXamlLoader . Load ( this ) ;
31
34
}
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
+ }
32
86
}
33
87
}
0 commit comments