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 ''
最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容