We have a very large project. The Visual Studio debug output log contains several repeating WPF binding errors.
For example:
System.Windows.Data Error: 5 : Value produced by BindingExpression is not valid for target property.; Value='NaN' BindingExpression:Path=Width; DataItem='ContentPresenter' (Name=''); target element is 'ContentPresenter' (Name=''); target property is 'MaxWidth' (type 'Double')
The lines are printed when some action is performed. However, this is a very heavy operation, in which tens of WPF classes are involved.
Is there a quick way to find the exact source of the binding error? Some tool which might help?
To enable this experience, go to “Options > Environment > Preview Features”, “XAML Binding Failure Window” and restart Visual Studio.
Navigate to Tools –> Options –> Debugging –> General –> Enable UI Debugging Tools for XAML . In case you are not able to inspect you xaml and not able to see it in Live property explorer you need to check it. With the option selected, the both xaml inspection and live visual tree work seamlessly for any xaml debugging.
ItemsSource can be data bound to any sequence that implements the IEnumerable interface, although the type of collection used does determine the way in which the control is updated when items are added to or removed.
The error you're seeing is because the MaxWidth
of a control is being bound to the Width
of another control. MaxWidth
has to have a definite numeric value, but Width
can have several non-definite values, depending on the layout being used. In this case, the width of the source control is NaN
- which is an invalid value for MaxWidth
. That's causing the error.
So, I'd be looking for a binding on a control where you're setting MaxWidth="{Binding Width, ElementName=someElement}"
, or similar.
At a guess, that binding has been put in place because a control is contained within a layout panel like a StackPanel
that doesn't constrain the size of its children, and someone's tried to bind MaxWidth
to deal with clipping issues. A better solution is to change to a panel control that constrains its content size.
The operation that's being performed is likely nothing to do with the error in this case, except that it seems to be invalidating your layout.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With