How to track WPF binding errors?

We have a very big project. Visual Studio Debug Output Log contains several recurring WPF binding errors. For example:

System.Windows.Data error: 5: The value generated by BindingExpression is not valid for the target property; Value = "NaN" BindingExpression: Path = Width; DataItem = 'ContentPresenter' (Name = ''); target element - "ContentPresenter" (Name = ''); target is "MaxWidth" (type "Double")

Lines are printed when an action is performed. However, this is a very difficult operation involving dozens of WPF classes.

Is there a quick way to find the exact source of a binding error? Which tool can help?

+6
c # wpf binding
source share
1 answer

The error you see is due to the fact that the MaxWidth element of the control is bound to the Width another control. MaxWidth must have a specific numeric value, but Width may have a few undefined values, depending on the layout used. In this case, the width of the NaN source control is an invalid value for MaxWidth . This causes an error.

So, I would look for a binding to a control in which you set MaxWidth="{Binding Width, ElementName=someElement}" or the like.

Guessing that the binding was put in place because the control is contained in a layout panel such as a StackPanel , which does not limit the size of its children, but someone tried to bind MaxWidth to deal with clipping problems. The best solution is to switch to the control panel, which limits its size to content.

The operation that is performed is most likely not related to an error in this case, except that it seems to be invalid for your layout.

+5
source share

All Articles