0

I want to define an Icon for a MenuItem in XAML.

Providing the full path works fine, but all examples shown in the documentation use a relative file spec The following code shows the two probablities. The upper sample does not show the icon (and it does not matter if you use a backslash \ or a normal slash / or you provide it like ../xxx.yyy ) but the second sample with the full path works fine.

{
...
    <MenuItem x:Name="MENItemSelBaseDir" Header="_Select Base Directory"    Click="MENItemSelBaseDir_Click" >
        <MenuItem.Icon>
            <Image Source="/images/FolderOpen.png"/>
        </MenuItem.Icon>
    </MenuItem>
    <MenuItem x:Name="MENItemShowVariables" Header="_Show project variables" Click="MENItemShowVariables_Click" >
    <MenuItem.Icon>
        <Image Source="D:\C#Prog\WPFProjekte\WPF_CFG\images\Parameter.ico"/>
    </MenuItem.Icon>
    </MenuItem>
...
}

How to use a relative path instead of an absolute path ?

Many thanks for any hint Wolfgang

大陸北方網友
  • 3,526
  • 3
  • 9
  • 31
  • The image file should be included in your Visual Studio project with a Build Action set to Resource. Then load it by a [Resource File Pack URI](https://docs.microsoft.com/en-us/dotnet/desktop/wpf/app-development/pack-uris-in-wpf?view=netframeworkdesktop-4.8). – Clemens Mar 28 '22 at 07:38

0 Answers0