fix: fix notification.
This commit is contained in:
parent
1554e7bac9
commit
a56a0ee18b
@ -1,5 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using Avalonia;
|
using Avalonia;
|
||||||
|
using Avalonia.Dialogs;
|
||||||
using Avalonia.Media;
|
using Avalonia.Media;
|
||||||
|
|
||||||
namespace Semi.Avalonia.Demo.Desktop;
|
namespace Semi.Avalonia.Demo.Desktop;
|
||||||
@ -26,6 +27,7 @@ class Program
|
|||||||
// Avalonia configuration, don't remove; also used by visual designer.
|
// Avalonia configuration, don't remove; also used by visual designer.
|
||||||
public static AppBuilder BuildAvaloniaApp()
|
public static AppBuilder BuildAvaloniaApp()
|
||||||
=> AppBuilder.Configure<App>()
|
=> AppBuilder.Configure<App>()
|
||||||
|
.UseManagedSystemDialogs()
|
||||||
.UsePlatformDetect()
|
.UsePlatformDetect()
|
||||||
.With(new Win32PlatformOptions())
|
.With(new Win32PlatformOptions())
|
||||||
.LogToTrace();
|
.LogToTrace();
|
||||||
|
@ -12,7 +12,7 @@ namespace Semi.Avalonia.Demo.Pages;
|
|||||||
|
|
||||||
public partial class NotificationDemo : UserControl
|
public partial class NotificationDemo : UserControl
|
||||||
{
|
{
|
||||||
private MainWindow? _window;
|
private WindowNotificationManager _manager;
|
||||||
public NotificationDemo()
|
public NotificationDemo()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
@ -21,14 +21,15 @@ public partial class NotificationDemo : UserControl
|
|||||||
protected override void OnAttachedToVisualTree(VisualTreeAttachmentEventArgs e)
|
protected override void OnAttachedToVisualTree(VisualTreeAttachmentEventArgs e)
|
||||||
{
|
{
|
||||||
base.OnAttachedToVisualTree(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)
|
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))
|
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));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -5,19 +5,8 @@ namespace Semi.Avalonia.Demo.Views;
|
|||||||
|
|
||||||
public partial class MainWindow : Window
|
public partial class MainWindow : Window
|
||||||
{
|
{
|
||||||
private readonly WindowNotificationManager _manager;
|
|
||||||
public MainWindow()
|
public MainWindow()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
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));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user