Click here to Skip to main content
13,799,517 members
Click here to Skip to main content
Add your own
alternative version

Tagged as


121 bookmarked
Posted 26 Nov 2012
Licenced CPOL

Growl Alike WPF Notifications

, 8 Mar 2013
Rate this:
Please Sign up or sign in to vote.
Lightweight growl alike notifications for WPF project.


Recently I needed to add Growl like notifications to a WPF project. Just a notification system that only this program will be using. I Googled a bit and found Growl for Windows, it's fine but seemed too much for just this functionality (it has an independent component and common message bus, which I don't need). Also you're adding new dependencies (Growl components, Forms, etc.) and new libraries to the project, but you can just have a few classes to have the same behavior of notifications to handle this.


This implementation provides the following functionality:

  • Notifications could be added and will be placed on the screen
  • Specific notifications can be deleted
  • Notification fades in when added (2 sec)
  • Notification stays for 6 seconds after fade in and then it will fade out (2 sec) and collapse
  • If user places mouse pointer above a notification it becomes fully visible and doesn't fade out
  • There's a maximum number of notifications, if there's more than the max number, they are placed in a queue and will be shown when the place is available
  • The looks of the notification is defined by a DataTemplate
  • Notification class is used to store data, which is bound to the DataTemplate

Using the code

GrowlNotifications class

The GrowlNotifiactions class contains logic to add or remove notifications. It is very simple. First of all a DataContext is set on creation to Notifications, which is an ObservableCollection<Notification>. This collection is the source for the ItemControl in XAML.

using System;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
namespace WPFGrowlNotification
    public partial class GrowlNotifiactions
        private const byte MAX_NOTIFICATIONS = 4;
        private int count;
        public Notifications Notifications = new Notifications();
        private readonly Notifications buffer = new Notifications();
        public GrowlNotifiactions()
            NotificationsControl.DataContext = Notifications;
        public void AddNotification(Notification notification)
            notification.Id = count++;
            if (Notifications.Count + 1 > MAX_NOTIFICATIONS)
            //Show window if there're notifications
            if (Notifications.Count > 0 && !IsActive)
        public void RemoveNotification(Notification notification)
            if (Notifications.Contains(notification))
            if (buffer.Count > 0)
            //Close window if there's nothing to show
            if (Notifications.Count < 1)
        private void NotificationWindowSizeChanged(object sender, SizeChangedEventArgs e)
            if (e.NewSize.Height != 0.0)
            var element = sender as Grid;
              n => n.Id == Int32.Parse(element.Tag.ToString())));

When a new notification is added a unique ID is assigned. This is needed when we want to remove an element from a collection (when it is collapsed in this case), see NotificationWindowSizeChanged. Then if there's space, the ItemsControl element notification is added directly to the Notifications collection, otherwise it will be stored in a buffer variable. The final step is to show the window.

When a notification is removed, the buffer is checked and if there's something in it, it's pushed to the Notifications collection. If there's nothing to show, the window is closed.

Notification class

The notification class implements INotifyPropertyChanged, so you can bind to its values in DataTemplate. You can customize it to show whatever you like.

using System.Collections.ObjectModel;
using System.ComponentModel;

namespace WPFGrowlNotification
    public class Notification : INotifyPropertyChanged
        private string message;
        public string Message
            get { return message; }

                if (message == value) return;
                message = value;

        private int id;
        public int Id
            get { return id; }

                if (id == value) return;
                id = value;

        private string imageUrl;
        public string ImageUrl
            get { return imageUrl; }

                if (imageUrl == value) return;
                imageUrl = value;

        private string title;
        public string Title
            get { return title; }

                if (title == value) return;
                title = value;

        protected virtual void OnPropertyChanged(string propertyName)
            var handler = PropertyChanged;
            if (handler != null) handler(this, new PropertyChangedEventArgs(propertyName));

        public event PropertyChangedEventHandler PropertyChanged;

    public class Notifications : ObservableCollection<Notification> { }


All the animations are in XAML and it is very handy. It is easy to go through them, there're only four triggers. Also you can see the DataTemplate which can be customized however you like to show what's in the Notification class.

