Getting many Binding “Information” in WPF output window

后端 未结 2 400
夕颜
夕颜 2020-12-10 20:24

When I start my app I get a lot of information like this:

System.Windows.Data Information: 10 : Cannot retrieve value using the binding and 
no valid fallbac         


        
相关标签:
2条回答
  • 2020-12-10 21:06

    Yes, you should. It is safest to treat binding feedback (information, errors, etc) just like compiler warning and errors. Binding issues tend to slow the execution of the application down since it forces bindings to be re-evaluated, and in my experience, sometimes breaks them to where you need to recreate the binding in code.

    The simplest workaround, if you can, is to set the FallbackValue on your binding to a value which can be treated as default. For example, if you have a class which has a "Count" property, but said class can be null at some point in time when your view is created, your binding might look like <TextBlock Text={Binding Count, FallbackValue=0} /> which would display a "0" in the text block, or pass the fallback value to the converter if there is one in use.

    0 讨论(0)
  • 2020-12-10 21:06

    I agree with Hugo that its nice if we can consider all the feedback given by bindings; but personally I don't think Information type trace messages are that harmful. You definitely need to solve the binding problems marked as Error and Warnings.

    I got binding information like this -

    System.Windows.Data Information: 20 : BindingExpression cannot retrieve value due to missing information. BindingExpression:Path=PlacementTarget.DataContext.RemoveCommand; DataItem='ContextMenu' (Name=''); target element is 'MenuItem' (Name=''); target property is 'Command' (type 'ICommand')

    Now, inside context menu its necessary to use PlacementTarget and unless you open the context menu this binding won't work;

    I have tried to find out some credible source which mentions exact impact of these Information messages, but didn't found any. The link provided by Hugo also mentions Error type output -

    Fix BindingExpression path errors

    If, when debugging your WPF application, you see errors in the output window like:

    System.Windows.Data Error: 40 : BindingExpression path error: 'AcquireFocus' property not found on 'object' ''DataSource' (HashCode=61327894)'. BindingExpression:Path=AcquireFocus; DataItem='DataSource' (HashCode=61327894); target element is 'VsButton' (Name=''); target property is 'AcquireFocus' (type 'Boolean')*

    then, as well as a broken data-binding, you may have a performance problem. WPF tries several different ways to resolve path errors, including searching for attached properties and this is quite expensive. Eliminate all such warnings, and you should be good. Visual Studio 2010 has new options for debugging WPF databindings.

    http://blogs.msdn.com/b/visualstudio/archive/2010/03/02/wpf-in-visual-studio-2010-part-2-performance-tuning.aspx

    0 讨论(0)
提交回复
热议问题