Skip to content

[Proposal] BadgeView #105

@TheCodeTraveler

Description

@TheCodeTraveler

BadgeView

  • Proposed
  • Prototype
  • Implementation
    • iOS Support
    • Android Support
    • macOS Support
    • Windows Support
  • Unit Tests: Not Started
  • Sample
  • Documentation: Not Started

Summary

The BadgeView allows the user to show a badge with a string value on top of any control. By wrapping a control in a BadgeView control, you can show a badge value on top of it. This is very much like the badges you see on the app icons on iOS and Android.

Motivation

Detailed Design

BadgeView.shared.cs

[ContentProperty(nameof(Content))]
public class BadgeView : BaseTemplatedView<Grid>
{
  public static readonly BindableProperty ContentProperty;
  public static readonly BindableProperty BadgePositionProperty;
  public static BindableProperty AutoHideProperty;
  public static BindableProperty IsAnimatedProperty;
  public static BindableProperty BadgeAnimationProperty;
  public static new BindableProperty BackgroundColorProperty;
  public static readonly BindableProperty BorderColorProperty;
  public static readonly BindableProperty HasShadowProperty;
  public static BindableProperty TextColorProperty;
  public static BindableProperty TextProperty;
  public static BindableProperty FontSizeProperty;
  public static BindableProperty FontFamilyProperty;
  public static BindableProperty FontAttributesProperty;
  
  public View? Content { get; set; }
  public BadgePosition BadgePosition { get; set; }
  public bool AutoHide { get; set; }
  public bool IsAnimated { get; set; }
  public IBadgeAnimation? BadgeAnimation { get; set; }
  public new Color BackgroundColor { get; set; }
  public Color BorderColor { get; set; }
  public bool HasShadow { get; set; }
  public Color TextColor { get; set; }
  public string Text { get; set; }
  [TypeConverter(typeof(FontSizeConverter))]
  public double FontSize { get; set; }
  public string FontFamily { get; set; }
  public FontAttributes FontAttributes { get; set; }
}

Usage Syntax

XAML Usage

<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:xct="http://xamarin.com/schemas/2020/toolkit"
             x:Class="MyLittleApp.MainPage">

     <StackLayout>

        <xct:BadgeView
            BackgroundColor="Red"
            FontAttributes="Bold"
            FontSize="Medium"
            TextColor="White"
            Text="1">
            <Label
                Text="This label has a badge in the top-right"/>
        </xct:BadgeView>

    </StackLayout>

</ContentPage>

C# Usage

class MyPage : ContentPage
{
  public MyPage()
  {
    Content = new BadgeView
    {
      BackgroundColor = Colors.Red,
      FontAttributes = FontAttributes.Bold,
      TextColor = Colors.White,
      Text = "1",
      Cotent = new Label { Text = "This label has a badge in the top-right" }
    };
  }
}

Metadata

Metadata

Assignees

Labels

approvedThis Proposal has been approved and is ready to be added to the ToolkitchampionA member of the .NET MAUI Toolkit core team has chosen to champion this featurepending documentationThis feature requires documentationproposalA fully fleshed out proposal describing a new feature in syntactic and semantic detail

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions