feat: initial DualBadge.

This commit is contained in:
Zhang Dian
2023-07-26 10:20:13 +08:00
parent cde1caabd4
commit 82312e7477
15 changed files with 152 additions and 0 deletions

View File

@@ -0,0 +1,45 @@
<ResourceDictionary
xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:u="https://irihi.tech/ursa">
<ControlTheme x:Key="{x:Type u:DualBadge}" TargetType="{x:Type u:DualBadge}">
<Setter Property="u:DualBadge.HorizontalAlignment" Value="Center" />
<Setter Property="u:DualBadge.VerticalAlignment" Value="Top" />
<Setter Property="u:DualBadge.CornerRadius" Value="16" />
<Setter Property="u:DualBadge.HeaderBackground" Value="{DynamicResource DualBadgeDefaultHeaderBackground}" />
<Setter Property="u:DualBadge.Margin" Value="0 4" />
<Setter Property="u:DualBadge.Template">
<ControlTemplate TargetType="{x:Type u:DualBadge}">
<Border
HorizontalAlignment="{TemplateBinding u:DualBadge.HorizontalAlignment}"
VerticalAlignment="{TemplateBinding u:DualBadge.VerticalAlignment}"
BorderThickness="{TemplateBinding u:DualBadge.BorderThickness}"
CornerRadius="{TemplateBinding u:DualBadge.CornerRadius}">
<Grid ColumnDefinitions="*,*,*">
<ContentPresenter
Name="{x:Static u:DualBadge.PART_Icon}"
Grid.Column="0"
Margin="{TemplateBinding Padding}"
Background="{TemplateBinding HeaderBackground}"
Content="{TemplateBinding Icon}"
ContentTemplate="{TemplateBinding IconTemplate}"/>
<ContentPresenter
Name="{x:Static u:DualBadge.PART_HeaderPresenter}"
Grid.Column="1"
Margin="{TemplateBinding Padding}"
Background="{TemplateBinding HeaderBackground}"
Content="{TemplateBinding Header}"
ContentTemplate="{TemplateBinding HeaderTemplate}" />
<ContentPresenter
Name="{x:Static u:DualBadge.PART_ContentPresenter}"
Grid.Column="2"
Margin="{TemplateBinding Padding}"
Background="{TemplateBinding Background}"
Content="{TemplateBinding Content}"
ContentTemplate="{TemplateBinding ContentTemplate}" />
</Grid>
</Border>
</ControlTemplate>
</Setter>
</ControlTheme>
</ResourceDictionary>

View File

@@ -5,6 +5,7 @@
<ResourceInclude Source="Banner.axaml" />
<ResourceInclude Source="ButtonGroup.axaml" />
<ResourceInclude Source="Divider.axaml" />
<ResourceInclude Source="DualBadge.axaml" />
<ResourceInclude Source="IPv4Box.axaml" />
<ResourceInclude Source="Loading.axaml" />
<ResourceInclude Source="Navigation.axaml" />

View File

@@ -0,0 +1,3 @@
<ResourceDictionary xmlns="https://github.com/avaloniaui" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<SolidColorBrush x:Key="DualBadgeDefaultHeaderBackground">LightGray</SolidColorBrush>
</ResourceDictionary>

View File

@@ -5,6 +5,7 @@
<MergeResourceInclude Source="Banner.axaml" />
<MergeResourceInclude Source="ButtonGroup.axaml" />
<MergeResourceInclude Source="Divider.axaml" />
<MergeResourceInclude Source="DualBadge.axaml" />
<MergeResourceInclude Source="IPv4Box.axaml" />
<MergeResourceInclude Source="Loading.axaml" />
<MergeResourceInclude Source="NavigationMenu.axaml" />

View File

@@ -0,0 +1,3 @@
<ResourceDictionary xmlns="https://github.com/avaloniaui" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<SolidColorBrush x:Key="DualBadgeDefaultHeaderBackground">LightGray</SolidColorBrush>
</ResourceDictionary>

View File

@@ -5,6 +5,7 @@
<MergeResourceInclude Source="Banner.axaml" />
<MergeResourceInclude Source="ButtonGroup.axaml" />
<MergeResourceInclude Source="Divider.axaml" />
<MergeResourceInclude Source="DualBadge.axaml" />
<MergeResourceInclude Source="IPv4Box.axaml" />
<MergeResourceInclude Source="Loading.axaml" />
<MergeResourceInclude Source="NavigationMenu.axaml" />

View File

@@ -0,0 +1,2 @@
<ResourceDictionary xmlns="https://github.com/avaloniaui" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
</ResourceDictionary>

View File

@@ -5,6 +5,7 @@
<MergeResourceInclude Source="Banner.axaml" />
<MergeResourceInclude Source="ButtonGroup.axaml" />
<MergeResourceInclude Source="Divider.axaml" />
<MergeResourceInclude Source="DualBadge.axaml" />
<MergeResourceInclude Source="IPv4Box.axaml" />
<MergeResourceInclude Source="NavigationMenu.axaml" />
<MergeResourceInclude Source="Pagination.axaml" />

View File

@@ -0,0 +1,53 @@
using Avalonia;
using Avalonia.Controls.Metadata;
using Avalonia.Controls.Presenters;
using Avalonia.Controls.Primitives;
using Avalonia.Controls.Templates;
using Avalonia.Media;
namespace Ursa.Controls;
[TemplatePart(PART_Icon, typeof(ContentPresenter))]
public class DualBadge : HeaderedContentControl
{
public const string PART_HeaderPresenter = "PART_HeaderPresenter";
public const string PART_ContentPresenter = "PART_ContentPresenter";
public const string PART_Icon = "PART_Icon";
public static readonly StyledProperty<object?> IconProperty =
AvaloniaProperty.Register<DualBadge, object?>(nameof(Icon));
public object? Icon
{
get => GetValue(IconProperty);
set => SetValue(IconProperty, value);
}
public static readonly StyledProperty<IDataTemplate?> IconTemplateProperty =
AvaloniaProperty.Register<DualBadge, IDataTemplate?>(nameof(IconTemplate));
public IDataTemplate? IconTemplate
{
get => GetValue(IconTemplateProperty);
set => SetValue(IconTemplateProperty, value);
}
public static readonly StyledProperty<IBrush?> HeaderForegroundProperty =
AvaloniaProperty.Register<DualBadge, IBrush?>(nameof(HeaderForeground));
public IBrush? HeaderForeground
{
get => GetValue(HeaderForegroundProperty);
set => SetValue(HeaderForegroundProperty, value);
}
public static readonly StyledProperty<IBrush?> HeaderBackgroundProperty =
AvaloniaProperty.Register<DualBadge, IBrush?>(nameof(HeaderBackground));
public IBrush? HeaderBackground
{
get => GetValue(HeaderBackgroundProperty);
set => SetValue(HeaderBackgroundProperty, value);
}
}