diff --git a/demo/Ursa.Demo/Pages/BadgeDemo.axaml b/demo/Ursa.Demo/Pages/BadgeDemo.axaml index 642cefa..5d2f3d0 100644 --- a/demo/Ursa.Demo/Pages/BadgeDemo.axaml +++ b/demo/Ursa.Demo/Pages/BadgeDemo.axaml @@ -8,126 +8,254 @@ d:DesignHeight="450" d:DesignWidth="800" mc:Ignorable="d"> - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + \ No newline at end of file diff --git a/src/Ursa.Themes.Semi/Controls/Badge.axaml b/src/Ursa.Themes.Semi/Controls/Badge.axaml index fdb21ed..4402f05 100644 --- a/src/Ursa.Themes.Semi/Controls/Badge.axaml +++ b/src/Ursa.Themes.Semi/Controls/Badge.axaml @@ -9,22 +9,23 @@ - - - - - - - - - - + + + + + + + + + + + + - + TextElement.FontSize="{TemplateBinding BadgeFontSize}" + TextElement.Foreground="{TemplateBinding Foreground}"> - + @@ -83,7 +84,7 @@ ContentTemplate="{TemplateBinding ContentTemplate}" /> @@ -130,5 +131,56 @@ + + + + + + + + + + + + + + + + - + \ No newline at end of file diff --git a/src/Ursa.Themes.Semi/Themes/Dark/Badge.axaml b/src/Ursa.Themes.Semi/Themes/Dark/Badge.axaml index b92979b..6d97358 100644 --- a/src/Ursa.Themes.Semi/Themes/Dark/Badge.axaml +++ b/src/Ursa.Themes.Semi/Themes/Dark/Badge.axaml @@ -1,10 +1,33 @@ - - - + + + - + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/Ursa.Themes.Semi/Themes/Light/Badge.axaml b/src/Ursa.Themes.Semi/Themes/Light/Badge.axaml index 36e14da..6128269 100644 --- a/src/Ursa.Themes.Semi/Themes/Light/Badge.axaml +++ b/src/Ursa.Themes.Semi/Themes/Light/Badge.axaml @@ -1,10 +1,33 @@ - - + + - + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/Ursa.Themes.Semi/Themes/Shared/Badge.axaml b/src/Ursa.Themes.Semi/Themes/Shared/Badge.axaml index 688be66..7c39786 100644 --- a/src/Ursa.Themes.Semi/Themes/Shared/Badge.axaml +++ b/src/Ursa.Themes.Semi/Themes/Shared/Badge.axaml @@ -1,8 +1,14 @@ - - - 18 + + 18 + 18 + 8 8 6,0 1 - 8 - + 10 + 100 + TopRight + \ No newline at end of file diff --git a/src/Ursa/Controls/Badge.cs b/src/Ursa/Controls/Badge.cs index 9956352..23124ed 100644 --- a/src/Ursa/Controls/Badge.cs +++ b/src/Ursa/Controls/Badge.cs @@ -1,7 +1,6 @@ using Avalonia; using Avalonia.Controls; using Avalonia.Controls.Metadata; -using Avalonia.Controls.Presenters; using Avalonia.Controls.Primitives; using Avalonia.Interactivity; using Avalonia.Media; @@ -10,18 +9,14 @@ using Ursa.Common; namespace Ursa.Controls; -[TemplatePart(PART_ContentPresenter, typeof(ContentPresenter))] [TemplatePart(PART_BadgeContainer, typeof(Border))] -[TemplatePart(PART_BadgeContentPresenter, typeof(ContentPresenter))] -public class Badge: ContentControl +public class Badge: HeaderedContentControl { public const string PART_ContentPresenter = "PART_ContentPresenter"; public const string PART_BadgeContainer = "PART_BadgeContainer"; - public const string PART_BadgeContentPresenter = "PART_BadgeContentPresenter"; - - private ContentPresenter? _content; + public const string PART_HeaderPresenter = "PART_HeaderPresenter"; + private Border? _badgeContainer; - private ContentPresenter? _badgeContent; public static readonly StyledProperty BadgeThemeProperty = AvaloniaProperty.Register( nameof(BadgeTheme)); @@ -39,14 +34,6 @@ public class Badge: ContentControl set => SetValue(DotProperty, value); } - public static readonly StyledProperty BadgeContentProperty = AvaloniaProperty.Register( - nameof(BadgeContent)); - public object? BadgeContent - { - get => GetValue(BadgeContentProperty); - set => SetValue(BadgeContentProperty, value); - } - public static readonly StyledProperty CornerPositionProperty = AvaloniaProperty.Register( nameof(CornerPosition)); public CornerPosition CornerPosition @@ -63,17 +50,24 @@ public class Badge: ContentControl set => SetValue(OverflowCountProperty, value); } + public static readonly StyledProperty BadgeFontSizeProperty = AvaloniaProperty.Register( + nameof(BadgeFontSize)); + + public double BadgeFontSize + { + get => GetValue(BadgeFontSizeProperty); + set => SetValue(BadgeFontSizeProperty, value); + } + static Badge() { - BadgeContentProperty.Changed.AddClassHandler((badge, args) => badge.UpdateBadgePosition()); + HeaderProperty.Changed.AddClassHandler((badge, args) => badge.UpdateBadgePosition()); } protected override void OnApplyTemplate(TemplateAppliedEventArgs e) { base.OnApplyTemplate(e); - _content = e.NameScope.Find(PART_ContentPresenter); _badgeContainer = e.NameScope.Find(PART_BadgeContainer); - _badgeContent = e.NameScope.Find(PART_BadgeContentPresenter); } protected override void OnLoaded(RoutedEventArgs e) @@ -92,7 +86,7 @@ public class Badge: ContentControl { var vertical = CornerPosition is CornerPosition.BottomLeft or CornerPosition.BottomRight ? 1 : -1; var horizontal = CornerPosition is CornerPosition.TopRight or CornerPosition.BottomRight ? 1 : -1; - if (_badgeContainer is not null && _content?.Child is not null) + if (_badgeContainer is not null && base.Presenter?.Child is not null) { _badgeContainer.RenderTransform = new TransformGroup() {