Page 1 of 1

Is it possible to set a resource's source in a ResourceDictionary by asset reference instead of a uri in Unity?

Posted: 16 Nov 2024, 12:01
by asusralis
When you create a BitmapImage in a ResourceDictionary, you have to use a string to set the path of the resource:
<BitmapImage x:Key="Image.Icon.xxx" UriSource="xxx.png"/>
This can easily break if you move around the assets in your project. A better way would be to declare the BitmapImage in XAML, but set the resource through the editor like this:
Unity_XHXXg8OG1K.png
However, it seems you can't see resources in this window; it's read-only. It would save a lot of time, and avoid potential issues in the future, if we could just set the resources in this window.

Re: Is it possible to set a resource's source in a ResourceDictionary by asset reference instead of a uri in Unity?

Posted: 18 Nov 2024, 14:44
by jsantos
That view is read-only and displays the dependencies for your XAML.

One approach you could take is to expose a dictionary of images in your data context and bind to it from your XAML. The dictionary could be fully populated within Unity.

Would that solution work for your needs?