<Window x:Class="WPFGrowlNotification.GrowlNotifiactions"


        xmlns:x="" xmlns:Model="clr-namespace:WPFGrowlNotification"


        xmlns:mc="" mc:Ignorable="d"

        Title="GrowlNotifiactions" Height="530" Width="300" ShowActivated="False" 

        AllowsTransparency="True" WindowStyle="None" ShowInTaskbar="False" 

        Background="Transparent" Topmost="True" UseLayoutRounding="True">
        <Storyboard x:Key="CollapseStoryboard">
            <DoubleAnimation From="100" To="0" Storyboard.TargetProperty="Height" Duration="0:0:1"/>
        <DataTemplate x:Key="MessageTemplate" DataType="Model:Notification">
            <Grid x:Name="NotificationWindow" Tag="{Binding Path=Id}" 

                  Background="Transparent" SizeChanged="NotificationWindowSizeChanged">
                <Border Name="border" Background="#2a3345" 

                  BorderThickness="0" CornerRadius="10" Margin="10">
                        <DropShadowEffect ShadowDepth="0" Opacity="0.8" BlurRadius="10"/>
                    <Grid Height="100" Width="280" Margin="6">
                            <RowDefinition Height="Auto"></RowDefinition>
                            <RowDefinition Height="*"></RowDefinition>
                            <ColumnDefinition Width="Auto"></ColumnDefinition>
                            <ColumnDefinition Width="*"></ColumnDefinition>
                        <Image Grid.RowSpan="2" Source="{Binding Path=ImageUrl}" Margin="4" Width="80"></Image>
                        <TextBlock Grid.Column="1" Text="{Binding Path=Title}" 


                                   TextOptions.TextFormattingMode="Display" Foreground="White" 

                                   FontFamily="Arial" FontSize="14" FontWeight="Bold" 

                                   VerticalAlignment="Center"  Margin="2,4,4,2" 

                                   TextWrapping="Wrap" TextTrimming="CharacterEllipsis" />
                        <Button x:Name="CloseButton" Grid.Column="1" Width="16" Height="16" 

                          HorizontalAlignment="Right" Margin="0,0,12,0" Style="{StaticResource CloseButton}" />
                        <TextBlock Grid.Row="1" Grid.Column="1" Text="{Binding Path=Message}" 


                                   TextOptions.TextFormattingMode="Display" Foreground="White" 

                                   FontFamily="Arial" VerticalAlignment="Center" 

                                   Margin="2,2,4,4" TextWrapping="Wrap" TextTrimming="CharacterEllipsis"/>
                <EventTrigger RoutedEvent="Window.Loaded" SourceName="NotificationWindow">
                    <BeginStoryboard x:Name="FadeInStoryBoard">
                            <DoubleAnimation Storyboard.TargetName="NotificationWindow" 

                              From="0.01" To="1" Storyboard.TargetProperty="Opacity" Duration="0:0:2"/>
                            <DoubleAnimation Storyboard.TargetName="NotificationWindow" 

                              From="1" To="0" Storyboard.TargetProperty="Opacity" 

                              Duration="0:0:2" BeginTime="0:0:6"/>
                <Trigger Property="IsMouseOver" Value="True">
                        <SeekStoryboard Offset="0:0:3" BeginStoryboardName="FadeInStoryBoard" />
                        <PauseStoryboard BeginStoryboardName="FadeInStoryBoard" />
                        <SeekStoryboard Offset="0:0:3" BeginStoryboardName="FadeInStoryBoard" />
                        <ResumeStoryboard BeginStoryboardName="FadeInStoryBoard"></ResumeStoryboard>
                <EventTrigger RoutedEvent="Button.Click" SourceName="CloseButton">
                        <Storyboard >
                            <DoubleAnimation Storyboard.TargetName="NotificationWindow" 

                              From="1" To="0" Storyboard.TargetProperty="(Grid.Opacity)" Duration="0:0:0"/>
                <Trigger SourceName="NotificationWindow" Property="Opacity" Value="0">
                    <Setter TargetName="NotificationWindow" Property="Visibility" Value="Hidden"></Setter>
                        <BeginStoryboard Storyboard="{StaticResource CollapseStoryboard}"/>
    <ItemsControl x:Name="NotificationsControl" FocusVisualStyle="{x:Null}" 

      d:DataContext="{d:DesignData Source=DesignTimeNotificationData.xaml}" 

      ItemsSource="{Binding .}" ItemTemplate="{StaticResource MessageTemplate}" />

