feat: add Light class to NotificationCard.

This commit is contained in:
Zhang Dian 2024-08-14 20:00:43 +08:00
parent 38b9494aaf
commit a328e2bb99
4 changed files with 117 additions and 55 deletions

View File

@ -9,6 +9,7 @@
mc:Ignorable="d"> mc:Ignorable="d">
<StackPanel Spacing="20"> <StackPanel Spacing="20">
<StackPanel> <StackPanel>
<Slider Name="SliderTest" Maximum="400" Minimum="0" TickFrequency="1" IsSnapToTickEnabled="True" />
<Expander Header="Expander 1"> <Expander Header="Expander 1">
<TextBlock Text="Hello Avalonia!" /> <TextBlock Text="Hello Avalonia!" />
</Expander> </Expander>
@ -36,4 +37,4 @@
</Expander> </Expander>
</Grid> </Grid>
</StackPanel> </StackPanel>
</UserControl> </UserControl>

View File

@ -7,18 +7,33 @@
d:DesignHeight="450" d:DesignHeight="450"
d:DesignWidth="800" d:DesignWidth="800"
mc:Ignorable="d"> mc:Ignorable="d">
<StackPanel HorizontalAlignment="Left" Spacing="20"> <StackPanel Spacing="20">
<StackPanel.Styles> <StackPanel Orientation="Horizontal" Spacing="20">
<Style Selector="Button"> <Button Click="NormalButton_OnClick" Content="Information" />
<Setter Property="Theme" Value="{DynamicResource SolidButton}" /> <Button Click="NormalButton_OnClick" Content="Success" Classes="Success" />
<Setter Property="HorizontalAlignment" Value="Stretch" /> <Button Click="NormalButton_OnClick" Content="Warning" Classes="Warning" />
</Style> <Button Click="NormalButton_OnClick" Content="Error" Classes="Danger" />
</StackPanel.Styles> </StackPanel>
<StackPanel Orientation="Horizontal">
<Button Click="InfoButton_OnClick" Content="Default" /> <Button Click="PositionButton_OnClick" Content="TopLeft" />
<Button Click="InfoButton_OnClick" Content="Information" /> <Button Click="PositionButton_OnClick" Content="TopCenter" />
<Button Click="InfoButton_OnClick" Content="Success" Classes="Success" /> <Button Click="PositionButton_OnClick" Content="TopRight" />
<Button Click="InfoButton_OnClick" Content="Warning" Classes="Warning" /> </StackPanel>
<Button Click="InfoButton_OnClick" Content="Error" Classes="Danger" /> <StackPanel Orientation="Horizontal">
<Button Click="PositionButton_OnClick" Content="BottomLeft" />
<Button Click="PositionButton_OnClick" Content="BottomCenter" />
<Button Click="PositionButton_OnClick" Content="BottomRight" />
</StackPanel>
<StackPanel Orientation="Horizontal" Spacing="20">
<StackPanel.Styles>
<Style Selector="Button">
<Setter Property="Theme" Value="{DynamicResource SolidButton}" />
</Style>
</StackPanel.Styles>
<Button Click="LightButton_OnClick" Content="Information" />
<Button Click="LightButton_OnClick" Content="Success" Classes="Success" />
<Button Click="LightButton_OnClick" Content="Warning" Classes="Warning" />
<Button Click="LightButton_OnClick" Content="Error" Classes="Danger" />
</StackPanel>
</StackPanel> </StackPanel>
</UserControl> </UserControl>

View File

@ -22,13 +22,35 @@ public partial class NotificationDemo : UserControl
_manager = new WindowNotificationManager(topLevel) { MaxItems = 3 }; _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) 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(t.ToString(), "This is message", t)
: new Notification(s, "This is message")); : new Notification(s, "This is message"));
} }
} }
private void PositionButton_OnClick(object? sender, RoutedEventArgs e)
{
if (sender is Button b && b.Content is string s)
{
Enum.TryParse<NotificationPosition>(s, out var t);
_manager.Position = t;
_manager?.Show(new Notification(t.ToString(), "This is message"));
}
}
private void LightButton_OnClick(object? sender, RoutedEventArgs e)
{
if (sender is Button b && b.Content is string s)
{
Enum.TryParse<NotificationType>(s, out var notificationType);
_manager?.Show(
new Notification(notificationType.ToString(), "This is message"),
type: notificationType,
classes: ["Light"]);
}
}
} }

View File

