77using AvPlatform = Avalonia . Platform ;
88using Core = Avalonia . Controls ;
99using IPlatformHandle = Avalonia . Platform . IPlatformHandle ;
10+ using Color = Avalonia . Media . Color ;
11+ using Colors = Avalonia . Media . Colors ;
1012#if WPF
1113using AvaloniaUI . Xpf . WpfAbstractions ;
1214using Window = System . Windows . Window ;
@@ -38,6 +40,7 @@ public class NativeWebDialog : Core.IWebView, Core.IWebViewHolder, IDisposable
3840 private bool ? _initialCanUserResize ;
3941 private PixelSize ? _initialSize ;
4042 private PixelPoint ? _initialPosition ;
43+ private Color ? _initialDefaultBackground ;
4144 private bool _disposed ;
4245 private bool _dialogInitialized ;
4346
@@ -276,6 +279,24 @@ public bool CanUserResize
276279 }
277280 }
278281
282+ /// <summary>
283+ /// Gets or sets the background color of the dialog and of the webview hosted inside of it.
284+ /// If null, the owner background is used, falling back to white.
285+ /// </summary>
286+ public Color ? DefaultBackground
287+ {
288+ get => _initialDefaultBackground ;
289+ set
290+ {
291+ _initialDefaultBackground = value ;
292+ if ( value is { } background
293+ && TryGetImpl ( ) is { } impl )
294+ {
295+ impl . DefaultBackground = background ;
296+ }
297+ }
298+ }
299+
279300 /// <inheritdoc cref="Core.INativeWebViewDialog.Closing"/>
280301 public event EventHandler ? Closing ;
281302 /// <inheritdoc cref="Core.INativeWebViewDialog.Show()"/>
@@ -295,6 +316,12 @@ public async void Show(TopLevel owner)
295316 {
296317 var impl = await GetOrInitialize ( ) ;
297318
319+ // Not stored in _initialDefaultBackground, so the owner is still resolved again on the next Show call.
320+ if ( _initialDefaultBackground is null )
321+ {
322+ impl . DefaultBackground = GetOwnerBackground ( owner ) ;
323+ }
324+
298325#if WPF
299326 var avTopLevel = XpfWpfAbstraction . GetAvaloniaTopLevelForWindow ( owner ) ;
300327#elif AVALONIA
@@ -317,6 +344,18 @@ public async void Show(TopLevel owner)
317344 }
318345 }
319346
347+ #if WPF
348+ private static Color GetOwnerBackground ( Window owner ) =>
349+ owner . Background is System . Windows . Media . SolidColorBrush solid ?
350+ new Color ( solid . Color . A , solid . Color . R , solid . Color . G , solid . Color . B ) :
351+ Colors . White ;
352+ #elif AVALONIA
353+ private static Color GetOwnerBackground ( TopLevel owner ) =>
354+ owner . Background is Media . ISolidColorBrush solid ?
355+ solid . Color :
356+ Colors . White ;
357+ #endif
358+
320359 private async Task < Core . INativeWebViewDialog > GetOrInitialize ( )
321360 {
322361 if ( TryGetImpl ( ) is { } impl )
@@ -439,6 +478,8 @@ private async Task Initialize()
439478 dialogImpl . Move ( position . X , position . Y ) ;
440479 if ( _initialSize is { } size )
441480 dialogImpl . Resize ( size . Width , size . Height ) ;
481+ if ( _initialDefaultBackground is { } background )
482+ dialogImpl . DefaultBackground = background ;
442483
443484 _implTcs . SetResult ( dialogImpl ) ;
444485
0 commit comments