Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Mahhala – WPF NotifyIcon

0.00/5 (No votes)
12 Aug 2010 1  
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.”

XML
<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 has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here