Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to reference an asset in class library in UWP with XAML syntax

I have a class library with a custom control in UWP. There is an asset image.png that is in the class library under the folder Assets

I want to display this image in the custom control using xaml syntax in generic.xaml inside the class library.

like image 248
troty_master Avatar asked Aug 16 '18 14:08

troty_master


1 Answers

That took me quite a while to solve, so I am posting the outcome for future explorers of the topic since I didn't manage to find a good solution anywhere.

Location of the files is: ClassLibraryName/Assets/image.scale-100.png ClassLibraryName/Assets/image.scale-150.png etc.

Build action: Content Copy to Output Directory: Do not Copy

In generic.xaml I have this now and the image loads correctly: Image Source="../ClassLibraryName/Assets/image.png"

It also works like this: Image Source="ms-appx:///ClassLibraryName/Assets/image.png"

like image 132
troty_master Avatar answered Sep 28 '22 16:09

troty_master