feat: DualBadge CornerRadius.

This commit is contained in:
Zhang Dian
2023-07-27 10:22:50 +08:00
parent f429d8219c
commit c5589b3db3
3 changed files with 87 additions and 28 deletions

View File

@@ -1,4 +1,5 @@
using Avalonia;
using Avalonia.Controls;
using Avalonia.Controls.Metadata;
using Avalonia.Controls.Presenters;
using Avalonia.Controls.Primitives;
@@ -7,9 +8,13 @@ using Avalonia.Media;
namespace Ursa.Controls;
[PseudoClasses(PC_IconEmpty, PC_HeaderEmpty, PC_ContentEmpty)]
[TemplatePart(PART_Icon, typeof(ContentPresenter))]
public class DualBadge : HeaderedContentControl
{
public const string PC_IconEmpty = ":icon-empty";
public const string PC_HeaderEmpty = ":header-empty";
public const string PC_ContentEmpty = ":content-empty";
public const string PART_HeaderPresenter = "PART_HeaderPresenter";
public const string PART_ContentPresenter = "PART_ContentPresenter";
public const string PART_Icon = "PART_Icon";
@@ -58,4 +63,57 @@ public class DualBadge : HeaderedContentControl
get => GetValue(HeaderBackgroundProperty);
set => SetValue(HeaderBackgroundProperty, value);
}
public static readonly StyledProperty<bool> IsIconEmptyProperty = AvaloniaProperty.Register<DualBadge, bool>(
nameof(IsIconEmpty));
public bool IsIconEmpty
{
get => GetValue(IsIconEmptyProperty);
set => SetValue(IsIconEmptyProperty, value);
}
public static readonly StyledProperty<bool> IsHeaderEmptyProperty = AvaloniaProperty.Register<DualBadge, bool>(
nameof(IsHeaderEmpty));
public bool IsHeaderEmpty
{
get => GetValue(IsHeaderEmptyProperty);
set => SetValue(IsHeaderEmptyProperty, value);
}
public static readonly StyledProperty<bool> IsContentEmptyProperty = AvaloniaProperty.Register<DualBadge, bool>(
nameof(IsContentEmpty));
public bool IsContentEmpty
{
get => GetValue(IsContentEmptyProperty);
set => SetValue(IsContentEmptyProperty, value);
}
static DualBadge()
{
IsIconEmptyProperty.Changed.AddClassHandler<DualBadge>((o, e) => o.OnIsIconEmptyChanged(e));
IsHeaderEmptyProperty.Changed.AddClassHandler<DualBadge>((o, e) => o.OnIsHeaderEmptyChanged(e));
IsContentEmptyProperty.Changed.AddClassHandler<DualBadge>((o, e) => o.OnIsContentEmptyChanged(e));
}
private void OnIsIconEmptyChanged(AvaloniaPropertyChangedEventArgs args)
{
bool newValue = args.GetNewValue<bool>();
PseudoClasses.Set(PC_IconEmpty, newValue);
}
private void OnIsHeaderEmptyChanged(AvaloniaPropertyChangedEventArgs args)
{
bool newValue = args.GetNewValue<bool>();
PseudoClasses.Set(PC_HeaderEmpty, newValue);
}
private void OnIsContentEmptyChanged(AvaloniaPropertyChangedEventArgs args)
{
bool newValue = args.GetNewValue<bool>();
PseudoClasses.Set(PC_ContentEmpty, newValue);
}
}