@ -33,52 +33,56 @@
<LayoutTransformControl Name="PART_LayoutTransformControl" UseRenderTransform="True"> <LayoutTransformControl Name="PART_LayoutTransformControl" UseRenderTransform="True">
<Border <Border
Margin="{DynamicResource NotificationCardMargin}" Margin="{DynamicResource NotificationCardMargin}"
Padding="{DynamicResource NotificationCardPadding}"
BoxShadow="{DynamicResource NotificationCardBoxShadows}"
Background="{TemplateBinding Background}" Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
CornerRadius="{TemplateBinding CornerRadius}"> CornerRadius="{TemplateBinding CornerRadius}">
<DockPanel> <Border
<PathIcon x:Name="PART_RootBorder"
Name="NotificationIcon" Padding="{DynamicResource NotificationCardPadding}"
Width="{DynamicResource NotificationCardIconWidth}" BoxShadow="{DynamicResource NotificationCardBoxShadow}"
Height="{DynamicResource NotificationCardIconHeight}" BorderBrush="{TemplateBinding BorderBrush}"
Margin="{DynamicResource NotificationCardIconMargin}" BorderThickness="{TemplateBinding BorderThickness}"
VerticalAlignment="Top" CornerRadius="{TemplateBinding CornerRadius}">
IsVisible="False" <DockPanel>
Data="{DynamicResource NotificationCardInformationIconPathData}" /> <PathIcon
<ContentControl Name="NotificationIcon"
Name="PART_Content" Width="{DynamicResource NotificationCardIconWidth}"
Content="{TemplateBinding Content}"> Height="{DynamicResource NotificationCardIconHeight}"
<ContentControl.DataTemplates> Margin="{DynamicResource NotificationCardIconMargin}"
<DataTemplate DataType="INotification"> VerticalAlignment="Top"
<StackPanel Spacing="{DynamicResource NotificationCardTitleSpacing}"> IsVisible="False"
<SelectableTextBlock Data="{DynamicResource NotificationCardInformationIconPathData}" />
Foreground="{DynamicResource NotificationCardTitleForeground}" <ContentControl
FontSize="{DynamicResource NotificationCardTitleFontSize}" Name="PART_Content"
FontWeight="{DynamicResource NotificationCardTitleFontWeight}" Content="{TemplateBinding Content}">
IsVisible="{Binding Title, Converter={x:Static StringConverters.IsNotNullOrEmpty}}" <ContentControl.DataTemplates>
Text="{Binding Title}" /> <DataTemplate DataType="INotification">
<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}" />
<SelectableTextBlock
Foreground="{DynamicResource NotificationCardMessageForeground}"
FontSize="{DynamicResource NotificationCardMessageFontSize}"
FontWeight="{DynamicResource NotificationCardMessageFontWeight}"
Text="{Binding Message}"
TextWrapping="Wrap" />
</StackPanel>
</DataTemplate>
<DataTemplate DataType="x:String">
<SelectableTextBlock <SelectableTextBlock
Foreground="{DynamicResource NotificationCardMessageForeground}" Foreground="{DynamicResource NotificationCardMessageForeground}"
FontSize="{DynamicResource NotificationCardMessageFontSize}" FontSize="{DynamicResource NotificationCardMessageFontSize}"
FontWeight="{DynamicResource NotificationCardMessageFontWeight}" FontWeight="{DynamicResource NotificationCardMessageFontWeight}"
Text="{Binding Message}" Text="{Binding}"
TextWrapping="Wrap" /> TextWrapping="Wrap" />
</StackPanel> </DataTemplate>
</DataTemplate> </ContentControl.DataTemplates>
<DataTemplate DataType="x:String"> </ContentControl>
<SelectableTextBlock </DockPanel>
Foreground="{DynamicResource NotificationCardMessageForeground}" </Border>
FontSize="{DynamicResource NotificationCardMessageFontSize}"
FontWeight="{DynamicResource NotificationCardMessageFontWeight}"
Text="{Binding}"
TextWrapping="Wrap" />
</DataTemplate>
</ContentControl.DataTemplates>
</ContentControl>
</DockPanel>
</Border> </Border>
</LayoutTransformControl> </LayoutTransformControl>
</ControlTemplate> </ControlTemplate>
@ -163,5 +167,25 @@
<Setter Property="Foreground" Value="{DynamicResource NotificationCardErrorIconForeground}" /> <Setter Property="Foreground" Value="{DynamicResource NotificationCardErrorIconForeground}" />
<Setter Property="Data" Value="{DynamicResource NotificationCardErrorIconPathData}" /> <Setter Property="Data" Value="{DynamicResource NotificationCardErrorIconPathData}" />
</Style> </Style>
<Style Selector="^.Light">
<Setter Property="Background" Value="{DynamicResource SemiColorBackground0}" />
<Style Selector="^:information /template/ Border#PART_RootBorder">
<Setter Property="BorderBrush" Value="{DynamicResource SemiColorInformation}" />
<Setter Property="Background" Value="{DynamicResource SemiColorInformationLight}" />
</Style>
<Style Selector="^:success /template/ Border#PART_RootBorder">
<Setter Property="BorderBrush" Value="{DynamicResource SemiColorSuccess}" />
<Setter Property="Background" Value="{DynamicResource SemiColorSuccessLight}" />
</Style>
<Style Selector="^:warning /template/ Border#PART_RootBorder">
<Setter Property="BorderBrush" Value="{DynamicResource SemiColorWarning}" />
<Setter Property="Background" Value="{DynamicResource SemiColorWarningLight}" />
</Style>
<Style Selector="^:error /template/ Border#PART_RootBorder">
<Setter Property="BorderBrush" Value="{DynamicResource SemiColorDanger}" />
<Setter Property="Background" Value="{DynamicResource SemiColorDangerLight}" />
</Style>
</Style>
</ControlTheme> </ControlTheme>
</ResourceDictionary> </ResourceDictionary>