Search code examples
c#wpftrayicon

How to show image/icon in taskbar context menu


I'm using Hardcodet NotifyIcon, and I want to display images next to my context menu items. But for some reason they don't appear.

This is the code

<tb:TaskbarIcon x:Name="MyNotifyIcon" Icon="{x:Static p:Resources.frame_01}" ToolTipText="hello world">
    <tb:TaskbarIcon.TrayToolTip>
        <TextBlock Text="{x:Static p:Resources.TraybarTitle}" HorizontalAlignment="Center" VerticalAlignment="Center" />
    </tb:TaskbarIcon.TrayToolTip>

    <tb:TaskbarIcon.ContextMenu>
        <ContextMenu Background="{StaticResource JITB.SolidColors.Cyan}">
            <MenuItem Click="Menu_Open">
                <MenuItem.Header>
                    <TextBlock Text="Open" Foreground="White"/>
                </MenuItem.Header>
                <MenuItem.Icon>
                    <Image HorizontalAlignment="Left" Source="../../Resources/Icons/Tray-menu-icons-open.ico.png"></Image>
                </MenuItem.Icon>
            </MenuItem>
            <MenuItem Click="Menu_Close">
                <MenuItem.Header>
                    <TextBlock Text="Close" Foreground="White"/>
                </MenuItem.Header>
                <MenuItem.Icon>
                    <Image Source="../../Resources/Icons/Tray-menu-icons-close.ico.png"></Image>
                </MenuItem.Icon>
                </MenuItem>
        </ContextMenu>
    </tb:TaskbarIcon.ContextMenu>
</tb:TaskbarIcon>

And this is the result:

enter image description here

As you can see - no images!

What am I doing wrong?


Solution

  • Try to use a pack URI:

    <Image HorizontalAlignment="Left" Source="pack://application:,,,/Resources/Icons/Tray-menu-icons-open.ico.png" />
    

    Or an absolute path:

    <Image HorizontalAlignment="Left" Source="/Resources/Icons/Tray-menu-icons-open.ico.png" />
    

    Also make sure that the Build Action properties of the images have been set to "Resource" and that the path and file name is correct.