diff --git a/samples/ControlCatalog/MainWindow.xaml b/samples/ControlCatalog/MainWindow.xaml index 49d0ee72ff..beac57077f 100644 --- a/samples/ControlCatalog/MainWindow.xaml +++ b/samples/ControlCatalog/MainWindow.xaml @@ -5,7 +5,7 @@ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:vm="clr-namespace:ControlCatalog.ViewModels" xmlns:v="clr-namespace:ControlCatalog.Views" - x:Class="ControlCatalog.MainWindow"> + x:Class="ControlCatalog.MainWindow" LocalNotificationManager="{Binding NotificationManager}"> diff --git a/samples/ControlCatalog/ViewModels/MainWindowViewModel.cs b/samples/ControlCatalog/ViewModels/MainWindowViewModel.cs index a514b4d621..7a02f5a45c 100644 --- a/samples/ControlCatalog/ViewModels/MainWindowViewModel.cs +++ b/samples/ControlCatalog/ViewModels/MainWindowViewModel.cs @@ -4,19 +4,26 @@ using System.Text; using System.Threading.Tasks; using Avalonia; using Avalonia.Controls.Notifications; +using Avalonia.Diagnostics.ViewModels; using Avalonia.Threading; +using ReactiveUI; namespace ControlCatalog.ViewModels { - class MainWindowViewModel + class MainWindowViewModel : ViewModelBase { public MainWindowViewModel() { + this.WhenAnyValue(x => x.NotificationManager).Subscribe(x => + { + + }); + Dispatcher.UIThread.InvokeAsync(async () => { await Task.Delay(5000); - + Application.Current.MainWindow.LocalNotificationManager.Show(new NotificationViewModel { Title = "Warning", Message = "Please save your work before closing." }); await Task.Delay(1500); @@ -33,5 +40,13 @@ namespace ControlCatalog.ViewModels }); } + + private INotificationManager _notificationManager; + + public INotificationManager NotificationManager + { + get { return _notificationManager; } + set { this.RaiseAndSetIfChanged(ref _notificationManager, value); } + } } } diff --git a/src/Avalonia.Controls/TopLevel.cs b/src/Avalonia.Controls/TopLevel.cs index 475fc5a927..dcd7434947 100644 --- a/src/Avalonia.Controls/TopLevel.cs +++ b/src/Avalonia.Controls/TopLevel.cs @@ -52,7 +52,7 @@ namespace Avalonia.Controls /// Defines the property. /// public static readonly DirectProperty LocalNotificationManagerProperty = - AvaloniaProperty.RegisterDirect(nameof(LocalNotificationManager), o => o.LocalNotificationManager); + AvaloniaProperty.RegisterDirect(nameof(LocalNotificationManager), o => o.LocalNotificationManager, defaultBindingMode: Data.BindingMode.OneWayToSource); /// /// Defines the property.