Live Chat Icon For mobile
Live Chat Icon
Popular Categories.NET  (152).NET Core  (26)Angular  (49)ASP.NET  (48)ASP.NET Core  (64)ASP.NET MVC  (86)Azure  (29)Blazor  (107)DocIO  (20)Essential JS 2  (72)Essential Studio  (164)File Formats  (20)Flutter  (115)JavaScript  (150)Microsoft  (102)PDF  (59)React  (33)Succinctly series  (124)Syncfusion  (490)TypeScript  (30)Uno Platform  (3)UWP  (4)Vue  (26)Webinar  (27)Windows Forms  (55)WinUI  (27)WPF  (123)Xamarin  (132)XlsIO  (24)Other CategoriesBarcode  (4)BI  (29)Bold BI  (4)Build conference  (6)Business intelligence  (53)Button  (4)C#  (108)Chart  (53)Cloud  (10)Company  (445)Dashboard  (6)Data Science  (3)Data Validation  (5)DataGrid  (50)Development  (263)Doc  (7)DockingManager  (1)eBook  (94)Enterprise  (22)Entity Framework  (5)Essential Tools  (14)Excel  (20)Extensions  (15)File Manager  (4)Gantt  (9)Gauge  (7)Git  (4)Grid  (27)HTML  (9)Installer  (2)Knockout  (2)Language  (1)LINQPad  (1)Linux  (2)M-Commerce  (1)Metro Studio  (11)Mobile  (233)Mobile MVC  (9)OLAP server  (1)Open source  (1)Orubase  (12)Partners  (21)PDF viewer  (25)Performance  (7)PHP  (1)PivotGrid  (4)Predictive Analytics  (6)Report Server  (3)Reporting  (10)Reporting / Back Office  (11)Rich Text Editor  (6)Road Map  (9)Scheduler  (29)SfDataGrid  (9)Silverlight  (21)Sneak Peek  (19)Solution Services  (2)Spreadsheet  (10)SQL  (7)Stock Chart  (1)Surface  (4)Tablets  (5)Theme  (11)Tips and Tricks  (65)UI  (139)Uncategorized  (68)Unix  (2)User interface  (68)Visual State Manager  (1)Visual Studio  (19)Visual Studio Code  (13)Web  (227)What's new  (146)Windows 8  (19)Windows App  (1)Windows Phone  (15)Windows Phone 7  (9)WinRT  (26)
Share on twitter
Share on facebook
Share on linkedin
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:

Share on twitter
Share on facebook
Share on linkedin
Popular Now

Be the first to get updates

Subscribe RSS feed
Scroll To Top