make it work after theme changing
MODIFY
WalletWasabi.Fluent/Behaviors/RegisterNotificationHostBehavior.cs
WalletWasabi.Fluent/Behaviors/RegisterNotificationHostBehavior.cs
-using Avalonia;
+using System;
+using System.Reactive.Disposables;
+using System.Reactive.Linq;
using Avalonia.Controls;
-using Avalonia.Controls.Notifications;
-using Avalonia.Xaml.Interactivity;
using WalletWasabi.Fluent.Helpers;
namespace WalletWasabi.Fluent.Behaviors
{
- public class RegisterNotificationHostBehavior : Behavior<Window>
+ public class RegisterNotificationHostBehavior : DisposingBehavior<Window>
{
- protected override void OnAttached()
+ protected override void OnAttached(CompositeDisposable disposables)
{
- var notificationManager = new WindowNotificationManager(AssociatedObject)
+ if (AssociatedObject is null)
{
- Position = NotificationPosition.BottomRight,
- MaxItems = 4,
- Margin = new Thickness(0, 0, 15, 40)
- };
+ return;
+ }
+
+ NotificationHelpers.SetNotificationManager(AssociatedObject);
- NotificationHelpers.SetNotificationManager(notificationManager);
+ // Must set notification host again after theme changing.
+ // TODO: improve, execute only once a time
+ Observable
+ .FromEventPattern(AssociatedObject, nameof(AssociatedObject.ResourcesChanged))
+ .Subscribe(_ => NotificationHelpers.SetNotificationManager(AssociatedObject))
+ .DisposeWith(disposables);
}
}
}

MODIFY
WalletWasabi.Fluent/Helpers/NotificationHelpers.cs
WalletWasabi.Fluent/Helpers/NotificationHelpers.cs
@@ -2,6 +2,8 @@ using System;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Reactive.Concurrency;
+using Avalonia;
+using Avalonia.Controls;
using Avalonia.Controls.Notifications;
using NBitcoin;
using ReactiveUI;
@@ -15,14 +17,16 @@ namespace WalletWasabi.Fluent.Helpers
private const int DefaultNotificationTimeout = 7;
private static WindowNotificationManager? NotificationManager;
- public static void SetNotificationManager(WindowNotificationManager windowNotificationManager)
+ public static void SetNotificationManager(Window host)
{
- if (NotificationManager is { })
+ var notificationManager = new WindowNotificationManager(host)
{
- throw new InvalidOperationException("Already set!");
- }
+ Position = NotificationPosition.BottomRight,
+ MaxItems = 4,
+ Margin = new Thickness(0, 0, 15, 40)
+ };
- NotificationManager = windowNotificationManager;
+ NotificationManager = notificationManager;
}
public static void Show(string title, string message)

make it work after theme changing