Question Can FallbackValue be used for an image's Source property?

glasswizzard

Well-known member
Joined
Nov 22, 2019
Messages
126
Programming Experience
Beginner
I'm trying to get this line of code to work:

C#:
<Image x:Name="ViewBoxImage" Source="{Binding ViewBoxImageSource, FallbackValue=../Resources/Images/ViewBoxImageName.png}"/>

That would be inside a viewbox. I don't know if FallbackValue doesn't work with an image source or if I'm typing it out wrong, but I can't get it to work. I want to see the image at design time, that's why I'm doing this.
 
A fallbackvalue will only be used if the binding source can't resolve to the path you gave for what ever reason.

I may stand corrected but the return type of the fallbackvalue is an object. Are you getting any errors at all? Or runtime errors?

Mobile reply
 
No, no errors or anything. The bindings never apply at design time so the only way to see an image is by using FallbackValue as far as I can tell.
 
Try this answer on SO : How to set FallbackValue in binding as path to external image file?

Does that work for you? May I ask which documentation have you been reading regarding the fallback value?

I do know from past experience, there are pages in Microsoft's docs under Xamarin which demonstrate using the fallbackvalue with images. Perhaps, you should be searching and scouring the docs on that one.
 
That solution works great, it needed to be a static resource. Thank you.

I watched a youtube video (that's where I first heard of the fallbackvalue attribute) then I did a google search on it and it seems I just found the basic usage. When I ran into my specific problem I did not manage to find a solution but I figured it was because the fallback attribute was getting the wrong type somehow. I must not have been specific enough or something with my search string.

Before I knew that the fallbackvalue attribute existed I tried to search for a way to make controls collapsed at design time, I failed completely to find the fallbackvalue attribute but one day I just happened to watch a video (on some different subject) where someone used it and mentioned what it does. I tried so hard to find that, not knowing it's name of course, and failed. My google skills don't seem be up to par, or maybe google just hates me :)
 
Back
Top Bottom