Question

Greetings,

As I create WPF application I obviously use lots of bindings. However I figured out that generally I don't use FallbackValue property.

My question is: should I always set Fallback value event if it should be: FallbackValue="" ?

What is the impact in memory/performance/others when using/not using FallbackValue?

Was it helpful?

Solution

I personally recommend providing FallbackValue where you don't depend on the load to provide the functionality unless you are certain that the load will never fail. There are multiple ways for a load to fail, and if your image etc. don't really affect functionality, it is harsh to your user to fail the program just because your company's logo happens not to load due to a corrupted file, or something...

However, if you need the resource for your functionality, you should not provide a fallback value but should trap the exception and handle it.

FallbackValue can also be used in priority image sources. Here, you fire off an async load of a resource somewhere else (possible over the Internet), and before the load is complete, your fallback value will be available. For example, you can use the fallback value to provide a place-holder image before your images come back. And if the image load (off the Internet) fails, you have a place-holder in place instead of a blank space -- sometimes having a blank space is not acceptable because of screen element sizing issues (things will disappear when having no size).

As for performance considerations, I have not sensed much degrading of performance due to fallback resources. However, please understand that if the resource is loaded async, then you're essentially loading two resources instead of one -- but the fallback is usually a local resource so impact to performance should be minimal.

OTHER TIPS

You should hardly ever use FallbackValue.

If you've set everything up correctly, then the databinding should never fail, so the fallbackvalue should never be seen.

The biggest performance problem that will hit you here is the cost of a failed databinding (these usually involve exceptions and are much costlier than sucessful bindings). Making use of FallbackValue could hide such performance problems. Therefore I'd argue that using FallbackValue is generally going to make performance worse (but as always, it depends)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top