feat: enhance NotificationCard.
This commit is contained in:
parent
d1089b9779
commit
9220c46d43
@ -7,11 +7,23 @@
|
||||
d:DesignHeight="450"
|
||||
d:DesignWidth="800"
|
||||
mc:Ignorable="d">
|
||||
<StackPanel HorizontalAlignment="Left" Spacing="20">
|
||||
<Button Click="InfoButton_OnClick" Content="Default" />
|
||||
<Button Click="InfoButton_OnClick" Content="Information" />
|
||||
<Button Click="InfoButton_OnClick" Content="Success" />
|
||||
<Button Click="InfoButton_OnClick" Content="Warning" />
|
||||
<Button Click="InfoButton_OnClick" Content="Error" />
|
||||
<StackPanel Spacing="20">
|
||||
<UniformGrid Rows="2" Columns="2" Width="500" HorizontalAlignment="Left">
|
||||
<UniformGrid.Styles>
|
||||
<Style Selector="RadioButton">
|
||||
<Setter Property="Theme" Value="{DynamicResource PureCardRadioButton}" />
|
||||
</Style>
|
||||
</UniformGrid.Styles>
|
||||
<RadioButton Click="PositionButton_OnClick" Content="TopLeft" />
|
||||
<RadioButton Click="PositionButton_OnClick" Content="TopRight" IsChecked="True" />
|
||||
<RadioButton Click="PositionButton_OnClick" Content="BottomLeft" />
|
||||
<RadioButton Click="PositionButton_OnClick" Content="BottomRight" />
|
||||
</UniformGrid>
|
||||
<StackPanel Orientation="Horizontal" Spacing="20">
|
||||
<Button Click="NormalButton_OnClick" Content="Information" />
|
||||
<Button Click="NormalButton_OnClick" Content="Success" Classes="Success" />
|
||||
<Button Click="NormalButton_OnClick" Content="Warning" Classes="Warning" />
|
||||
<Button Click="NormalButton_OnClick" Content="Error" Classes="Danger" />
|
||||
</StackPanel>
|
||||
</StackPanel>
|
||||
</UserControl>
|
@ -22,13 +22,22 @@ public partial class NotificationDemo : UserControl
|
||||
_manager = new WindowNotificationManager(topLevel) { MaxItems = 3 };
|
||||
}
|
||||
|
||||
private void InfoButton_OnClick(object? sender, RoutedEventArgs e)
|
||||
private void NormalButton_OnClick(object? sender, RoutedEventArgs e)
|
||||
{
|
||||
if (sender is Button b && b.Content is string s)
|
||||
{
|
||||
_manager?.Show(Enum.TryParse<NotificationType>(s, out NotificationType t)
|
||||
_manager?.Show(Enum.TryParse<NotificationType>(s, out var t)
|
||||
? new Notification(t.ToString(), "This is message", t)
|
||||
: new Notification(s, "This is message"));
|
||||
}
|
||||
}
|
||||
|
||||
private void PositionButton_OnClick(object? sender, RoutedEventArgs e)
|
||||
{
|
||||
if (sender is RadioButton b && b.Content is string s)
|
||||
{
|
||||
Enum.TryParse<NotificationPosition>(s, out var t);
|
||||
_manager.Position = t;
|
||||
}
|
||||
}
|
||||
}
|
@ -3,65 +3,69 @@
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
x:CompileBindings="True">
|
||||
<Design.PreviewWith>
|
||||
<NotificationCard>
|
||||
<TextBlock Text="Hello World" />
|
||||
</NotificationCard>
|
||||
<ThemeVariantScope RequestedThemeVariant="Dark">
|
||||
<StackPanel>
|
||||
<NotificationCard />
|
||||
<NotificationCard>
|
||||
Hello, Semi.Avalonia!
|
||||
</NotificationCard>
|
||||
</StackPanel>
|
||||
</ThemeVariantScope>
|
||||
</Design.PreviewWith>
|
||||
<ControlTheme x:Key="{x:Type NotificationCard}" TargetType="NotificationCard">
|
||||
<Setter Property="UseLayoutRounding" Value="True" />
|
||||
<Setter Property="MinWidth" Value="{DynamicResource NotificationCardWidth}" />
|
||||
<Setter Property="FontSize" Value="14" />
|
||||
<Setter Property="Foreground" Value="{DynamicResource NotificationCardForeground}" />
|
||||
<Setter Property="RenderTransformOrigin" Value="50%,75%" />
|
||||
<Setter Property="BorderThickness" Value="{DynamicResource NotificationCardBorderThickness}" />
|
||||
<Setter Property="BorderBrush" Value="{DynamicResource NotificationCardBorderBrush}" />
|
||||
<Setter Property="Background" Value="{DynamicResource NotificationCardBackground}" />
|
||||
<Setter Property="CornerRadius" Value="{DynamicResource NotificationCardCornerRadius}" />
|
||||
<Setter Property="Template">
|
||||
<ControlTemplate TargetType="NotificationCard">
|
||||
<LayoutTransformControl Name="PART_LayoutTransformControl" UseRenderTransform="True">
|
||||
<Border
|
||||
Margin="8"
|
||||
BoxShadow="{DynamicResource NotificationCardBoxShadows}"
|
||||
Margin="{DynamicResource NotificationCardMargin}"
|
||||
Background="{TemplateBinding Background}"
|
||||
CornerRadius="{TemplateBinding CornerRadius}">
|
||||
<Border
|
||||
Background="{TemplateBinding Background}"
|
||||
x:Name="PART_RootBorder"
|
||||
Padding="{DynamicResource NotificationCardPadding}"
|
||||
BoxShadow="{DynamicResource NotificationCardBoxShadows}"
|
||||
BorderBrush="{TemplateBinding BorderBrush}"
|
||||
BorderThickness="{TemplateBinding BorderThickness}"
|
||||
ClipToBounds="True"
|
||||
CornerRadius="{TemplateBinding CornerRadius}">
|
||||
<DockPanel>
|
||||
<DockPanel MinWidth="{DynamicResource NotificationCardMinWidth}">
|
||||
<PathIcon
|
||||
Name="NotificationIcon"
|
||||
Width="16"
|
||||
Height="16"
|
||||
Margin="16,16,12,0"
|
||||
Width="{DynamicResource NotificationCardIconWidth}"
|
||||
Height="{DynamicResource NotificationCardIconHeight}"
|
||||
Margin="{DynamicResource NotificationCardIconMargin}"
|
||||
VerticalAlignment="Top"
|
||||
IsVisible="False"
|
||||
Data="{DynamicResource NotificationCardInformationIconPathData}"/>
|
||||
Data="{DynamicResource NotificationCardInformationIconPathData}" />
|
||||
<ContentControl
|
||||
Name="PART_Content"
|
||||
MinHeight="64"
|
||||
Content="{TemplateBinding Content}">
|
||||
<ContentControl.DataTemplates>
|
||||
<DataTemplate DataType="INotification">
|
||||
<StackPanel Margin="0,8,8,8" Spacing="8">
|
||||
<TextBlock
|
||||
FontSize="16"
|
||||
FontWeight="600"
|
||||
<StackPanel Spacing="{DynamicResource NotificationCardTitleSpacing}">
|
||||
<SelectableTextBlock
|
||||
Foreground="{DynamicResource NotificationCardTitleForeground}"
|
||||
FontSize="{DynamicResource NotificationCardTitleFontSize}"
|
||||
FontWeight="{DynamicResource NotificationCardTitleFontWeight}"
|
||||
IsVisible="{Binding Title, Converter={x:Static StringConverters.IsNotNullOrEmpty}}"
|
||||
Text="{Binding Title}" />
|
||||
<TextBlock
|
||||
MaxHeight="80"
|
||||
Margin="0,0,8,0"
|
||||
FontSize="14"
|
||||
FontWeight="400"
|
||||
<SelectableTextBlock
|
||||
Foreground="{DynamicResource NotificationCardMessageForeground}"
|
||||
FontSize="{DynamicResource NotificationCardMessageFontSize}"
|
||||
FontWeight="{DynamicResource NotificationCardMessageFontWeight}"
|
||||
IsVisible="{Binding Message, Converter={x:Static StringConverters.IsNotNullOrEmpty}}"
|
||||
Text="{Binding Message}"
|
||||
TextWrapping="Wrap" />
|
||||
</StackPanel>
|
||||
</DataTemplate>
|
||||
<DataTemplate DataType="x:String">
|
||||
<TextBlock
|
||||
Margin="12"
|
||||
<SelectableTextBlock
|
||||
Foreground="{DynamicResource NotificationCardMessageForeground}"
|
||||
FontSize="{DynamicResource NotificationCardMessageFontSize}"
|
||||
FontWeight="{DynamicResource NotificationCardMessageFontWeight}"
|
||||
Text="{Binding}"
|
||||
TextWrapping="Wrap" />
|
||||
</DataTemplate>
|
||||
|
@ -1,10 +1,11 @@
|
||||
<ResourceDictionary xmlns="https://github.com/avaloniaui" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
|
||||
<SolidColorBrush x:Key="NotificationCardForeground" Color="#F9F9F9" />
|
||||
<SolidColorBrush x:Key="NotificationCardBorderBrush" Opacity="0.08" Color="White" />
|
||||
<SolidColorBrush x:Key="NotificationCardBackground" Color="#43444A" />
|
||||
<SolidColorBrush x:Key="NotificationCardInformationIconForeground" Color="#54A9FF" />
|
||||
<SolidColorBrush x:Key="NotificationCardSuccessIconForeground" Color="#5DC264" />
|
||||
<SolidColorBrush x:Key="NotificationCardWarningIconForeground" Color="#FFAE43" />
|
||||
<SolidColorBrush x:Key="NotificationCardErrorIconForeground" Color="#FC725A" />
|
||||
<BoxShadows x:Key="NotificationCardBoxShadows">0 0 8 0 #1AFFFFFF</BoxShadows>
|
||||
<BoxShadows x:Key="NotificationCardBoxShadows">inset 0 0 0 1 #1AFFFFFF, 0 4 14 0 #40000000</BoxShadows>
|
||||
<SolidColorBrush x:Key="NotificationCardTitleForeground" Color="#F9F9F9" />
|
||||
<SolidColorBrush x:Key="NotificationCardMessageForeground" Opacity="0.8" Color="#F9F9F9" />
|
||||
</ResourceDictionary>
|
@ -1,10 +1,11 @@
|
||||
<ResourceDictionary xmlns="https://github.com/avaloniaui" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
|
||||
<SolidColorBrush x:Key="NotificationCardForeground" Color="#1C1F23" />
|
||||
<SolidColorBrush x:Key="NotificationCardBorderBrush" Opacity="0.08" Color="#1C1F23" />
|
||||
<SolidColorBrush x:Key="NotificationCardBackground" Color="White" />
|
||||
<SolidColorBrush x:Key="NotificationCardInformationIconForeground" Color="#0077FA" />
|
||||
<SolidColorBrush x:Key="NotificationCardSuccessIconForeground" Color="#3BB346" />
|
||||
<SolidColorBrush x:Key="NotificationCardWarningIconForeground" Color="#FC8800" />
|
||||
<SolidColorBrush x:Key="NotificationCardErrorIconForeground" Color="#F93920" />
|
||||
<BoxShadows x:Key="NotificationCardBoxShadows">0 0 8 0 #1A000000</BoxShadows>
|
||||
<BoxShadows x:Key="NotificationCardBoxShadows">0 0 1 0 #4A000000, 0 4 14 0 #1A000000</BoxShadows>
|
||||
<SolidColorBrush x:Key="NotificationCardTitleForeground" Color="#1C1F23" />
|
||||
<SolidColorBrush x:Key="NotificationCardMessageForeground" Opacity="0.8" Color="#1C1F23" />
|
||||
</ResourceDictionary>
|
@ -1,9 +1,22 @@
|
||||
<ResourceDictionary xmlns="https://github.com/avaloniaui" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
|
||||
<x:Double x:Key="NotificationCardWidth">320</x:Double>
|
||||
<x:Double x:Key="NotificationCardMinWidth">320</x:Double>
|
||||
<Thickness x:Key="NotificationCardBorderThickness">1</Thickness>
|
||||
<CornerRadius x:Key="NotificationCardCornerRadius">6</CornerRadius>
|
||||
<Geometry x:Key="NotificationCardInformationIconPathData">M12 23C18.0751 23 23 18.0751 23 12C23 5.92487 18.0751 1 12 1C5.92487 1 1 5.92487 1 12C1 18.0751 5.92487 23 12 23ZM14 7C14 8.10457 13.1046 9 12 9C10.8954 9 10 8.10457 10 7C10 5.89543 10.8954 5 12 5C13.1046 5 14 5.89543 14 7ZM9 10.75C9 10.3358 9.33579 10 9.75 10H12.5C13.0523 10 13.5 10.4477 13.5 11V16.5H14.25C14.6642 16.5 15 16.8358 15 17.25C15 17.6642 14.6642 18 14.25 18H9.75C9.33579 18 9 17.6642 9 17.25C9 16.8358 9.33579 16.5 9.75 16.5H10.5V11.5H9.75C9.33579 11.5 9 11.1642 9 10.75Z</Geometry>
|
||||
<Geometry x:Key="NotificationCardSuccessIconPathData">M12 23C18.0751 23 23 18.0751 23 12C23 5.92487 18.0751 1 12 1C5.92487 1 1 5.92487 1 12C1 18.0751 5.92487 23 12 23ZM17.8831 9.82235L11.6854 17.4112C11.4029 17.7806 10.965 17.9981 10.5 18C10.035 18.0019 9.59533 17.788 9.30982 17.421L5.81604 13.4209C5.30744 12.767 5.42524 11.8246 6.07916 11.316C6.73308 10.8074 7.67549 10.9252 8.1841 11.5791L10.4838 14.0439L15.5 8C16.0032 7.34193 16.9446 7.21641 17.6027 7.71964C18.2608 8.22287 18.3863 9.16428 17.8831 9.82235Z</Geometry>
|
||||
<Geometry x:Key="NotificationCardWarningIconPathData">M10.2268 2.3986L1.52616 19.0749C0.831449 20.4064 1.79747 22 3.29933 22H20.7007C22.2025 22 23.1686 20.4064 22.4739 19.0749L13.7732 2.3986C13.0254 0.965441 10.9746 0.965442 10.2268 2.3986ZM13.1415 14.0101C13.0603 14.5781 12.5739 15 12.0001 15C11.4263 15 10.9398 14.5781 10.8586 14.0101L10.2829 9.97992C10.1336 8.93495 10.9445 8.00002 12.0001 8.00002C13.0556 8.00002 13.8665 8.93495 13.7172 9.97992L13.1415 14.0101ZM13.5001 18.5C13.5001 19.3284 12.8285 20 12.0001 20C11.1716 20 10.5001 19.3284 10.5001 18.5C10.5001 17.6716 11.1716 17 12.0001 17C12.8285 17 13.5001 17.6716 13.5001 18.5Z</Geometry>
|
||||
<Geometry x:Key="NotificationCardErrorIconPathData">M23 12C23 18.0751 18.0751 23 12 23C5.92487 23 1 18.0751 1 12C1 5.92487 5.92487 1 12 1C18.0751 1 23 5.92487 23 12ZM13.5 17.5C13.5 16.6716 12.8284 16 12 16C11.1716 16 10.5 16.6716 10.5 17.5C10.5 18.3284 11.1716 19 12 19C12.8284 19 13.5 18.3284 13.5 17.5ZM12 5C10.9138 5 10.0507 5.91244 10.1109 6.99692L10.4168 12.5023C10.4635 13.3426 11.1584 14 12 14C12.8416 14 13.5365 13.3426 13.5832 12.5023L13.8891 6.99692C13.9493 5.91244 13.0862 5 12 5Z</Geometry>
|
||||
<Thickness x:Key="NotificationCardMargin">8</Thickness>
|
||||
<Thickness x:Key="NotificationCardPadding">20 16 12 16</Thickness>
|
||||
|
||||
<x:Double x:Key="NotificationCardIconWidth">18</x:Double>
|
||||
<x:Double x:Key="NotificationCardIconHeight">18</x:Double>
|
||||
<Thickness x:Key="NotificationCardIconMargin">0 0 12 0</Thickness>
|
||||
<StreamGeometry x:Key="NotificationCardInformationIconPathData">M12 23C18.0751 23 23 18.0751 23 12C23 5.92487 18.0751 1 12 1C5.92487 1 1 5.92487 1 12C1 18.0751 5.92487 23 12 23ZM14 7C14 8.10457 13.1046 9 12 9C10.8954 9 10 8.10457 10 7C10 5.89543 10.8954 5 12 5C13.1046 5 14 5.89543 14 7ZM9 10.75C9 10.3358 9.33579 10 9.75 10H12.5C13.0523 10 13.5 10.4477 13.5 11V16.5H14.25C14.6642 16.5 15 16.8358 15 17.25C15 17.6642 14.6642 18 14.25 18H9.75C9.33579 18 9 17.6642 9 17.25C9 16.8358 9.33579 16.5 9.75 16.5H10.5V11.5H9.75C9.33579 11.5 9 11.1642 9 10.75Z</StreamGeometry>
|
||||
<StreamGeometry x:Key="NotificationCardSuccessIconPathData">M12 23C18.0751 23 23 18.0751 23 12C23 5.92487 18.0751 1 12 1C5.92487 1 1 5.92487 1 12C1 18.0751 5.92487 23 12 23ZM17.8831 9.82235L11.6854 17.4112C11.4029 17.7806 10.965 17.9981 10.5 18C10.035 18.0019 9.59533 17.788 9.30982 17.421L5.81604 13.4209C5.30744 12.767 5.42524 11.8246 6.07916 11.316C6.73308 10.8074 7.67549 10.9252 8.1841 11.5791L10.4838 14.0439L15.5 8C16.0032 7.34193 16.9446 7.21641 17.6027 7.71964C18.2608 8.22287 18.3863 9.16428 17.8831 9.82235Z</StreamGeometry>
|
||||
<StreamGeometry x:Key="NotificationCardWarningIconPathData">M10.2268 2.3986L1.52616 19.0749C0.831449 20.4064 1.79747 22 3.29933 22H20.7007C22.2025 22 23.1686 20.4064 22.4739 19.0749L13.7732 2.3986C13.0254 0.965441 10.9746 0.965442 10.2268 2.3986ZM13.1415 14.0101C13.0603 14.5781 12.5739 15 12.0001 15C11.4263 15 10.9398 14.5781 10.8586 14.0101L10.2829 9.97992C10.1336 8.93495 10.9445 8.00002 12.0001 8.00002C13.0556 8.00002 13.8665 8.93495 13.7172 9.97992L13.1415 14.0101ZM13.5001 18.5C13.5001 19.3284 12.8285 20 12.0001 20C11.1716 20 10.5001 19.3284 10.5001 18.5C10.5001 17.6716 11.1716 17 12.0001 17C12.8285 17 13.5001 17.6716 13.5001 18.5Z</StreamGeometry>
|
||||
<StreamGeometry x:Key="NotificationCardErrorIconPathData">M23 12C23 18.0751 18.0751 23 12 23C5.92487 23 1 18.0751 1 12C1 5.92487 5.92487 1 12 1C18.0751 1 23 5.92487 23 12ZM13.5 17.5C13.5 16.6716 12.8284 16 12 16C11.1716 16 10.5 16.6716 10.5 17.5C10.5 18.3284 11.1716 19 12 19C12.8284 19 13.5 18.3284 13.5 17.5ZM12 5C10.9138 5 10.0507 5.91244 10.1109 6.99692L10.4168 12.5023C10.4635 13.3426 11.1584 14 12 14C12.8416 14 13.5365 13.3426 13.5832 12.5023L13.8891 6.99692C13.9493 5.91244 13.0862 5 12 5Z</StreamGeometry>
|
||||
|
||||
<x:Double x:Key="NotificationCardTitleSpacing">4</x:Double>
|
||||
|
||||
<x:Double x:Key="NotificationCardTitleFontSize">16</x:Double>
|
||||
<FontWeight x:Key="NotificationCardTitleFontWeight">600</FontWeight>
|
||||
<x:Double x:Key="NotificationCardMessageFontSize">14</x:Double>
|
||||
<FontWeight x:Key="NotificationCardMessageFontWeight">400</FontWeight>
|
||||
</ResourceDictionary>
|
Loading…
x
Reference in New Issue
Block a user