feat: add ShowIcon property.
This commit is contained in:
@@ -92,7 +92,7 @@
|
||||
Height="{DynamicResource NotificationCardIconHeight}"
|
||||
Margin="{DynamicResource NotificationCardIconMargin}"
|
||||
VerticalAlignment="Top"
|
||||
IsVisible="False"
|
||||
IsVisible="{TemplateBinding ShowIcon}"
|
||||
Data="{DynamicResource NotificationCardInformationIconPathData}" />
|
||||
<ContentControl
|
||||
x:Name="PART_Content"
|
||||
@@ -366,22 +366,18 @@
|
||||
</Style>
|
||||
|
||||
<Style Selector="^:information /template/ PathIcon#NotificationIcon">
|
||||
<Setter Property="IsVisible" Value="True" />
|
||||
<Setter Property="Foreground" Value="{DynamicResource NotificationCardInformationIconForeground}" />
|
||||
<Setter Property="Data" Value="{DynamicResource NotificationCardInformationIconPathData}" />
|
||||
</Style>
|
||||
<Style Selector="^:success /template/ PathIcon#NotificationIcon">
|
||||
<Setter Property="IsVisible" Value="True" />
|
||||
<Setter Property="Foreground" Value="{DynamicResource NotificationCardSuccessIconForeground}" />
|
||||
<Setter Property="Data" Value="{DynamicResource NotificationCardSuccessIconPathData}" />
|
||||
</Style>
|
||||
<Style Selector="^:warning /template/ PathIcon#NotificationIcon">
|
||||
<Setter Property="IsVisible" Value="True" />
|
||||
<Setter Property="Foreground" Value="{DynamicResource NotificationCardWarningIconForeground}" />
|
||||
<Setter Property="Data" Value="{DynamicResource NotificationCardWarningIconPathData}" />
|
||||
</Style>
|
||||
<Style Selector="^:error /template/ PathIcon#NotificationIcon">
|
||||
<Setter Property="IsVisible" Value="True" />
|
||||
<Setter Property="Foreground" Value="{DynamicResource NotificationCardErrorIconForeground}" />
|
||||
<Setter Property="Data" Value="{DynamicResource NotificationCardErrorIconPathData}" />
|
||||
</Style>
|
||||
|
||||
@@ -57,7 +57,7 @@
|
||||
Height="{DynamicResource NotificationCardIconHeight}"
|
||||
Margin="{DynamicResource ToastCardIconMargin}"
|
||||
VerticalAlignment="Top"
|
||||
IsVisible="False"
|
||||
IsVisible="{TemplateBinding ShowIcon}"
|
||||
Data="{DynamicResource NotificationCardInformationIconPathData}" />
|
||||
<ContentControl
|
||||
x:Name="PART_Content"
|
||||
@@ -154,22 +154,18 @@
|
||||
</Style>
|
||||
|
||||
<Style Selector="^:information /template/ PathIcon#ToastIcon">
|
||||
<Setter Property="IsVisible" Value="True" />
|
||||
<Setter Property="Foreground" Value="{DynamicResource NotificationCardInformationIconForeground}" />
|
||||
<Setter Property="Data" Value="{DynamicResource NotificationCardInformationIconPathData}" />
|
||||
</Style>
|
||||
<Style Selector="^:success /template/ PathIcon#ToastIcon">
|
||||
<Setter Property="IsVisible" Value="True" />
|
||||
<Setter Property="Foreground" Value="{DynamicResource NotificationCardSuccessIconForeground}" />
|
||||
<Setter Property="Data" Value="{DynamicResource NotificationCardSuccessIconPathData}" />
|
||||
</Style>
|
||||
<Style Selector="^:warning /template/ PathIcon#ToastIcon">
|
||||
<Setter Property="IsVisible" Value="True" />
|
||||
<Setter Property="Foreground" Value="{DynamicResource NotificationCardWarningIconForeground}" />
|
||||
<Setter Property="Data" Value="{DynamicResource NotificationCardWarningIconPathData}" />
|
||||
</Style>
|
||||
<Style Selector="^:error /template/ PathIcon#ToastIcon">
|
||||
<Setter Property="IsVisible" Value="True" />
|
||||
<Setter Property="Foreground" Value="{DynamicResource NotificationCardErrorIconForeground}" />
|
||||
<Setter Property="Data" Value="{DynamicResource NotificationCardErrorIconPathData}" />
|
||||
</Style>
|
||||
|
||||
@@ -85,6 +85,9 @@ public class Notification : INotification, INotifyPropertyChanged
|
||||
/// <inheritdoc/>
|
||||
public TimeSpan Expiration { get; set; }
|
||||
|
||||
/// <inheritdoc/>
|
||||
public bool ShowIcon { get; set; }
|
||||
|
||||
/// <inheritdoc/>
|
||||
public bool ShowClose { get; }
|
||||
|
||||
|
||||
@@ -66,7 +66,9 @@ public class WindowNotificationManager : WindowMessageManager, INotificationMana
|
||||
/// <inheritdoc/>
|
||||
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);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
@@ -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
|
||||
/// <param name="content">the content of the notification</param>
|
||||
/// <param name="type">the type of the notification</param>
|
||||
/// <param name="expiration">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</param>
|
||||
/// <param name="showIcon">whether to show the icon</param>
|
||||
/// <param name="showClose">whether to show the close button</param>
|
||||
/// <param name="onClick">an Action to be run when the notification is clicked</param>
|
||||
/// <param name="onClose">an Action to be run when the notification is closed</param>
|
||||
@@ -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]
|
||||
};
|
||||
|
||||
@@ -12,6 +12,11 @@ public interface IMessage
|
||||
/// </summary>
|
||||
NotificationType Type { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the message should show an icon.
|
||||
/// </summary>
|
||||
bool ShowIcon { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the message should show a close button.
|
||||
/// </summary>
|
||||
|
||||
@@ -78,6 +78,15 @@ public abstract class MessageCard : ContentControl
|
||||
public static readonly StyledProperty<NotificationType> NotificationTypeProperty =
|
||||
AvaloniaProperty.Register<MessageCard, NotificationType>(nameof(NotificationType));
|
||||
|
||||
public bool ShowIcon
|
||||
{
|
||||
get => GetValue(ShowIconProperty);
|
||||
set => SetValue(ShowIconProperty, value);
|
||||
}
|
||||
|
||||
public static readonly StyledProperty<bool> ShowIconProperty =
|
||||
AvaloniaProperty.Register<MessageCard, bool>(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;
|
||||
}
|
||||
|
||||
@@ -65,6 +65,9 @@ public class Toast : IToast, INotifyPropertyChanged
|
||||
/// <inheritdoc/>
|
||||
public NotificationType Type { get; set; }
|
||||
|
||||
/// <inheritdoc/>
|
||||
public bool ShowIcon { get; set; }
|
||||
|
||||
/// <inheritdoc/>
|
||||
public bool ShowClose { get; set; }
|
||||
|
||||
|
||||
@@ -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
|
||||
/// <inheritdoc/>
|
||||
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);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
@@ -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
|
||||
/// <param name="content">the content of the toast</param>
|
||||
/// <param name="type">the type of the toast</param>
|
||||
/// <param name="expiration">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</param>
|
||||
/// <param name="showIcon">whether to show the icon</param>
|
||||
/// <param name="showClose">whether to show the close button</param>
|
||||
/// <param name="onClick">an Action to be run when the toast is clicked</param>
|
||||
/// <param name="onClose">an Action to be run when the toast is closed</param>
|
||||
@@ -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
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user