Rocko Bonaparte
Topic Author
Posts: 30
Joined: 13 Oct 2020, 08:32

Image paths in XAML, BitmapImage in models?

17 Jan 2021, 22:04

My image bindings aren't failing in Unity but they aren't drawing either. I'm binding to Uris that map to the images I want to show. I don't see anything this way.

I was wading through the samples and I think I see a certain convention that I wanted to confirm. Images with static paths defined directly in XAML can be sourced directly with text. For images influenced by a model, it looks like the image source is being set by a BitmapImage. Is this the convention? If so, I'd have to change my binding from a Uri property to a BitmapImage property. I wanted to confirm before refactoring for what might be nothing.

Tags:
 
User avatar
sfernandez
Site Admin
Posts: 2254
Joined: 22 Dec 2011, 19:20

Re: Image paths in XAML, BitmapImage in models?

18 Jan 2021, 11:44

My image bindings aren't failing in Unity but they aren't drawing either. I'm binding to Uris that map to the images I want to show. I don't see anything this way.
I was wading through the samples and I think I see a certain convention that I wanted to confirm. Images with static paths defined directly in XAML can be sourced directly with text. For images influenced by a model, it looks like the image source is being set by a BitmapImage. Is this the convention? If so, I'd have to change my binding from a Uri property to a BitmapImage property. I wanted to confirm before refactoring for what might be nothing.
This is probably because those images are not dependencies of any loaded xaml, so they won't be available for loading when playing. For this situations you can add explicit dependencies in any xaml by using Xaml.Dependencies as explained here: https://www.noesisengine.com/docs/Gui.C ... tml#assets

Or you can expose Unity's Texture2D directly in your Unity view model (as we do in our DataBinding sample). In this case you will be responsible of loading the texture in Unity (using Resources.Load) or by having the view model accessible from Unity's inspector and setting the textures there so they are correctly referenced by the scene. The texture property is automatically translated by Noesis into an ImageSource you can bind to an Image or ImageBrush.
 
Rocko Bonaparte
Topic Author
Posts: 30
Joined: 13 Oct 2020, 08:32

Re: Image paths in XAML, BitmapImage in models?

18 Jan 2021, 19:10

Thanks for responding. I was about to just post that I figured it out when I saw you replied hahaha. In my case, the images are ultimately dynamic. I was trying to use a placeholder while messing around that wasn't dynamic per-se, but it would be dynamic as far as Unity/Noesis/WPF is concerned since I was defining it in the source code outside of the awareness of any XAML. It's just that WPF lets me source from any old path while Unity is more strict to keep it within the domains of the project and also as a texture asset.

I figured that out per the Texture2D loading instructions:
https://www.noesisengine.com/docs/Gui.C ... orial.html
(under Runtime Images)

The sample image I used has a screwed up thing going on with alpha but that's documented too and the final image won't have an alpha so I think I got it well enough to proceed with integration.

Who is online

Users browsing this forum: Google [Bot] and 2 guests