Search code examples
c#wpfimageribbonembedded-resource

C#, WPF, Embedded resources/embedded resources


I want a number of resources to be included in the resulting .exe file, such as a number of images. But I have trouble to access these resources (images) from the RibbonCommands in the XAML file.

I have marked the files and changed their properties to "Embedded Resources", but get problem to refer to them in the Code and the XAML file.

For the Main window I have done the following:

Which works!

But the RibbonCommands does not seem to be able to find Embedded resources.

<r:RibbonCommand x:Key="ScanCommand"  
                 LabelTitle="{x:Static const:strings.Scan}"  
                 ToolTipDescription="{x:Static const:strings.ScanToolTip}"  
                 Executed="ScanDisplayUnit"  
                 LargeImageSource="/EasyLink;component/ScanIcon48x48.png"

The error message I got is:

"/EasyLink;component/ScanIcon48x48.png" is not part of the project

Or it's Build Action property is not set to "Resource"

Is it not possible to use "Embedded Resources" in Ribbons?

Is it correctly understood that the different between "Embedded Resource" and "Resource" is that the "Embedded Resource" include the resources in the resulting .exe file but "Resource" does not do this?


Solution

  • I just tested this, and as I thought - the difference between "Embedded Resource" and "Resource" isn't that one embeds the resource in the assembly and one doesn't. They both do.

    I think the main difference is that "Resource" provides a resource management scheme that is more accessible to WPF applications, so that's the option you should be using for your image.