Sample application

The sample application has a window that adds different notifications to the notification window.


  • 02/18/2013 - Bug fix: notification window should be hidden, not closed. Closing should be external or on some event.
  • 02/17/2013 - Bug fix: Collection window stays open if the last notification is closed. Thanks ChrDressler (see comments).
  • 12/19/2012 - ItemsControl focusable style is set to null. Notifications window is not activated. Thanks John Schroedl (see comments).
  • 12/10/2012 - Executable added to downloads.
  • 11/26/2012 - Initial version.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Ivan Leonenko
Software Developer (Senior) Enkata
Russian Federation Russian Federation
More than 7 years of software design and development.

Specialties: C#, .NET 2 3.5 4, WPF (MVVM), Silverlight, ASP.NET, WCF, Javascript, Flash, ActionScript, SQL, WinAPI, Powershell

My blog

You may also be interested in...

Comments and Discussions

GeneralRe: Add Notification from Bottom Up / Closing Notification Pin
PeteUKinUSA7-Jan-13 20:18
memberPeteUKinUSA7-Jan-13 20:18 
QuestionWhere is the 'Growl' Pin
FatCatProgrammer10-Dec-12 4:18
memberFatCatProgrammer10-Dec-12 4:18 
AnswerRe: Where is the 'Growl' Pin
Ivan Leonenko10-Dec-12 4:58
memberIvan Leonenko10-Dec-12 4:58 
GeneralRe: Where is the 'Growl' Pin
FatCatProgrammer10-Dec-12 14:51
memberFatCatProgrammer10-Dec-12 14:51 
GeneralRe: Where is the 'Growl' Pin
Ivan Leonenko10-Dec-12 22:19
memberIvan Leonenko10-Dec-12 22:19 
GeneralRe: Where is the 'Growl' Pin
Thornik25-Feb-13 23:26
memberThornik25-Feb-13 23:26 
GeneralRe: Where is the 'Growl' Pin
Ivan Leonenko25-Feb-13 23:38
memberIvan Leonenko25-Feb-13 23:38 
GeneralMy vote of 5 Pin
Vladimir Kocheryzhkin4-Dec-12 1:44
memberVladimir Kocheryzhkin4-Dec-12 1:44 
GeneralRe: My vote of 5 Pin
Ivan Leonenko4-Dec-12 2:13
memberIvan Leonenko4-Dec-12 2:13 
GeneralMy vote of 5 Pin
Michał Zalewski4-Dec-12 1:39
memberMichał Zalewski4-Dec-12 1:39 
GeneralRe: My vote of 5 Pin
Ivan Leonenko4-Dec-12 2:14
memberIvan Leonenko4-Dec-12 2:14 
GeneralMy vote of 5 Pin
RabinDl26-Nov-12 8:18
memberRabinDl26-Nov-12 8:18 
GeneralMy vote of 5 Pin
Akinmade Bond26-Nov-12 7:54
professionalAkinmade Bond26-Nov-12 7:54 
GeneralRe: My vote of 5 Pin
Ivan Leonenko26-Nov-12 9:04
memberIvan Leonenko26-Nov-12 9:04 
GeneralRe: My vote of 5 Pin
Akinmade Bond26-Nov-12 23:47
professionalAkinmade Bond26-Nov-12 23:47 
GeneralMy vote of 5 Pin
dyma26-Nov-12 6:20
memberdyma26-Nov-12 6:20 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web01 | 2.8.181207.3 | Last Updated 8 Mar 2013
Article Copyright 2012 by Ivan Leonenko
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid