Everything You Need to Know About The WinUI Badge Control
Live Chat Icon For mobile
Live Chat Icon
Popular Categories.NET  (175).NET Core  (29).NET MAUI  (208)Angular  (109)ASP.NET  (51)ASP.NET Core  (82)ASP.NET MVC  (89)Azure  (41)Black Friday Deal  (1)Blazor  (220)BoldSign  (15)DocIO  (24)Essential JS 2  (107)Essential Studio  (200)File Formats  (67)Flutter  (133)JavaScript  (221)Microsoft  (119)PDF  (81)Python  (1)React  (101)Streamlit  (1)Succinctly series  (131)Syncfusion  (920)TypeScript  (33)Uno Platform  (3)UWP  (4)Vue  (45)Webinar  (51)Windows Forms  (61)WinUI  (68)WPF  (159)Xamarin  (161)XlsIO  (37)Other CategoriesBarcode  (5)BI  (29)Bold BI  (8)Bold Reports  (2)Build conference  (8)Business intelligence  (55)Button  (4)C#  (151)Chart  (132)Cloud  (15)Company  (443)Dashboard  (8)Data Science  (3)Data Validation  (8)DataGrid  (63)Development  (633)Doc  (8)DockingManager  (1)eBook  (99)Enterprise  (22)Entity Framework  (5)Essential Tools  (14)Excel  (41)Extensions  (22)File Manager  (7)Gantt  (18)Gauge  (12)Git  (5)Grid  (31)HTML  (13)Installer  (2)Knockout  (2)Language  (1)LINQPad  (1)Linux  (2)M-Commerce  (1)Metro Studio  (11)Mobile  (508)Mobile MVC  (9)OLAP server  (1)Open source  (1)Orubase  (12)Partners  (21)PDF viewer  (43)Performance  (12)PHP  (2)PivotGrid  (4)Predictive Analytics  (6)Report Server  (3)Reporting  (10)Reporting / Back Office  (11)Rich Text Editor  (12)Road Map  (12)Scheduler  (52)Security  (3)SfDataGrid  (9)Silverlight  (21)Sneak Peek  (31)Solution Services  (4)Spreadsheet  (11)SQL  (11)Stock Chart  (1)Surface  (4)Tablets  (5)Theme  (12)Tips and Tricks  (112)UI  (387)Uncategorized  (68)Unix  (2)User interface  (68)Visual State Manager  (2)Visual Studio  (31)Visual Studio Code  (19)Web  (597)What's new  (333)Windows 8  (19)Windows App  (2)Windows Phone  (15)Windows Phone 7  (9)WinRT  (26)
Everything You Need to Know About WinUI Badge Control

Everything You Need to Know About The WinUI Badge Control

When you want to show a notification that prompts your customers to act based on any of the following scenarios, then the badge control comes in handy:

  • Message received in an application (chat apps).
  • New version or an update to an app.
  • Process status information.

The WinUI Badge is a notification control. It is used to notify users about new or unread messages, notifications, status, and more. You can easily integrate it with controls like ListBox and Pivot.

In this blog post, we will learn how to integrate the WinUI Badge control and use its features in your application.

Adding WinUI Badge to an element

Let’s create a button control and add the WinUI Badge Control to your application.

Follow these steps to add the WinUI Badge control manually in the XAML file:

  1. First, create a project using the instructions provided in the WinUI 3 desktop app for C# and .NET 5 documentation.
  2. Then, install the latest Syncfusion.Notifications.WinUI NuGet package in the project.
  3. Now, import the Syncfusion.UI.Xaml.Notifications control namespace in the XAML page.
  4. Finally, initialize the BadgeContainer control. Assign the Badge control to its Badge property and assign a button or any other host control to the Content property.
    Refer to the following code.

    <Grid>
        <notify:BadgeContainer Name="badgeContainer"
                                   HorizontalAlignment="Center"
                                   VerticalAlignment="Center"
                                   >
            <notify:BadgeContainer.Badge>
                <notify:SfBadge
                        HorizontalAlignment="Right"
                        VerticalAlignment="Top"
                        Height="20"
                        Width="25"
                        Content="7"
                />
            </notify:BadgeContainer.Badge>
            <notify:BadgeContainer.Content>
                <Button Content="Outlook" Height="35" Width="130" />
            </notify:BadgeContainer.Content>
        </notify:BadgeContainer>
    </Grid>
