如何找到一个绑定错误的来源? [英] How to locate the source of a binding error?
问题描述
我怎样才能找出的XAML行包含的麻烦绑定当我调试输出是完全类似下面的行:
How can I figure out what line of xaml contains the troublesome binding When my debug output is full of lines like the following:
System.Windows.Data错误:5:值由BindingEx pression产生不适用于目标属性;值='UW.Entities.ProgramModel.UWProgram'BindingEx pression:路径=; DataItem的='RuntimeType'(哈希code = 24995901);目标元素是'DataGridCollectionViewSource'(哈希code = 60976864);目标属性是源(类型'对象')
我不知道如何可以让我找到XAML的负责任的行路跨preT这一点。我甚至不能找出XAML文件中的错误的来源。是否有某种方式来获得,当出现这些错误的详细信息?
I don't know how to interpret this in a way that can let me find the responsible line of xaml. I can't even figure out what xaml file the error is coming from. Is there some way to get more information when these errors occur?
UW.Entities.ProgramModel.UWProgram'只是一种 - 我不知道是什么对象绑定到的。我也有很多在XAML的各个位DataGridCollectionViewSources的,谁所有的财产来源,势必一些东西,可能会或可能不会有这种类型的(再次 - 没有简单的方法来告诉)。
'UW.Entities.ProgramModel.UWProgram' is just a type - I don't know what the object being bound to is. I also have lots of DataGridCollectionViewSources in various bits of xaml, all who's property 'Source' is bound to something which may or may not have that type (again - no easy way to tell).
推荐答案
如果您不知道是哪个绑定失败
我会用窥探工具这个目的。总之 - 在右上角,你会发现下拉列表允许过滤器的视觉效果,只要选择的的视觉效果结合错误的。请参见在线文档了解详细信息。
I would use Snoop utility for this purposes. In short - in the top right corner you'll find DropDown list which allows filter visuals, just select Visuals with binding Error. See online documentation for more details.
如果您知道哪个绑定失败
有时你知道哪个绑定失败,但没能找到FO问题的来源,因为绑定是pretty的猫腻,比如TemplateBindings,绑定是指以一个DataContext另一个控制,等等。我发现有用的投入一个的TextBlock
这Text属性绑定到这种方式,你可以看到究竟是什么束缚了相同的结合来源,因为TextBlock中会显示一个绑定对象的类型名称。
Sometime you know which binding fails but was not able to find a source fo the problem since binding is pretty tricky, for instance TemplateBindings, bindings which refer to a DataContext of another control, etc.. I found helpful putting a TextBlock
which Text property is bound to the same binding source in this way you can see what exactly bound since TextBlock will display a type name of a bound object.
例如,你已经失败后绑定:
For instance you have following failed binding:
<ItemsControl ItemsSource="{Binding Parent.DataContext.ActiveItem.DataContext}" />
<!-- See what is bound, if failed - try previous level -->
<TextBlock Text="{Binding Parent.DataContext}" />
<TextBlock Text="{Binding Parent.Inner.Items}" />
<TextBlock Text="{Binding Parent.Inner}" />
相关链接:
- <一个href="http://blogs.msdn.com/b/wpfsldesigner/archive/2010/06/30/debugging-data-bindings-in-a-wpf-or-silverlight-application.aspx">Debugging数据绑定在WPF和Silverlight应用程序
- 在使用特殊DebugConverter允许打破一个调试器,同时做一个绑定好的招,看的调试WPF数据绑定文章
- Debugging Data Bindings in a WPF or Silverlight Application
- Nice trick using special DebugConverter which allows break a debugger whilst doing a binding, see Debugging WPF DataBinding article
这篇关于如何找到一个绑定错误的来源?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!