wpf 中的无效绑定

设置wpf绑定的跟踪级别为high,output中观察wpf的处理流程:

  • 对于一个无效的绑定,wpf尝试了5次,最后一次设置成了默认值。
  • 所以在程序中要尽量避免无效绑定
<TextBlock Text="{Binding Title, PresentationTraceSources.TraceLevel=High}" />
-------------------------------------------------------------------------------------------------------
System.Windows.Data Warning: 56 : Created BindingExpression (hash=66394201) for Binding (hash=49086616)
System.Windows.Data Warning: 58 :   Path: 'Title'
System.Windows.Data Warning: 60 : BindingExpression (hash=66394201): Default mode resolved to OneWay
System.Windows.Data Warning: 61 : BindingExpression (hash=66394201): Default update trigger resolved to PropertyChanged
System.Windows.Data Warning: 62 : BindingExpression (hash=66394201): Attach to System.Windows.Controls.TextBlock.Text (hash=41050810)

// 1
System.Windows.Data Warning: 67 : BindingExpression (hash=66394201): Resolving source 
System.Windows.Data Warning: 70 : BindingExpression (hash=66394201): Found data context element: TextBlock (hash=41050810) (OK)
System.Windows.Data Warning: 71 : BindingExpression (hash=66394201): DataContext is null
// 延迟重试
System.Windows.Data Warning: 65 : BindingExpression (hash=66394201): Resolve source deferred

// 2
System.Windows.Data Warning: 67 : BindingExpression (hash=66394201): Resolving source 
System.Windows.Data Warning: 70 : BindingExpression (hash=66394201): Found data context element: TextBlock (hash=41050810) (OK)
System.Windows.Data Warning: 71 : BindingExpression (hash=66394201): DataContext is null

// 3
System.Windows.Data Warning: 67 : BindingExpression (hash=66394201): Resolving source 
System.Windows.Data Warning: 70 : BindingExpression (hash=66394201): Found data context element: TextBlock (hash=41050810) (OK)
System.Windows.Data Warning: 71 : BindingExpression (hash=66394201): DataContext is null

// 4
System.Windows.Data Warning: 67 : BindingExpression (hash=66394201): Resolving source 
System.Windows.Data Warning: 70 : BindingExpression (hash=66394201): Found data context element: TextBlock (hash=41050810) (OK)
System.Windows.Data Warning: 71 : BindingExpression (hash=66394201): DataContext is null

// 5 - last chance
System.Windows.Data Warning: 67 : BindingExpression (hash=66394201): Resolving source  (last chance)
System.Windows.Data Warning: 70 : BindingExpression (hash=66394201): Found data context element: TextBlock (hash=41050810) (OK)
System.Windows.Data Warning: 78 : BindingExpression (hash=66394201): Activate with root item <null>
System.Windows.Data Warning: 106 : BindingExpression (hash=66394201):   Item at level 0 is null - no accessor
System.Windows.Data Warning: 80 : BindingExpression (hash=66394201): TransferValue - got raw value {DependencyProperty.UnsetValue}
System.Windows.Data Warning: 88 : BindingExpression (hash=66394201): TransferValue - using fallback/default value ''
System.Windows.Data Warning: 89 : BindingExpression (hash=66394201): TransferValue - using final value ''
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容