Browse Source

attempt to bind to local notification manager.

pull/2453/head
Dan Walmsley 7 years ago
parent
commit
feba03d113
  1. 2
      samples/ControlCatalog/MainWindow.xaml
  2. 19
      samples/ControlCatalog/ViewModels/MainWindowViewModel.cs
  3. 2
      src/Avalonia.Controls/TopLevel.cs

2
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}">
<Window.DataTemplates>
<DataTemplate DataType="vm:NotificationViewModel">
<v:NotificationView />

19
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); }
}
}
}

2
src/Avalonia.Controls/TopLevel.cs

@ -52,7 +52,7 @@ namespace Avalonia.Controls
/// Defines the <see cref="LocalNotificationManager"/> property.
/// </summary>
public static readonly DirectProperty<TopLevel, INotificationManager> LocalNotificationManagerProperty =
AvaloniaProperty.RegisterDirect<TopLevel, INotificationManager>(nameof(LocalNotificationManager), o => o.LocalNotificationManager);
AvaloniaProperty.RegisterDirect<TopLevel, INotificationManager>(nameof(LocalNotificationManager), o => o.LocalNotificationManager, defaultBindingMode: Data.BindingMode.OneWayToSource);
/// <summary>
/// Defines the <see cref="SystemNotificationManager"/> property.

Loading…
Cancel
Save