美文网首页
wpf 中的无效绑定

wpf 中的无效绑定

作者: ichengzi | 来源:发表于2017-06-14 17:59 被阅读26次

    设置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 ''
    

    相关文章

      网友评论

          本文标题:wpf 中的无效绑定

          本文链接:https://www.haomeiwen.com/subject/ffleqxtx.html