WPF 稀奇古怪的错误记录

以下大多错误可能是由于粗心造成的

1.界面xaml报错

报错截图:

WPF 稀奇古怪的错误记录_第1张图片

造成原因:界面按钮的命令绑定出错

2.水印效果

WPF 稀奇古怪的错误记录_第2张图片

ccf1dd36346a065785588799e4252c4df66.jpg                        166f5e26b7652243b9339dff8c61503203a.jpg

3.绑定的调试姿势

1)最基础的查看输出窗口

WPF 稀奇古怪的错误记录_第3张图片

2)调整跟踪级别

看下面这个例子:


    
		
	

我试图绑定到属性“标题”,但在哪个对象?正如关于数据上下文的文章中所述,WPF将在此处使用TextBlock上的DataContext属性,该属性可以在控件层次结构中继承,但在此示例中,我忘记分配数据上下文。这基本上意味着我正在尝试获取NULL对象的属性。 WPF将收集到这可能是一个完全有效的绑定,但该对象尚未初始化,因此它不会报错。如果运行此示例并查看输出窗口,则不会看到任何绑定错误。

但是,这种情况不是期望的行为,有一种方法可以强制WPF告诉您遇到的所有绑定问题。 可以通过在PresentationTraceSources对象上设置TraceLevel来完成,该对象可以在System.Diagnostics命名空间中找到


    
        
    

 输出的信息如下:

System.Windows.Data Warning: 55 : Created BindingExpression (hash=2902278) for Binding (hash=52760599)
System.Windows.Data Warning: 57 :   Path: 'Title'
System.Windows.Data Warning: 59 : BindingExpression (hash=2902278): Default mode resolved to OneWay
System.Windows.Data Warning: 60 : BindingExpression (hash=2902278): Default update trigger resolved to PropertyChanged
System.Windows.Data Warning: 61 : BindingExpression (hash=2902278): Attach to System.Windows.Controls.TextBlock.Text (hash=18876224)
System.Windows.Data Warning: 66 : BindingExpression (hash=2902278): Resolving source
System.Windows.Data Warning: 69 : BindingExpression (hash=2902278): Found data context element: TextBlock (hash=18876224) (OK)
System.Windows.Data Warning: 70 : BindingExpression (hash=2902278): DataContext is null
System.Windows.Data Warning: 64 : BindingExpression (hash=2902278): Resolve source deferred
System.Windows.Data Warning: 66 : BindingExpression (hash=2902278): Resolving source
System.Windows.Data Warning: 69 : BindingExpression (hash=2902278): Found data context element: TextBlock (hash=18876224) (OK)
System.Windows.Data Warning: 70 : BindingExpression (hash=2902278): DataContext is null
System.Windows.Data Warning: 66 : BindingExpression (hash=2902278): Resolving source
System.Windows.Data Warning: 69 : BindingExpression (hash=2902278): Found data context element: TextBlock (hash=18876224) (OK)
System.Windows.Data Warning: 70 : BindingExpression (hash=2902278): DataContext is null
System.Windows.Data Warning: 66 : BindingExpression (hash=2902278): Resolving source
System.Windows.Data Warning: 69 : BindingExpression (hash=2902278): Found data context element: TextBlock (hash=18876224) (OK)
System.Windows.Data Warning: 70 : BindingExpression (hash=2902278): DataContext is null
System.Windows.Data Warning: 66 : BindingExpression (hash=2902278): Resolving source  (last chance)
System.Windows.Data Warning: 69 : BindingExpression (hash=2902278): Found data context element: TextBlock (hash=18876224) (OK)
System.Windows.Data Warning: 77 : BindingExpression (hash=2902278): Activate with root item 
System.Windows.Data Warning: 105 : BindingExpression (hash=2902278):   Item at level 0 is null - no accessor
System.Windows.Data Warning: 79 : BindingExpression (hash=2902278): TransferValue - got raw value {DependencyProperty.UnsetValue}
System.Windows.Data Warning: 87 : BindingExpression (hash=2902278): TransferValue - using fallback/default value ''
System.Windows.Data Warning: 88 : BindingExpression (hash=2902278): TransferValue - using final value ''

PresentationTraceSources类的介绍

此部分的来源网站

 

转载于:https://my.oschina.net/u/2525682/blog/3099455

你可能感兴趣的:(WPF 稀奇古怪的错误记录)