diff --git a/demo/Ursa.Demo/Pages/NotificationDemo.axaml b/demo/Ursa.Demo/Pages/NotificationDemo.axaml index f32fb3c..846ff53 100644 --- a/demo/Ursa.Demo/Pages/NotificationDemo.axaml +++ b/demo/Ursa.Demo/Pages/NotificationDemo.axaml @@ -12,7 +12,10 @@ - + + + + diff --git a/demo/Ursa.Demo/Pages/ToastDemo.axaml b/demo/Ursa.Demo/Pages/ToastDemo.axaml index bddf38f..72f2145 100644 --- a/demo/Ursa.Demo/Pages/ToastDemo.axaml +++ b/demo/Ursa.Demo/Pages/ToastDemo.axaml @@ -12,7 +12,10 @@ - + + + + diff --git a/demo/Ursa.Demo/ViewModels/NotificationDemoViewModel.cs b/demo/Ursa.Demo/ViewModels/NotificationDemoViewModel.cs index 86d7e23..6fafc95 100644 --- a/demo/Ursa.Demo/ViewModels/NotificationDemoViewModel.cs +++ b/demo/Ursa.Demo/ViewModels/NotificationDemoViewModel.cs @@ -11,6 +11,7 @@ public partial class NotificationDemoViewModel : ObservableObject { public WindowNotificationManager? NotificationManager { get; set; } + [ObservableProperty] private bool _showIcon = true; [ObservableProperty] private bool _showClose = true; [RelayCommand] @@ -26,27 +27,25 @@ public partial class NotificationDemoViewModel : ObservableObject [RelayCommand] public void ShowNormal(object obj) { - if (obj is string s) - { - Enum.TryParse(s, out var notificationType); - NotificationManager?.Show( - new Notification("Welcome", "This is message"), - showClose: ShowClose, - type: notificationType); - } + if (obj is not string s) return; + Enum.TryParse(s, out var notificationType); + NotificationManager?.Show( + new Notification("Welcome", "This is message"), + showIcon: ShowIcon, + showClose: ShowClose, + type: notificationType); } [RelayCommand] public void ShowLight(object obj) { - if (obj is string s) - { - Enum.TryParse(s, out var notificationType); - NotificationManager?.Show( - new Notification("Welcome", "This is message"), - showClose: ShowClose, - type: notificationType, - classes: ["Light"]); - } + if (obj is not string s) return; + Enum.TryParse(s, out var notificationType); + NotificationManager?.Show( + new Notification("Welcome", "This is message"), + showIcon: ShowIcon, + showClose: ShowClose, + type: notificationType, + classes: ["Light"]); } } \ No newline at end of file diff --git a/demo/Ursa.Demo/ViewModels/ToastDemoViewModel.cs b/demo/Ursa.Demo/ViewModels/ToastDemoViewModel.cs index 9b97e19..fa0c87a 100644 --- a/demo/Ursa.Demo/ViewModels/ToastDemoViewModel.cs +++ b/demo/Ursa.Demo/ViewModels/ToastDemoViewModel.cs @@ -10,8 +10,8 @@ public partial class ToastDemoViewModel : ObservableObject { public WindowToastManager? ToastManager { get; set; } - [ObservableProperty] - private bool _showClose = true; + [ObservableProperty] private bool _showIcon = true; + [ObservableProperty] private bool _showClose = true; [RelayCommand] public void ShowNormal(object obj) @@ -21,6 +21,7 @@ public partial class ToastDemoViewModel : ObservableObject Enum.TryParse(s, out var notificationType); ToastManager?.Show( new Toast("This is message"), + showIcon: ShowIcon, showClose: ShowClose, type: notificationType); } @@ -40,6 +41,7 @@ public partial class ToastDemoViewModel : ObservableObject Enum.TryParse(s, out var notificationType); ToastManager?.Show( new Toast("This is message"), + showIcon: ShowIcon, showClose: ShowClose, type: notificationType, classes: ["Light"]); diff --git a/src/Ursa.Themes.Semi/Controls/Notification.axaml b/src/Ursa.Themes.Semi/Controls/Notification.axaml index deae03e..baf697e 100644 --- a/src/Ursa.Themes.Semi/Controls/Notification.axaml +++ b/src/Ursa.Themes.Semi/Controls/Notification.axaml @@ -92,7 +92,7 @@ Height="{DynamicResource NotificationCardIconHeight}" Margin="{DynamicResource NotificationCardIconMargin}" VerticalAlignment="Top" - IsVisible="False" + IsVisible="{TemplateBinding ShowIcon}" Data="{DynamicResource NotificationCardInformationIconPathData}" /> diff --git a/src/Ursa.Themes.Semi/Controls/Toast.axaml b/src/Ursa.Themes.Semi/Controls/Toast.axaml index fb62795..6a946ad 100644 --- a/src/Ursa.Themes.Semi/Controls/Toast.axaml +++ b/src/Ursa.Themes.Semi/Controls/Toast.axaml @@ -57,7 +57,7 @@ Height="{DynamicResource NotificationCardIconHeight}" Margin="{DynamicResource ToastCardIconMargin}" VerticalAlignment="Top" - IsVisible="False" + IsVisible="{TemplateBinding ShowIcon}" Data="{DynamicResource NotificationCardInformationIconPathData}" /> diff --git a/src/Ursa/Controls/Notification/Notification.cs b/src/Ursa/Controls/Notification/Notification.cs index d3e1230..e6cdd99 100644 --- a/src/Ursa/Controls/Notification/Notification.cs +++ b/src/Ursa/Controls/Notification/Notification.cs @@ -85,6 +85,9 @@ public class Notification : INotification, INotifyPropertyChanged /// public TimeSpan Expiration { get; set; } + /// + public bool ShowIcon { get; set; } + /// public bool ShowClose { get; } diff --git a/src/Ursa/Controls/Notification/WindowNotificationManager.cs b/src/Ursa/Controls/Notification/WindowNotificationManager.cs index af502a6..f6b517e 100644 --- a/src/Ursa/Controls/Notification/WindowNotificationManager.cs +++ b/src/Ursa/Controls/Notification/WindowNotificationManager.cs @@ -66,7 +66,9 @@ public class WindowNotificationManager : WindowMessageManager, INotificationMana /// public void Show(INotification content) { - Show(content, content.Type, content.Expiration, content.ShowClose, content.OnClick, content.OnClose); + Show(content, content.Type, content.Expiration, + content.ShowIcon, content.ShowClose, + content.OnClick, content.OnClose); } /// @@ -74,8 +76,9 @@ public class WindowNotificationManager : WindowMessageManager, INotificationMana { if (content is INotification notification) { - Show(notification, notification.Type, notification.Expiration, notification.ShowClose, notification.OnClick, - notification.OnClose); + Show(notification, notification.Type, notification.Expiration, + notification.ShowIcon, notification.ShowClose, + notification.OnClick, notification.OnClose); } else { @@ -89,6 +92,7 @@ public class WindowNotificationManager : WindowMessageManager, INotificationMana /// the content of the notification /// the type of the notification /// the expiration time of the notification after which it will automatically close. If the value is Zero then the notification will remain open until the user closes it + /// whether to show the icon /// whether to show the close button /// an Action to be run when the notification is clicked /// an Action to be run when the notification is closed @@ -97,6 +101,7 @@ public class WindowNotificationManager : WindowMessageManager, INotificationMana object content, NotificationType type, TimeSpan? expiration = null, + bool showIcon = true, bool showClose = true, Action? onClick = null, Action? onClose = null, @@ -108,6 +113,7 @@ public class WindowNotificationManager : WindowMessageManager, INotificationMana { Content = content, NotificationType = type, + ShowIcon = showIcon, ShowClose = showClose, [!NotificationCard.PositionProperty] = this[!PositionProperty] }; diff --git a/src/Ursa/Controls/NotificationShared/IMessage.cs b/src/Ursa/Controls/NotificationShared/IMessage.cs index b1cad33..53fdbe9 100644 --- a/src/Ursa/Controls/NotificationShared/IMessage.cs +++ b/src/Ursa/Controls/NotificationShared/IMessage.cs @@ -12,6 +12,11 @@ public interface IMessage /// NotificationType Type { get; } + /// + /// Gets a value indicating whether the message should show an icon. + /// + bool ShowIcon { get; } + /// /// Gets a value indicating whether the message should show a close button. /// diff --git a/src/Ursa/Controls/NotificationShared/MessageCard.cs b/src/Ursa/Controls/NotificationShared/MessageCard.cs index d244a69..3400a45 100644 --- a/src/Ursa/Controls/NotificationShared/MessageCard.cs +++ b/src/Ursa/Controls/NotificationShared/MessageCard.cs @@ -78,6 +78,15 @@ public abstract class MessageCard : ContentControl public static readonly StyledProperty NotificationTypeProperty = AvaloniaProperty.Register(nameof(NotificationType)); + public bool ShowIcon + { + get => GetValue(ShowIconProperty); + set => SetValue(ShowIconProperty, value); + } + + public static readonly StyledProperty ShowIconProperty = + AvaloniaProperty.Register(nameof(ShowIcon), true); + public bool ShowClose { get => GetValue(ShowCloseProperty); @@ -187,19 +196,19 @@ public abstract class MessageCard : ContentControl { switch (NotificationType) { - case NotificationType.Error: + case Avalonia.Controls.Notifications.NotificationType.Error: PseudoClasses.Add(PC_Error); break; - case NotificationType.Information: + case Avalonia.Controls.Notifications.NotificationType.Information: PseudoClasses.Add(PC_Information); break; - case NotificationType.Success: + case Avalonia.Controls.Notifications.NotificationType.Success: PseudoClasses.Add(PC_Success); break; - case NotificationType.Warning: + case Avalonia.Controls.Notifications.NotificationType.Warning: PseudoClasses.Add(PC_Warning); break; } diff --git a/src/Ursa/Controls/Toast/Toast.cs b/src/Ursa/Controls/Toast/Toast.cs index 8352272..a59233f 100644 --- a/src/Ursa/Controls/Toast/Toast.cs +++ b/src/Ursa/Controls/Toast/Toast.cs @@ -65,6 +65,9 @@ public class Toast : IToast, INotifyPropertyChanged /// public NotificationType Type { get; set; } + /// + public bool ShowIcon { get; set; } + /// public bool ShowClose { get; set; } diff --git a/src/Ursa/Controls/Toast/WindowToastManager.cs b/src/Ursa/Controls/Toast/WindowToastManager.cs index 7ab3e15..18c9be8 100644 --- a/src/Ursa/Controls/Toast/WindowToastManager.cs +++ b/src/Ursa/Controls/Toast/WindowToastManager.cs @@ -1,8 +1,5 @@ using Avalonia.Controls; -using Avalonia.Controls.Metadata; using Avalonia.Controls.Notifications; -using Avalonia.Controls.Primitives; -using Avalonia.Layout; using Avalonia.Threading; namespace Ursa.Controls; @@ -34,7 +31,9 @@ public class WindowToastManager : WindowMessageManager, IToastManager /// public void Show(IToast content) { - Show(content, content.Type, content.Expiration, content.ShowClose, content.OnClick, content.OnClose); + Show(content, content.Type, content.Expiration, + content.ShowIcon, content.ShowClose, + content.OnClick, content.OnClose); } /// @@ -42,7 +41,9 @@ public class WindowToastManager : WindowMessageManager, IToastManager { if (content is IToast toast) { - Show(toast, toast.Type, toast.Expiration, toast.ShowClose, toast.OnClick, toast.OnClose); + Show(toast, toast.Type, toast.Expiration, + toast.ShowIcon, toast.ShowClose, + toast.OnClick, toast.OnClose); } else { @@ -56,6 +57,7 @@ public class WindowToastManager : WindowMessageManager, IToastManager /// the content of the toast /// the type of the toast /// the expiration time of the toast after which it will automatically close. If the value is Zero then the toast will remain open until the user closes it + /// whether to show the icon /// whether to show the close button /// an Action to be run when the toast is clicked /// an Action to be run when the toast is closed @@ -64,6 +66,7 @@ public class WindowToastManager : WindowMessageManager, IToastManager object content, NotificationType type, TimeSpan? expiration = null, + bool showIcon = true, bool showClose = true, Action? onClick = null, Action? onClose = null, @@ -75,6 +78,7 @@ public class WindowToastManager : WindowMessageManager, IToastManager { Content = content, NotificationType = type, + ShowIcon = showIcon, ShowClose = showClose };