fix: fix notification.

This commit is contained in:
rabbitism 2023-02-01 21:33:12 +08:00
parent 1554e7bac9
commit a56a0ee18b
3 changed files with 6 additions and 14 deletions

View File

@ -1,5 +1,6 @@
using System;
using Avalonia;
using Avalonia.Dialogs;
using Avalonia.Media;
namespace Semi.Avalonia.Demo.Desktop;
@ -26,6 +27,7 @@ class Program
// Avalonia configuration, don't remove; also used by visual designer.
public static AppBuilder BuildAvaloniaApp()
=> AppBuilder.Configure<App>()
.UseManagedSystemDialogs()
.UsePlatformDetect()
.With(new Win32PlatformOptions())
.LogToTrace();

View File

@ -12,7 +12,7 @@ namespace Semi.Avalonia.Demo.Pages;
public partial class NotificationDemo : UserControl
{
private MainWindow? _window;
private WindowNotificationManager _manager;
public NotificationDemo()
{
InitializeComponent();
@ -21,14 +21,15 @@ public partial class NotificationDemo : UserControl
protected override void OnAttachedToVisualTree(VisualTreeAttachmentEventArgs e)
{
base.OnAttachedToVisualTree(e);
_window = VisualRoot as MainWindow;
var topLevel = TopLevel.GetTopLevel(this);
_manager = new WindowNotificationManager(topLevel){ MaxItems = 3};
}
private void InfoButton_OnClick(object? sender, RoutedEventArgs e)
{
if (sender is Button b && b.Content is string s && Enum.TryParse<NotificationType>(s, out NotificationType t))
{
_window?.Notify(t);
_manager.Show(new Notification(t.ToString(), "This is message", t));
}
}
}

View File

@ -5,19 +5,8 @@ namespace Semi.Avalonia.Demo.Views;
public partial class MainWindow : Window
{
private readonly WindowNotificationManager _manager;
public MainWindow()
{
InitializeComponent();
_manager = new WindowNotificationManager(this)
{
Position = NotificationPosition.TopLeft,
MaxItems = 3
};
}
internal void Notify(NotificationType t)
{
_manager.Show(new Notification(t.ToString(), "This is a notification message", t));
}
}