Joe
Joe

Reputation: 6816

Any use in supplying FallbackValue to working WPF bindings to eliminate warnings?

Today I was testing a UserControl which works well. On a whim, I changed the output window WPF Trace Setting for "Data Binding" from "Warning" to "All" and tested again, just to see what I was missing.

As you might expect, my output window really started filling up with a whole lot of messages. For example

System.Windows.Data Information: 10 : Cannot retrieve value using the binding and no valid fallback value exists; using default instead. BindingExpression:Path=Image; DataItem=null; target element is 'Image' (Name='CurrentImage'); target property is 'Source' (type 'ImageSource')

No big deal. I know the binding works well. My image shows up just fine But here is the relevant XAML

<!--Image is drawn first, underneath everything else.

<Image x:Name="CurrentImage" 
       Canvas.Left="0" Canvas.Top="0"
       Source="{Binding Image}"
       Loaded="CurrentImage_OnLoaded"
       />

To satisfy my curiosity, I decided to try to eliminate this message with a Fallback value to see if there was any effect.. And I was certainly able to using x:Null (I suppose I could have also use a static resource imagesource...)

<Image x:Name="CurrentImage" 
       Canvas.Left="0" Canvas.Top="0"
       Source="{Binding Image, FallbackValue={x:Null}}"
       Loaded="CurrentImage_OnLoaded"
       /> 

The message went away and the control worked... exactly as it did before.

(This might be a poor example as it's not a "warning" but I also occasionally have "warning" and even "error" level messages appearing from other parts that similarly works just fine all the time.)

So I was wondering: Is there any real value in eliminating such messages with default values? Will WPF work any faster or better if I do this regularly?

Or is there some message level (warning, error, critical informational) at which I should make it my task to do so and beyond which I should ignore these?

Or should I just go back to real problems take these on a case by case basis?

Upvotes: 1

Views: 604

Answers (1)

mm8
mm8

Reputation: 169330

Is there any real value in eliminating such messages with default values?

No.

Will WPF work any faster or better if I do this regularly?

You should eliminate any actual binding errors in your code/markup and let the framework take care of the rest. The framework does produce some harmless binding errors that you can't do much about besides ignoring or supress them.

Or should I just go back to real problems take these on a case by case basis?

Yes. There is no reason to focus on trying to fix non-issues that you aren't even responsible for in the first place.

Upvotes: 1

Related Questions