0

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?

Maverick Meerkat
  • 5,737
  • 3
  • 47
  • 66
  • 1
    Did you try to put in the Source the absolute path, instead of relative? – Mishka Sep 26 '17 at 12:57
  • Set the Build Action of the image files to `Resource`, then remove the `../..` part from the paths. – Clemens Sep 26 '17 at 13:00
  • Try the following path: Source="/Resources/Icons/Tray-menu-icons-open.ico.png">. Or: Source="pack://application:,,,/Resources/Icons/Tray-menu-icons-open.ico.png". Are your images really named ".ico.png"? – mm8 Sep 26 '17 at 13:01
  • @Mishka You're right - that was the problem... I don't understand it, as intellisense gave me the option to complete it. – Maverick Meerkat Sep 26 '17 at 13:03

1 Answers1

0

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.

mm8
  • 163,881
  • 10
  • 57
  • 88
  • 2
    Where the `pack://application:,,,` prefix isn't actually necessary in XAML, because it is added automatically. So the "absolute path" is implicitly also an assembly Resource File Pack URI. – Clemens Sep 26 '17 at 19:34