Click here to Skip to main content
Click here to Skip to main content

Mahhala – WPF NotifyIcon

, 12 Aug 2010
Rate this:
Please Sign up or sign in to vote.
WPF NotifyIcon

Mahhala (isiZulu word for free or without charge) is a new series that showcases some of the cool free WPF/Silverlight controls available…

“You can learn a lot by reading other people's source code. That's the idea behind this series, "The Weekly Source Code." You can certainly become a better programmer by writing code but I think good writers become better by reading as much as they can.” - Scott Hanselman

This week I am very fortunate to be chatting with Philipp Sumi, the creator of WPF NotifyIcon.

RG - Welcome Philipp, please tell us a little about yourself?
PS - I'm a developer/architect/geek without work/life balance, a (yet) unofficially diagnosed code addiction and great love for all things .NET. I'm working as a freelancer and consultant in Switzerland and dream of spending European winter months creating cool software in sunny New Zealand or Australia (hint hint).

RG - What is WPF NotifyIcon?
PS - At its core, it's basically a wrapper around the Win32 API that enables you to display a NotifyIcon in the system tray area. However, it goes quite a bit beyond that core functionality by bringing WPF into the picture. Besides the tray icon, the developer can easily display rich tool tips, interactive popups, context menus or balloon messages in the tray area. All that functionality is exposed through a convenient API that should feel familiar for every WPF developer.

I came up with the control because I wanted to provide a rich user experience for a tool (NetDrives) that was supposed to run mainly in the background, but allows the user to quickly access some core functionality through the system tray. The existing WinForms component was too limited for my needs, so I wrote my own.

RG - How does your implementation compare with what is available in the new SL4 toast messages?
PS - Besides the different platforms (SL vs. WPF), Silverlight's toasts are basically a simple version of what's called a "balloon message" in the WPF control. You don't get all the other good stuff.

RG - Where can people get a hold of you?
PS - Placing bear traps in front of big computer screens has proven to be quite a successful strategy. For the more subtle, there's a contact form on my blog (http://www.hardcodet.net/contact) that should produce a near-immediate (although less vocal) response as well.

Although I use WPF NotifyIcon 90% of the time for balloon popups, the more compelling scenario is when you use WPF content inside the balloon or popup…

“Unlike a ToolTip, a Popup is only displayed if the user clicks on the NotifyIcon. It stays open if the user moves the mouse away from the tray area, but will close as soon as the user clicks somewhere else. Accordingly, you can provide interactive content within a Popup, usually to provide some quick access to your application.”

<hc:TaskbarIcon ToolTip="ToolTip">
    <hc:TaskbarIcon.TrayPopup>                
        <Border Background="#FAFFFFFF" Width="200" Height="75"
                CornerRadius="5,5,5,5">
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition Height="30" />
                    <RowDefinition Height="*" />
                    <RowDefinition Height="10" />
                </Grid.RowDefinitions>
                <Border Background="Blue" CornerRadius="5,5,0,0" Grid.Row="0" />
                <Border Background="Blue" CornerRadius="0,0,5,5" Grid.Row="2" />
                
                <TextBlock Text="WPF NotifyIcon" Foreground="White" 
			Grid.Row="0" HorizontalAlignment="Left" 
                           VerticalAlignment="Center" Margin="5,0,0,0" FontWeight="Bold">
                    <TextBlock.Effect>
                        <DropShadowEffect />
                    </TextBlock.Effect>
                </TextBlock>
                <TextBlock Text="Very cool, huh?" Grid.Row="1" HorizontalAlignment="Left" 
                           VerticalAlignment="Center" Margin="5,0,0,0" />
            </Grid>                    
        </Border>
    </hc:TaskbarIcon.TrayPopup>
</hc:TaskbarIcon>

And here is how it looks…

For more information, read this cool CodeProject article and for a practical example of using WPF NotifyIcon in a PRISM/MVVM application, check out OpenPOS!

Next week I chat with Pavan Podila, the creator of FluidKit.

License

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

About the Author

rudigrobler

South Africa South Africa
No Biography provided

Comments and Discussions

 
-- There are no messages in this forum --
| Advertise | Privacy | Mobile
Web02 | 2.8.140721.1 | Last Updated 12 Aug 2010
Article Copyright 2010 by rudigrobler
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid