diff --git a/src/Ursa/Controls/Badge/Badge.cs b/src/Ursa/Controls/Badge/Badge.cs
index fe3f26e..7a5a8f0 100644
--- a/src/Ursa/Controls/Badge/Badge.cs
+++ b/src/Ursa/Controls/Badge/Badge.cs
@@ -8,59 +8,47 @@ using Ursa.Common;
namespace Ursa.Controls;
-[TemplatePart(PART_BadgeContainer, typeof(Border))]
+///
+/// Represents a Badge control that can display a notification indicator or count on top of other content.
+///
+[TemplatePart(PART_BadgeContainer, typeof(Control))]
public class Badge : HeaderedContentControl
{
public const string PART_ContentPresenter = "PART_ContentPresenter";
public const string PART_BadgeContainer = "PART_BadgeContainer";
public const string PART_HeaderPresenter = "PART_HeaderPresenter";
- private Border? _badgeContainer;
-
+ ///
+ /// Defines the theme applied to the badge.
+ ///
public static readonly StyledProperty BadgeThemeProperty =
AvaloniaProperty.Register(nameof(BadgeTheme));
- public ControlTheme BadgeTheme
- {
- get => GetValue(BadgeThemeProperty);
- set => SetValue(BadgeThemeProperty, value);
- }
-
+ ///
+ /// Defines whether the badge should be displayed as a dot.
+ ///
public static readonly StyledProperty DotProperty =
AvaloniaProperty.Register(nameof(Dot));
- public bool Dot
- {
- get => GetValue(DotProperty);
- set => SetValue(DotProperty, value);
- }
-
+ ///
+ /// Defines the corner position where the badge should be displayed.
+ ///
public static readonly StyledProperty CornerPositionProperty =
AvaloniaProperty.Register(nameof(CornerPosition));
- public CornerPosition CornerPosition
- {
- get => GetValue(CornerPositionProperty);
- set => SetValue(CornerPositionProperty, value);
- }
-
+ ///
+ /// Defines the maximum count to display before showing overflow indicator.
+ ///
public static readonly StyledProperty OverflowCountProperty =
AvaloniaProperty.Register(nameof(OverflowCount));
- public int OverflowCount
- {
- get => GetValue(OverflowCountProperty);
- set => SetValue(OverflowCountProperty, value);
- }
-
+ ///
+ /// Defines the font size of the badge text.
+ ///
public static readonly StyledProperty BadgeFontSizeProperty =
AvaloniaProperty.Register(nameof(BadgeFontSize));
- public double BadgeFontSize
- {
- get => GetValue(BadgeFontSizeProperty);
- set => SetValue(BadgeFontSizeProperty, value);
- }
+ private Control? _badgeContainer;
static Badge()
{
@@ -68,22 +56,76 @@ public class Badge : HeaderedContentControl
DotProperty.Changed.AddClassHandler((badge, _) => badge.UpdateBadgePosition());
}
+ ///
+ /// Gets or sets the theme applied to the badge.
+ ///
+ public ControlTheme BadgeTheme
+ {
+ get => GetValue(BadgeThemeProperty);
+ set => SetValue(BadgeThemeProperty, value);
+ }
+
+ ///
+ /// Gets or sets a value indicating whether the badge should be displayed as a dot.
+ ///
+ public bool Dot
+ {
+ get => GetValue(DotProperty);
+ set => SetValue(DotProperty, value);
+ }
+
+ ///
+ /// Gets or sets the corner position where the badge should be displayed.
+ ///
+ public CornerPosition CornerPosition
+ {
+ get => GetValue(CornerPositionProperty);
+ set => SetValue(CornerPositionProperty, value);
+ }
+
+ ///
+ /// Gets or sets the maximum count to display before showing overflow indicator.
+ ///
+ public int OverflowCount
+ {
+ get => GetValue(OverflowCountProperty);
+ set => SetValue(OverflowCountProperty, value);
+ }
+
+ ///
+ /// Gets or sets the font size of the badge text.
+ ///
+ public double BadgeFontSize
+ {
+ get => GetValue(BadgeFontSizeProperty);
+ set => SetValue(BadgeFontSizeProperty, value);
+ }
+
+ ///
protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
{
_badgeContainer?.RemoveHandler(SizeChangedEvent, OnBadgeSizeChanged);
base.OnApplyTemplate(e);
- _badgeContainer = e.NameScope.Find(PART_BadgeContainer);
+ _badgeContainer = e.NameScope.Find(PART_BadgeContainer);
_badgeContainer?.AddHandler(SizeChangedEvent, OnBadgeSizeChanged);
}
- private void OnBadgeSizeChanged(object? sender, SizeChangedEventArgs e) => UpdateBadgePosition();
+ ///
+ /// Handles the size changed event of the badge container and updates its position.
+ ///
+ private void OnBadgeSizeChanged(object? sender, SizeChangedEventArgs e)
+ {
+ UpdateBadgePosition();
+ }
+ ///
+ /// Updates the badge position based on the current corner position and size.
+ ///
private void UpdateBadgePosition()
{
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 && Presenter?.Child is not null)
- {
_badgeContainer.RenderTransform = new TransformGroup
{
Children =
@@ -93,6 +135,5 @@ public class Badge : HeaderedContentControl
vertical * _badgeContainer.Bounds.Height / 2)
]
};
- }
}
}
\ No newline at end of file