From f219acff4925d97fb817506d228b1d57a529a73b Mon Sep 17 00:00:00 2001
From: Zhang Dian <54255897+zdpcdt@users.noreply.github.com>
Date: Mon, 9 Sep 2024 19:54:04 +0800
Subject: [PATCH] feat: Notification Position.
---
demo/Ursa.Demo/Pages/NotificationDemo.axaml | 46 +++++++++++++++----
demo/Ursa.Demo/Pages/ToastDemo.axaml | 30 ++++++++----
.../ViewModels/NotificationDemoViewModel.cs | 10 ++++
.../Controls/Notification.axaml | 30 +++++++++++-
.../Controls/Notification/NotificationCard.cs | 36 ++++++++++++++-
5 files changed, 130 insertions(+), 22 deletions(-)
diff --git a/demo/Ursa.Demo/Pages/NotificationDemo.axaml b/demo/Ursa.Demo/Pages/NotificationDemo.axaml
index b5cd1db..f32fb3c 100644
--- a/demo/Ursa.Demo/Pages/NotificationDemo.axaml
+++ b/demo/Ursa.Demo/Pages/NotificationDemo.axaml
@@ -11,24 +11,50 @@
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
+
+
+
+
+
+
+
+
-
-
-
-
+
+
+
+
\ No newline at end of file
diff --git a/demo/Ursa.Demo/Pages/ToastDemo.axaml b/demo/Ursa.Demo/Pages/ToastDemo.axaml
index 1a4a1db..bddf38f 100644
--- a/demo/Ursa.Demo/Pages/ToastDemo.axaml
+++ b/demo/Ursa.Demo/Pages/ToastDemo.axaml
@@ -11,24 +11,34 @@
-
-
+
+
+
-
-
-
-
+
+
+
+
+
+
+
+
-
-
-
-
+
+
+
+
\ No newline at end of file
diff --git a/demo/Ursa.Demo/ViewModels/NotificationDemoViewModel.cs b/demo/Ursa.Demo/ViewModels/NotificationDemoViewModel.cs
index da1623c..86d7e23 100644
--- a/demo/Ursa.Demo/ViewModels/NotificationDemoViewModel.cs
+++ b/demo/Ursa.Demo/ViewModels/NotificationDemoViewModel.cs
@@ -13,6 +13,16 @@ public partial class NotificationDemoViewModel : ObservableObject
[ObservableProperty] private bool _showClose = true;
+ [RelayCommand]
+ public void ChangePosition(object obj)
+ {
+ if (obj is string s && NotificationManager is not null)
+ {
+ Enum.TryParse(s, out var notificationPosition);
+ NotificationManager.Position = notificationPosition;
+ }
+ }
+
[RelayCommand]
public void ShowNormal(object obj)
{
diff --git a/src/Ursa.Themes.Semi/Controls/Notification.axaml b/src/Ursa.Themes.Semi/Controls/Notification.axaml
index a550bc3..8cfa4c8 100644
--- a/src/Ursa.Themes.Semi/Controls/Notification.axaml
+++ b/src/Ursa.Themes.Semi/Controls/Notification.axaml
@@ -22,8 +22,36 @@
-
+
+
+
+
+
+
+
+
+
+
diff --git a/src/Ursa/Controls/Notification/NotificationCard.cs b/src/Ursa/Controls/Notification/NotificationCard.cs
index 5956712..64bdee4 100644
--- a/src/Ursa/Controls/Notification/NotificationCard.cs
+++ b/src/Ursa/Controls/Notification/NotificationCard.cs
@@ -1,6 +1,40 @@
+using Avalonia;
+using Avalonia.Controls;
+using Avalonia.Controls.Notifications;
+using Avalonia.LogicalTree;
+
namespace Ursa.Controls;
///
/// Control that represents and displays a notification.
///
-public class NotificationCard : MessageCard;
\ No newline at end of file
+public class NotificationCard : MessageCard
+{
+ private NotificationPosition _position;
+
+ public NotificationPosition Position
+ {
+ get => _position;
+ set => SetAndRaise(PositionProperty, ref _position, value);
+ }
+
+ public static readonly DirectProperty PositionProperty =
+ AvaloniaProperty.RegisterDirect(nameof(Position),
+ o => o.Position, (o, v) => o.Position = v);
+
+ protected override void OnAttachedToLogicalTree(LogicalTreeAttachmentEventArgs e)
+ {
+ base.OnAttachedToLogicalTree(e);
+ UpdatePseudoClasses(Position);
+ }
+
+ private void UpdatePseudoClasses(NotificationPosition position)
+ {
+ PseudoClasses.Set(WindowNotificationManager.PC_TopLeft, position == NotificationPosition.TopLeft);
+ PseudoClasses.Set(WindowNotificationManager.PC_TopRight, position == NotificationPosition.TopRight);
+ PseudoClasses.Set(WindowNotificationManager.PC_BottomLeft, position == NotificationPosition.BottomLeft);
+ PseudoClasses.Set(WindowNotificationManager.PC_BottomRight, position == NotificationPosition.BottomRight);
+ PseudoClasses.Set(WindowNotificationManager.PC_TopCenter, position == NotificationPosition.TopCenter);
+ PseudoClasses.Set(WindowNotificationManager.PC_BottomCenter, position == NotificationPosition.BottomCenter);
+ }
+}
\ No newline at end of file