Click here to Skip to main content
15,885,278 members
Articles / Desktop Programming / WPF

WPF NotifyIcon

Rate me:
Please Sign up or sign in to vote.
4.98/5 (483 votes)
23 Nov 2013CPOL16 min read 1.8M   48.5K   704  
A NotifyIcon for WPF that leverages several features of the platform
<Window x:Class="Samples.Tutorials.MvvmSample.MvvmSampleWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:local="clr-namespace:Samples.Tutorials.MvvmSample"
        xmlns:tb="http://www.hardcodet.net/taskbar"
        Title="MvvmSampleWindow"
        Height="300"
        Width="300">
    <Window.DataContext>
        <local:MvvmSampleViewModel />
    </Window.DataContext>
    <Grid>


        <!-- 
            the NotifyIcon automatically derives the DataContext of it's
            declaring view. Alternatively, you could just assign it manually
        -->
        <tb:TaskbarIcon IconSource="/Icons/Inactive.ico"
                        ToolTipText="{Binding Timestamp}">
            <tb:TaskbarIcon.TrayPopup >
                <!-- the popup, here a custom user control, will also get the DataContext of the NotifyIcon -->
                <local:ClockPopup Opacity="0.8" />
            </tb:TaskbarIcon.TrayPopup>
        </tb:TaskbarIcon>
        
        
        
        <TextBlock TextWrapping="Wrap"
                   Text="MVVM is quite simple - content of the NotifyIcon derive its DataContext. Sample: Hover over the icon in order to see the bound ToolTipText. Click for a richer Popup that is bound to the same property."
                   HorizontalAlignment="Left"
                   VerticalAlignment="Top"
                   Margin="10,10,10,0" />


    </Grid>
</Window>

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

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


Written By
Architect I'm a gun for hire
Switzerland Switzerland
Philipp is an independent software engineer with great love for all things .NET.
He lives in Winterthur, Switzerland and his home on the web is at http://www.hardcodet.net.

Comments and Discussions