Adding WinUI Badge control to a Button Control
Adding WinUI Badge control to a Button Control

Change Badge alignment

The WinUI Badge control allows you to change its position to any corner of the host control using the HorizontalAlignment and VerticalAlignment properties.

Refer to the following code example.

<Grid>
    <notify:BadgeContainer Name="badgeContainer"
                               HorizontalAlignment="Center"
                               VerticalAlignment="Center"
                               >
        <notify:BadgeContainer.Badge>
            <notify:SfBadge
                    HorizontalAlignment="Right"
                    VerticalAlignment="Center"
                    Height="20"
                    Width="25"
                    Content="7"
            />
        </notify:BadgeContainer.Badge>
        <notify:BadgeContainer.Content>
            <Button Content="Outlook" Height="35" Width="130" />
        </notify:BadgeContainer.Content>
    </notify:BadgeContainer>
</Grid>
Changing the Alignment of WinUI Badge Control
Changing the Alignment of WinUI Badge Control

Note: For more details, refer to the different alignment options in the WinUI Badge control documentation.

Change Badge position

Using the HorizontalAnchor and VerticalAnchor properties, you can move the Badge control horizontally or vertically inside, outside, or in the middle of the border in the host control.

The default value of the HorizontalAnchor and VerticalAnchor properties is Center.

Refer to the following code example.

<notify:BadgeContainer Name="badgeContainer"
                               HorizontalAlignment="Center"
                               VerticalAlignment="Center"
                               >
    <notify:BadgeContainer.Badge>
        <notify:SfBadge
                HorizontalAnchor="Center"
                VerticalAnchor="Outside"
                    Height="20"
                    Width="25"
                    Content="7"
            />
    </notify:BadgeContainer.Badge>
    <notify:BadgeContainer.Content>
        <Button Content="Outlook" Height="35" Width="130" />
    </notify:BadgeContainer.Content>
</notify:BadgeContainer>
Changing WinUI Badge Control Position
Changing WinUI Badge Control Position

The Badge control also allows you to apply custom positions using the HorizontalPosition and VerticalPosition properties like in the following code example.

<notify:BadgeContainer x:Name="container"
                               HorizontalAlignment="Center" VerticalAlignment="Center" >
    <notify:BadgeContainer.Badge>
        <notify:SfBadge Height="20" Width="20"
                                HorizontalAnchor="Custom"
                                VerticalAnchor="Custom"
                                HorizontalPosition="0.8"
                                VerticalPosition="0.1"
                                Content="7"
                                Shape="Ellipse" />
    </notify:BadgeContainer.Badge>
    <notify:BadgeContainer.Content>
        <Image Source="HostImage.png" Height="75" Width="75" />
    </notify:BadgeContainer.Content>
</notify:BadgeContainer>
Custom Anchor Position in WinUI Badge Control
Custom Anchor Position in WinUI Badge Control

Note: For more details, refer to the predefined and custom positioning in the WinUI Badge control documentation.

Distinct and attractive colors

Use the Fill property to apply distinctive colors to the background of the Badge control based on the status of the host control. This feature comes in handy when you need to prompt the users to act based on the application’s status.

Refer to the following code example.

<notify:BadgeContainer Name="badgeContainer"
                               HorizontalAlignment="Center"
                               VerticalAlignment="Center"
                               >
    <notify:BadgeContainer.Badge>
        <notify:SfBadge
                    Fill="Success"
                    Height="20"
                    Width="25"
                    Content="99+"
            />
    </notify:BadgeContainer.Badge>
    <notify:BadgeContainer.Content>
        <Button Content="Outlook" Height="35" Width="130" />
    </notify:BadgeContainer.Content>
</notify:BadgeContainer>
Applying Background Color Based on the Host Status in WinUI Badge Control
Applying Background Color Based on the Host Status in WinUI Badge Control

