From 96d4a1588bba6bfca9cdebfcf9bf9a1c3394cf26 Mon Sep 17 00:00:00 2001 From: Emmanuel Hansen Date: Thu, 10 Nov 2022 18:30:06 +0000 Subject: [PATCH] remove notification manager property from toplevel. remove unused notification manager in control catalog main window --- samples/ControlCatalog/MainWindow.xaml.cs | 12 +----------- .../ControlCatalog/Pages/NotificationsPage.xaml.cs | 2 +- .../ViewModels/MainWindowViewModel.cs | 2 +- .../Notifications/WindowNotificationManager.cs | 12 ++---------- src/Avalonia.Controls/TopLevel.cs | 13 ------------- 5 files changed, 5 insertions(+), 36 deletions(-) diff --git a/samples/ControlCatalog/MainWindow.xaml.cs b/samples/ControlCatalog/MainWindow.xaml.cs index c61296ac8f..c589f41442 100644 --- a/samples/ControlCatalog/MainWindow.xaml.cs +++ b/samples/ControlCatalog/MainWindow.xaml.cs @@ -11,23 +11,13 @@ namespace ControlCatalog { public class MainWindow : Window { - private WindowNotificationManager _notificationArea; private NativeMenu? _recentMenu; public MainWindow() { this.InitializeComponent(); - //Renderer.DrawFps = true; - //Renderer.DrawDirtyRects = Renderer.DrawFps = true; - - _notificationArea = new WindowNotificationManager(this) - { - Position = NotificationPosition.TopRight, - MaxItems = 3 - }; - - DataContext = new MainWindowViewModel(_notificationArea); + DataContext = new MainWindowViewModel(); _recentMenu = ((NativeMenu.GetMenu(this)?.Items[0] as NativeMenuItem)?.Menu?.Items[2] as NativeMenuItem)?.Menu; } diff --git a/samples/ControlCatalog/Pages/NotificationsPage.xaml.cs b/samples/ControlCatalog/Pages/NotificationsPage.xaml.cs index be08af41e1..bfd49a2c00 100644 --- a/samples/ControlCatalog/Pages/NotificationsPage.xaml.cs +++ b/samples/ControlCatalog/Pages/NotificationsPage.xaml.cs @@ -27,7 +27,7 @@ namespace ControlCatalog.Pages { base.OnAttachedToVisualTree(e); - _viewModel.NotificationManager = (VisualRoot as TopLevel)?.NotificationManager; + _viewModel.NotificationManager = new Avalonia.Controls.Notifications.WindowNotificationManager(VisualRoot as TopLevel); } } } diff --git a/samples/ControlCatalog/ViewModels/MainWindowViewModel.cs b/samples/ControlCatalog/ViewModels/MainWindowViewModel.cs index 72ba6cead0..b79eff780c 100644 --- a/samples/ControlCatalog/ViewModels/MainWindowViewModel.cs +++ b/samples/ControlCatalog/ViewModels/MainWindowViewModel.cs @@ -24,7 +24,7 @@ namespace ControlCatalog.ViewModels private bool _preferSystemChromeEnabled; private double _titleBarHeight; - public MainWindowViewModel(IManagedNotificationManager notificationManager) + public MainWindowViewModel() { AboutCommand = MiniCommand.CreateFromTask(async () => { diff --git a/src/Avalonia.Controls/Notifications/WindowNotificationManager.cs b/src/Avalonia.Controls/Notifications/WindowNotificationManager.cs index 969b0a38b1..45beaa0b2f 100644 --- a/src/Avalonia.Controls/Notifications/WindowNotificationManager.cs +++ b/src/Avalonia.Controls/Notifications/WindowNotificationManager.cs @@ -54,20 +54,12 @@ namespace Avalonia.Controls.Notifications /// Initializes a new instance of the class. /// /// The window that will host the control. - public WindowNotificationManager(TopLevel host) + public WindowNotificationManager(TopLevel? host) { - if (VisualChildren.Count != 0) + if (host != null) { Install(host); } - else - { - Observable.FromEventPattern(host, nameof(host.TemplateApplied)).Take(1) - .Subscribe(_ => - { - Install(host); - }); - } UpdatePseudoClasses(Position); } diff --git a/src/Avalonia.Controls/TopLevel.cs b/src/Avalonia.Controls/TopLevel.cs index d538f05eec..6804c9ecb9 100644 --- a/src/Avalonia.Controls/TopLevel.cs +++ b/src/Avalonia.Controls/TopLevel.cs @@ -96,7 +96,6 @@ namespace Avalonia.Controls private Border? _transparencyFallbackBorder; private TargetWeakEventSubscriber? _resourcesChangesSubscriber; private IStorageProvider? _storageProvider; - private WindowNotificationManager? _notificationManager; /// /// Initializes static members of the class. @@ -330,18 +329,6 @@ namespace Avalonia.Controls IRenderTarget IRenderRoot.CreateRenderTarget() => CreateRenderTarget(); - public WindowNotificationManager NotificationManager - { - get - { - if(_notificationManager == null) - { - _notificationManager = new WindowNotificationManager(this); - } - return _notificationManager; - } - } - /// protected virtual IRenderTarget CreateRenderTarget() {