Introducing New Badge Control for WPF | Syncfusion Blogs
Live Chat Icon For mobile
Live Chat Icon
Popular Categories.NET  (174).NET Core  (29).NET MAUI  (207)Angular  (109)ASP.NET  (51)ASP.NET Core  (82)ASP.NET MVC  (89)Azure  (41)Black Friday Deal  (1)Blazor  (218)BoldSign  (14)DocIO  (24)Essential JS 2  (107)Essential Studio  (200)File Formats  (66)Flutter  (133)JavaScript  (221)Microsoft  (119)PDF  (81)Python  (1)React  (100)Streamlit  (1)Succinctly series  (131)Syncfusion  (917)TypeScript  (33)Uno Platform  (3)UWP  (4)Vue  (45)Webinar  (51)Windows Forms  (61)WinUI  (68)WPF  (159)Xamarin  (161)XlsIO  (36)Other CategoriesBarcode  (5)BI  (29)Bold BI  (8)Bold Reports  (2)Build conference  (8)Business intelligence  (55)Button  (4)C#  (149)Chart  (131)Cloud  (15)Company  (443)Dashboard  (8)Data Science  (3)Data Validation  (8)DataGrid  (63)Development  (630)Doc  (8)DockingManager  (1)eBook  (99)Enterprise  (22)Entity Framework  (5)Essential Tools  (14)Excel  (40)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  (507)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  (594)What's new  (332)Windows 8  (19)Windows App  (2)Windows Phone  (15)Windows Phone 7  (9)WinRT  (26)
Introducing New Badge Control for WPF

Introducing New Badge Control for WPF

We are happy to announce the availability of the WPF Badge control in our 2020 Volume 4 release. This control comes in handy when you want to show notifications to your users. Depending on the content of the notifications, users may be prompted to perform some action. The following are some scenarios where badge notifications are useful:

  • New messages in your inbox.
  • A new version or update is available for your application.
  • The availability of a person in a chat application.
  • An error occurred during an upgrade process.

In this blog post, we will see how to add the Badge control to an application and discuss its customization options.

Attaching the Badge to an element

Let’s cover how to add the Badge control as a notification over a button.

  1. In Visual Studio, create a new WPF project.
  2. Add the Syncfusion.Tools.WPF NuGet package to the project reference.
  3. Import the Syncfusion WPF schema. As shown in the following code sample, we used syncfusion as a prefix to the namespace.
    <Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
            xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
            xmlns:syncfusion="http://schemas.syncfusion.com/wpf"
    </Window>
  4. Add a button for which a notification is required.
    <Button 
            HorizontalAlignment="Center" VerticalAlignment="Center"
            Content="Inbox" 
            Width="70" Height="40"/>
    </Button>
  5. Attach the Badge control to notify users of the unread count.
    <Button Content="Inbox">
        <syncfusion:SfBadge.Badge>
            <syncfusion:SfBadge Content="10+" />
        </syncfusion:SfBadge.Badge>
    </Button>

    WPF Button with Badge Control
    WPF Button with Badge Control

Badge alignment

The Badge control can be placed at any corner of the button by using the HorizontalAlignment and VerticalAlignment properties.

<Button Content="Mailbox">
    <syncfusion:SfBadge.Badge>
        <syncfusion:SfBadge Content="10"
                            HorizontalAlignment="Right"
                            VerticalAlignment="Bottom"/>
    </syncfusion:SfBadge.Badge>
</Button>
WPF Badge Aligned with Bottom-Right Corner
WPF Badge Aligned with Bottom-Right Corner

Badge anchor

The badge can be aligned within or outside the host control by using the HorizontalAnchor and VerticalAnchor properties.

<Button Content="Mailbox">
    <syncfusion:SfBadge.Badge>
        <syncfusion:SfBadge Content="10"
                            HorizontalAnchor="Outside"
                            VerticalAnchor="Outside"/>
    </syncfusion:SfBadge.Badge>
</Button>
WPF Badge Anchored to the Button Control
WPF Badge Anchored to the Button Control

Badge precise alignment

You can fine-tune the alignment of the Badge control using the HorizontalPosition, VerticalPosition, HorizontalAnchorPosition, and VerticalAnchorPosition properties. These are relative APIs where 0 represents the top or leftmost position, and 1 represents the bottom or rightmost position. This means that when the size of the host control is changed, the position of the badge is relatively aligned. Refer to our documentation to learn more about custom alignment.

