diff --git a/src/Avalonia.Controls/Notifications/INotificationManager.cs b/src/Avalonia.Controls/Notifications/INotificationManager.cs index e0b73d6293..3ea690388d 100644 --- a/src/Avalonia.Controls/Notifications/INotificationManager.cs +++ b/src/Avalonia.Controls/Notifications/INotificationManager.cs @@ -2,7 +2,7 @@ namespace Avalonia.Controls.Notifications { - interface INotificationManager + public interface INotificationManager { void Show(object content, string areaName = "", TimeSpan? expirationTime = null, Action onClick = null, Action onClose = null); } diff --git a/src/Avalonia.Controls/TopLevel.cs b/src/Avalonia.Controls/TopLevel.cs index 32c40847c5..f29da746ab 100644 --- a/src/Avalonia.Controls/TopLevel.cs +++ b/src/Avalonia.Controls/TopLevel.cs @@ -3,6 +3,7 @@ using System; using System.Reactive.Linq; +using Avalonia.Controls.Notifications; using Avalonia.Controls.Primitives; using Avalonia.Input; using Avalonia.Input.Raw; @@ -46,12 +47,26 @@ namespace Avalonia.Controls public static readonly StyledProperty PointerOverElementProperty = AvaloniaProperty.Register(nameof(IInputRoot.PointerOverElement)); + /// + /// Defines the property. + /// + public static readonly DirectProperty LocalNotificationManagerProperty = + AvaloniaProperty.RegisterDirect(nameof(LocalNotificationManager), o => o.LocalNotificationManager); + + /// + /// Defines the property. + /// + public static readonly DirectProperty SystemNotificationManagerProperty = + AvaloniaProperty.RegisterDirect(nameof(SystemNotificationManager), o => o.SystemNotificationManager); + private readonly IInputManager _inputManager; private readonly IAccessKeyHandler _accessKeyHandler; private readonly IKeyboardNavigationHandler _keyboardNavigationHandler; private readonly IApplicationLifecycle _applicationLifecycle; private readonly IPlatformRenderInterface _renderInterface; private Size _clientSize; + private INotificationManager _localNotificationManager; + private INotificationManager _systemNotificationManager; private ILayoutManager _layoutManager; /// @@ -87,6 +102,9 @@ namespace Avalonia.Controls } PlatformImpl = impl; + + _localNotificationManager = new NotificationManager(); + dependencyResolver = dependencyResolver ?? AvaloniaLocator.Current; var styler = TryGetService(dependencyResolver); @@ -96,6 +114,13 @@ namespace Avalonia.Controls _applicationLifecycle = TryGetService(dependencyResolver); _renderInterface = TryGetService(dependencyResolver); + _systemNotificationManager = TryGetService(dependencyResolver); + + if(_systemNotificationManager == null) + { + _systemNotificationManager = _localNotificationManager; + } + Renderer = impl.CreateRenderer(this); if (Renderer != null) @@ -155,6 +180,25 @@ namespace Avalonia.Controls protected set { SetAndRaise(ClientSizeProperty, ref _clientSize, value); } } + /// + /// Gets or sets the Local (in window managed) notification manager. + /// + public INotificationManager LocalNotificationManager + { + get => _localNotificationManager; + protected set => SetAndRaise(LocalNotificationManagerProperty, ref _localNotificationManager, value); + } + + /// + /// Gets or sets the System (native os) notification manager. If the system doesnt natively support notifications then this property + /// will match the . + /// + public INotificationManager SystemNotificationManager + { + get => _systemNotificationManager; + protected set => SetAndRaise(SystemNotificationManagerProperty, ref _systemNotificationManager, value); + } + public ILayoutManager LayoutManager { get