Browse Source

remove notification manager property from toplevel. remove unused notification manager in control catalog main window

pull/9277/head
Emmanuel Hansen 4 years ago
parent
commit
96d4a1588b
  1. 12
      samples/ControlCatalog/MainWindow.xaml.cs
  2. 2
      samples/ControlCatalog/Pages/NotificationsPage.xaml.cs
  3. 2
      samples/ControlCatalog/ViewModels/MainWindowViewModel.cs
  4. 12
      src/Avalonia.Controls/Notifications/WindowNotificationManager.cs
  5. 13
      src/Avalonia.Controls/TopLevel.cs

12
samples/ControlCatalog/MainWindow.xaml.cs

@ -11,23 +11,13 @@ namespace ControlCatalog
{ {
public class MainWindow : Window public class MainWindow : Window
{ {
private WindowNotificationManager _notificationArea;
private NativeMenu? _recentMenu; private NativeMenu? _recentMenu;
public MainWindow() public MainWindow()
{ {
this.InitializeComponent(); this.InitializeComponent();
//Renderer.DrawFps = true; DataContext = new MainWindowViewModel();
//Renderer.DrawDirtyRects = Renderer.DrawFps = true;
_notificationArea = new WindowNotificationManager(this)
{
Position = NotificationPosition.TopRight,
MaxItems = 3
};
DataContext = new MainWindowViewModel(_notificationArea);
_recentMenu = ((NativeMenu.GetMenu(this)?.Items[0] as NativeMenuItem)?.Menu?.Items[2] as NativeMenuItem)?.Menu; _recentMenu = ((NativeMenu.GetMenu(this)?.Items[0] as NativeMenuItem)?.Menu?.Items[2] as NativeMenuItem)?.Menu;
} }

2
samples/ControlCatalog/Pages/NotificationsPage.xaml.cs

@ -27,7 +27,7 @@ namespace ControlCatalog.Pages
{ {
base.OnAttachedToVisualTree(e); base.OnAttachedToVisualTree(e);
_viewModel.NotificationManager = (VisualRoot as TopLevel)?.NotificationManager; _viewModel.NotificationManager = new Avalonia.Controls.Notifications.WindowNotificationManager(VisualRoot as TopLevel);
} }
} }
} }

2
samples/ControlCatalog/ViewModels/MainWindowViewModel.cs

@ -24,7 +24,7 @@ namespace ControlCatalog.ViewModels
private bool _preferSystemChromeEnabled; private bool _preferSystemChromeEnabled;
private double _titleBarHeight; private double _titleBarHeight;
public MainWindowViewModel(IManagedNotificationManager notificationManager) public MainWindowViewModel()
{ {
AboutCommand = MiniCommand.CreateFromTask(async () => AboutCommand = MiniCommand.CreateFromTask(async () =>
{ {

12
src/Avalonia.Controls/Notifications/WindowNotificationManager.cs

@ -54,20 +54,12 @@ namespace Avalonia.Controls.Notifications
/// Initializes a new instance of the <see cref="WindowNotificationManager"/> class. /// Initializes a new instance of the <see cref="WindowNotificationManager"/> class.
/// </summary> /// </summary>
/// <param name="host">The window that will host the control.</param> /// <param name="host">The window that will host the control.</param>
public WindowNotificationManager(TopLevel host) public WindowNotificationManager(TopLevel? host)
{ {
if (VisualChildren.Count != 0) if (host != null)
{ {
Install(host); Install(host);
} }
else
{
Observable.FromEventPattern<TemplateAppliedEventArgs>(host, nameof(host.TemplateApplied)).Take(1)
.Subscribe(_ =>
{
Install(host);
});
}
UpdatePseudoClasses(Position); UpdatePseudoClasses(Position);
} }

13
src/Avalonia.Controls/TopLevel.cs

@ -96,7 +96,6 @@ namespace Avalonia.Controls
private Border? _transparencyFallbackBorder; private Border? _transparencyFallbackBorder;
private TargetWeakEventSubscriber<TopLevel, ResourcesChangedEventArgs>? _resourcesChangesSubscriber; private TargetWeakEventSubscriber<TopLevel, ResourcesChangedEventArgs>? _resourcesChangesSubscriber;
private IStorageProvider? _storageProvider; private IStorageProvider? _storageProvider;
private WindowNotificationManager? _notificationManager;
/// <summary> /// <summary>
/// Initializes static members of the <see cref="TopLevel"/> class. /// Initializes static members of the <see cref="TopLevel"/> class.
@ -330,18 +329,6 @@ namespace Avalonia.Controls
IRenderTarget IRenderRoot.CreateRenderTarget() => CreateRenderTarget(); IRenderTarget IRenderRoot.CreateRenderTarget() => CreateRenderTarget();
public WindowNotificationManager NotificationManager
{
get
{
if(_notificationManager == null)
{
_notificationManager = new WindowNotificationManager(this);
}
return _notificationManager;
}
}
/// <inheritdoc/> /// <inheritdoc/>
protected virtual IRenderTarget CreateRenderTarget() protected virtual IRenderTarget CreateRenderTarget()
{ {

Loading…
Cancel
Save