<Image 
    Source="Assets/Badge/avatar.png">
    <syncfusion:SfBadge.Badge>
        <syncfusion:SfBadge
            HorizontalAnchor="Custom"
            VerticalAnchor="Custom"
            HorizontalPosition="0.8"
            VerticalPosition="0.8"
            HorizontalAnchorPosition="0.5"
            VerticalAnchorPosition="0.5">
            <Ellipse 
                Width="20" 
                Height="20" 
                Fill="LimeGreen"/>
        </syncfusion:SfBadge>
    </syncfusion:SfBadge.Badge>
</Image>
Badge Relatively Positioned on Differently Host Control Sizes
Badge Relatively Positioned on Differently Host Control Sizes

Badge shape

The Badge control comes with a predefined set of standard shapes. However, you can customize the shape of the badge by using the CustomShape property.

<Button Content="Inbox">
    <syncfusion:SfBadge.Badge>
        <syncfusion:SfBadge Content="28+" Shape="Ellipse"/>
    </syncfusion:SfBadge.Badge>
</Button>
Different Shapes of WPF Badge
Different Shapes of WPF Badge

Badge notification severity

To indicate the severity or priority of a notification, the Badge control comes with built-in fill options. Based on the current theme and selected fill, the foreground and background of the badge will be updated.

<Button Content="Primary">
    <syncfusion:SfBadge.Badge>
        <syncfusion:SfBadge Content="28+"
                            Fill="Error"/>
    </syncfusion:SfBadge.Badge>
</Button>
WPF Badge with Different Fill Colors
WPF Badge with Different Fill Colors

Badge animation

The Badge control’s content changes are visually indicated using animations. The control comes with scaling and transparent animations.

Badge animation
Badge animation

Integrated with controls

The Badge control can be attached to any UIElement, not just standard WPF controls. Let’s see how to show the Badge control in Ribbon and Docking Manager controls.

Badge Included in Ribbon and Docking Manager Elements
Badge Included in Ribbon and Docking Manager Elements

Integrate Badge with Ribbon control

The following code example integrates the Badge control with a Button control in the Ribbon control.

<syncfusion:RibbonButton
    SizeForm="Large" 
    Label="Primary">
    <syncfusion:SfBadge.Badge>
        <syncfusion:SfBadge
            FontSize="10"
            Height="15" 
            Width="26"
            Fill="Information"
            Shape="Oval"/>
    </syncfusion:SfBadge.Badge>
</syncfusion:RibbonButton>

Integrate with Docking Manager

The following code example integrates the Badge control to customize the header of the Docking Manager using HeaderTemplate.

<syncfusion:DockingManager
    UseDocumentContainer="True"
    x:Name="dockingManager" >
    <ContentControl 
        syncfusion:DockingManager.Header="Primary"
        syncfusion:DockingManager.State="Document">
        <syncfusion:DockingManager.HeaderTemplate>
            <DataTemplate>
                <Border Width="100">
                    <TextBlock Text="{Binding}" 
                                HorizontalAlignment="Left"/>
                    <syncfusion:SfBadge.Badge>
                        <syncfusion:SfBadge VerticalAlignment="Center"
                                            HorizontalAlignment="Right"
                                            FontSize="10"
                                            Padding="-20"
                                            Background="Orange"
                                            HorizontalAnchor="Inside"
                                            Content="43+"/>
                    </syncfusion:SfBadge.Badge>
                </Border>
            </DataTemplate>
        </syncfusion:DockingManager.HeaderTemplate>
        <TextBlock
            HorizontalAlignment="Center"
            VerticalAlignment="Center"
            FontSize="14">
            Primary mails are listed here.
        </TextBlock>
    </ContentControl>
</syncfusion:DockingManager>

Conclusion

I hope you now have a clear picture of the Syncfusion Badge control for WPF and all its customization features. You can learn more about it from its feature tour and user guide pages. You can also download examples of the control from this GitHub repository and try them out for yourself.

Syncfusion has over 90 essential WPF controls like a DataGridChartsDiagram, and PDF Viewer. Give these controls a shot by downloading the setup from our latest release. Our demos are now available in Microsoft Store, and .NET Core demos are available in the App Center.

For existing customers, the newest version 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.

Also, if you wish to send us feedback or would like to submit any questions, please feel free to post them in the comments section of this blog post. You can also contact us through our support forumsfeedback portal, or Direct-Trac support system.

Tags:

Share this post:

Popular Now

Be the first to get updates

Subscribe RSS feed

Be the first to get updates

Subscribe RSS feed