Predefined and custom shapes

You can change the shape of the Badge control using the predefined shapes available in the Shape property. Also, you can apply a custom shape using the CustomShape property.

Refer to the following code example.

<!--SfBadge with predefined shape-->
<notify:BadgeContainer Name="badgeContainer"
                               HorizontalAlignment="Left"
                               VerticalAlignment="Center"
                               >
    <notify:BadgeContainer.Badge>
        <notify:SfBadge
                    Shape="Oval"
                    Height="20"
                    Width="25"
                    Content="7"
            />
    </notify:BadgeContainer.Badge>
    <notify:BadgeContainer.Content>
        <Button Content="Outlook" Height="35" Width="130" />
    </notify:BadgeContainer.Content>
</notify:BadgeContainer>

<!--SfBadge with custom shape-->
<notify:BadgeContainer Name="badgeContainer"
                               HorizontalAlignment="Left"
                               VerticalAlignment="Center"
                               >
    <notify:BadgeContainer.Badge>
        <notify:SfBadge
                    Shape="Custom"
                    CustomShape="M16.057999,0C19.938004,1.2542023E-07 23.380997,2.294006 24.832001,5.7030019 25.012009,6.126006 25.421005,6.4270009 25.900009,6.5299977 29.384003,7.2799977 32,10.303007 32,13.912992 32,18.084988 28.512009,21.479 24.220001,21.479L5.697998,21.479C2.5550003,21.479 0,18.989986 0,15.936002 0,12.877989 2.5550003,10.39401 5.697998,10.39401 5.7389984,10.39401 5.7789993,10.39401 5.8199997,10.394987 6.2430038,10.406004 6.598999,10.093992 6.5740051,9.7049845 6.5650024,9.5490092 6.5600052,9.3930043 6.5600052,9.2369984 6.5600052,4.1430048 10.820999,1.2542023E-07 16.057999,0z"
                    Height="20"
                    Width="25"
                    Content="7"
            />
    </notify:BadgeContainer.Badge>
    <notify:BadgeContainer.Content>
        <Button Content="Outlook" Height="35" Width="130" />
    </notify:BadgeContainer.Content>
</notify:BadgeContainer>
WinUI Badge Control with Predefined and Custom Shapes
WinUI Badge Control with Predefined and Custom Shapes

Set visual effects

Also, you can apply required animation or visual effects using the AnimationType property based on the Opacity or Scale values.

Refer to the following code example.

<notify:BadgeContainer Name="badgeContainer"
                               HorizontalAlignment="Left"
                               VerticalAlignment="Center"
                               >
    <notify:BadgeContainer.Badge>
        <notify:SfBadge
                    x:Name="sfBadge"
                    AnimationType="Scale"
                    Height="20"
                    Width="25"
                    Content="7"
            />
    </notify:BadgeContainer.Badge>
    <notify:BadgeContainer.Content>
        <Button Content="Outlook" Height="35" Width="130" />
    </notify:BadgeContainer.Content>
</notify:BadgeContainer>
Setting Animation Effects in WinUI Badge Control
Setting Animation Effects in WinUI Badge Control

Auto repositioning the badge

When a user resizes the application containing the host of the Badge control, then the Badge will automatically update its position to the assigned alignment position based on the host control’s size.

Auto Positioning of WinUI Badge on Resizing the Host control
Auto Positioning of WinUI Badge on Resizing the Host control

GitHub reference

Also, you can download the complete example for the notification Badge control in WinUI.

Conclusion

Thanks for reading! With these amazing features, we believe our WinUI Badge control fits your expectations and requirements. Use this control to display a notification count, the number of unread messages in an email category, the status of product support, etc. To see more, you can download and check out our demo app in the Windows Store.

For existing customers, the newest version of Essential Studio is available for download from the license and downloads page. If you are not yet a customer, you can try our 30-day free trial to check out these new features.

You can also contact us through support forums, feedback portal, or the Direct-Trac support system. We are always happy to assist you!

Related blogs

Tags:

Share this post:

Popular Now

Be the first to get updates

Subscribe RSS feed

Be the first to get updates

Subscribe RSS feed