asusralis
Topic Author
Posts: 152
Joined: 30 Jul 2018, 05:03

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

16 Nov 2024, 12:01

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.
 
User avatar
jsantos
Site Admin
Posts: 4823
Joined: 20 Jan 2012, 17:18
Contact:

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

18 Nov 2024, 14:44

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?

Who is online

Users browsing this forum: No registered users and 4 guests