WPF 动态创建绑定集合到 (all item controls i.e. ComboBox, menu, ListBox etc.).出现cannot find source for binding with reference...的问题
问题描述:
cannot find source for binding with reference 'RelativeSource FindAncestor, AncestorType='System.Windows.Controls.ItemsControl', AncestorLevel='1''. BindingExpression:Path=VerticalContentAlignment; DataItem=null; target element is 'ListBoxItem' (Name=''); target property is 'VerticalContentAlignment' (type 'VerticalAlignment')
这是微软内部的一个error,但是不影响使用,可以忽略不计。相关文档可阅读
https://weblogs.asp.net/akjoshi/resolving-un-harmful-binding-errors-in-wpf
https://stackoverflow.com/questions/160391/listbox-with-grid-as-itemspaneltemplate-produces-weird-binding-errors
http://www.interact-sw.co.uk/iangblog/2007/02/14/wpfdefaulttemplate
经常会出现在,数据源实时刷新,而ItemControl控件还没create Item
//指定由源开关和事件类型筛选器筛选的跟踪消息的级别。(用于解决调试中,线程中实时刷新数据源cannot find source for binding with reference ...)
//https://docs.microsoft.com/zh-cn/dotnet/api/system.diagnostics.sourcelevels?view=net-5.0
// setting the data binding source switch level as critical in constructor of the class or a top level window System.Diagnostics.PresentationTraceSources.DataBindingSource.Switch.Level = System.Diagnostics.SourceLevels.Critical;