diff --git a/Maui.CommunityToolkit.TabView.Compat/TabBadgeTemplate.cs b/Maui.CommunityToolkit.TabView.Compat/TabBadgeTemplate.cs index e19c643..ef06900 100644 --- a/Maui.CommunityToolkit.TabView.Compat/TabBadgeTemplate.cs +++ b/Maui.CommunityToolkit.TabView.Compat/TabBadgeTemplate.cs @@ -9,10 +9,8 @@ public TabBadgeTemplate() HorizontalOptions = LayoutOptions.Start; VerticalOptions = LayoutOptions.Start; - var badgeBorder = new Frame + var badgeBorder = new Border { - HasShadow = false, - IsClippedToBounds = false, Padding = 2, Margin = 6 }; diff --git a/Maui.CommunityToolkit.TabView.Compat/TabBadgeView.cs b/Maui.CommunityToolkit.TabView.Compat/TabBadgeView.cs index 1397c03..bee967b 100644 --- a/Maui.CommunityToolkit.TabView.Compat/TabBadgeView.cs +++ b/Maui.CommunityToolkit.TabView.Compat/TabBadgeView.cs @@ -1,4 +1,5 @@ -using System.ComponentModel; +using Microsoft.Maui.Controls.Shapes; +using System.ComponentModel; using System.Runtime.CompilerServices; namespace Maui.CommunityToolkit.TabView.Compat; @@ -8,7 +9,7 @@ public class TabBadgeView : TemplatedView internal const string ElementBorder = "PART_Border"; internal const string ElementText = "PART_Text"; - Frame? badgeBorder; + Border? badgeBorder; Label? badgeText; bool isVisible; @@ -108,13 +109,16 @@ public string Text protected override void OnApplyTemplate() { base.OnApplyTemplate(); + try + { + badgeBorder = (Border)GetTemplateChild(ElementBorder); + badgeText = (Label)GetTemplateChild(ElementText); - badgeBorder = (Frame)GetTemplateChild(ElementBorder); - badgeText = (Label)GetTemplateChild(ElementText); - - UpdateSize(); - UpdatePosition(badgeBorder); - UpdateIsEnabled(badgeText); + UpdateSize(); + UpdatePosition(badgeBorder); + UpdateIsEnabled(badgeText); + } + catch (Exception _) { } } protected override void OnPropertyChanged([CallerMemberName] string propertyName = "") @@ -135,7 +139,7 @@ void UpdateIsEnabled(in Label badgeText) void OnBadgeTextPropertyChanged(object? sender, PropertyChangedEventArgs e) { - if (e.PropertyName is nameof(Height) or nameof(Width) && badgeBorder is Frame frame) + if (e.PropertyName is nameof(Height) or nameof(Width) && badgeBorder is Border frame) { UpdateSize(); UpdatePosition(frame); @@ -153,10 +157,13 @@ void UpdateSize() badgeBorder.HeightRequest = badgeTextHeight; badgeBorder.WidthRequest = badgeTextWidth; - badgeBorder.CornerRadius = (int)Math.Round(badgeTextHeight / 2); + badgeBorder.StrokeShape = new RoundRectangle + { + CornerRadius = new CornerRadius((int)Math.Round(badgeTextHeight / 2)) + }; } - void UpdatePosition(Frame badgeBorder) + void UpdatePosition(Border badgeBorder) { if (PlacementTarget == null) return; @@ -178,7 +185,7 @@ void UpdateBackgroundColor(Color backgroundColor) void UpdateBorderColor(Color borderColor) { if (badgeBorder != null) - badgeBorder.BorderColor = borderColor; + badgeBorder.Stroke = borderColor; } void UpdateTextColor(Color textColor)