System.Diagnostics.PresentationTraceSources.SetTraceLevel() 方法的使用
Use of System.Diagnostics.PresentationTraceSources.SetTraceLevel() method
我阅读了 SetTraceLevel() method 的文档,但无法从那两行文档中得到任何信息。
谁能解释一下。
我只在绑定上使用它,不确定是否are/aren没有任何其他方式可以使用它...
在XAML中,添加命名空间:
xmlns:diag="clr-namespace:System.Diagnostics;assembly=WindowsBase"
然后,您可以在绑定中设置跟踪级别:
<TextBox Text="{Binding Path=TextField, UpdateSourceTrigger=PropertyChanged, diag:PresentationTraceSources.TraceLevel=High}" />
仅供参考 - Intellisense 似乎无法协助输入。
如果您想在代码中执行此操作并使用您链接的方法:
TextBox tb = new TextBox();
Binding b = new Binding();
b.Path = new PropertyPath("TextField", new object[] { });
b.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged;
System.Diagnostics.PresentationTraceSources.SetTraceLevel(b, System.Diagnostics.PresentationTraceLevel.High);
tb.SetBinding(TextBox.TextProperty, b);
无论哪种方式,跟踪都会显示在 VS 2015 的输出中 window(VM 是 DataContext,'This is a test.' 是 属性 TextField 的默认值)。
System.Windows.Data Warning: 56 : Created BindingExpression (hash=25035015) for Binding (hash=19986012)
System.Windows.Data Warning: 58 : Path: 'TextField'
System.Windows.Data Warning: 60 : BindingExpression (hash=25035015): Default mode resolved to TwoWay
System.Windows.Data Warning: 62 : BindingExpression (hash=25035015): Attach to System.Windows.Controls.TextBox.Text (hash=23243381)
System.Windows.Data Warning: 67 : BindingExpression (hash=25035015): Resolving source
System.Windows.Data Warning: 70 : BindingExpression (hash=25035015): Found data context element: TextBox (hash=23243381) (OK)
System.Windows.Data Warning: 78 : BindingExpression (hash=25035015): Activate with root item VM (hash=48624771)
System.Windows.Data Warning: 108 : BindingExpression (hash=25035015): At level 0 - for VM.TextField found accessor RuntimePropertyInfo(TextField)
System.Windows.Data Warning: 104 : BindingExpression (hash=25035015): Replace item at level 0 with VM (hash=48624771), using accessor RuntimePropertyInfo(TextField)
System.Windows.Data Warning: 101 : BindingExpression (hash=25035015): GetValue at level 0 from VM (hash=48624771) using RuntimePropertyInfo(TextField): 'This is a test.'
System.Windows.Data Warning: 80 : BindingExpression (hash=25035015): TransferValue - got raw value 'This is a test.'
System.Windows.Data Warning: 89 : BindingExpression (hash=25035015): TransferValue - using final value 'This is a test.'
更改文本框中的文本(添加另一个“.”)会导致此输出:
System.Windows.Data Warning: 90 : BindingExpression (hash=25035015): Update - got raw value 'This is a test..'
System.Windows.Data Warning: 94 : BindingExpression (hash=25035015): Update - using final value 'This is a test..'
System.Windows.Data Warning: 102 : BindingExpression (hash=25035015): SetValue at level 0 to VM (hash=48624771) using RuntimePropertyInfo(TextField): 'This is a test..'
System.Windows.Data Warning: 95 : BindingExpression (hash=25035015): Got PropertyChanged event from VM (hash=48624771)
System.Windows.Data Warning: 101 : BindingExpression (hash=25035015): GetValue at level 0 from VM (hash=48624771) using RuntimePropertyInfo(TextField): 'This is a test..'
System.Windows.Data Warning: 80 : BindingExpression (hash=25035015): TransferValue - got raw value 'This is a test..'
System.Windows.Data Warning: 89 : BindingExpression (hash=25035015): TransferValue - using final value 'This is a test..'
编辑:
https://msdn.microsoft.com/en-us/library/system.diagnostics.presentationtracesources(v=vs.100).aspx
看起来它应该适用于其他一些事情,而不仅仅是绑定。
我阅读了 SetTraceLevel() method 的文档,但无法从那两行文档中得到任何信息。
谁能解释一下。
我只在绑定上使用它,不确定是否are/aren没有任何其他方式可以使用它...
在XAML中,添加命名空间:
xmlns:diag="clr-namespace:System.Diagnostics;assembly=WindowsBase"
然后,您可以在绑定中设置跟踪级别:
<TextBox Text="{Binding Path=TextField, UpdateSourceTrigger=PropertyChanged, diag:PresentationTraceSources.TraceLevel=High}" />
仅供参考 - Intellisense 似乎无法协助输入。
如果您想在代码中执行此操作并使用您链接的方法:
TextBox tb = new TextBox();
Binding b = new Binding();
b.Path = new PropertyPath("TextField", new object[] { });
b.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged;
System.Diagnostics.PresentationTraceSources.SetTraceLevel(b, System.Diagnostics.PresentationTraceLevel.High);
tb.SetBinding(TextBox.TextProperty, b);
无论哪种方式,跟踪都会显示在 VS 2015 的输出中 window(VM 是 DataContext,'This is a test.' 是 属性 TextField 的默认值)。
System.Windows.Data Warning: 56 : Created BindingExpression (hash=25035015) for Binding (hash=19986012)
System.Windows.Data Warning: 58 : Path: 'TextField'
System.Windows.Data Warning: 60 : BindingExpression (hash=25035015): Default mode resolved to TwoWay
System.Windows.Data Warning: 62 : BindingExpression (hash=25035015): Attach to System.Windows.Controls.TextBox.Text (hash=23243381)
System.Windows.Data Warning: 67 : BindingExpression (hash=25035015): Resolving source
System.Windows.Data Warning: 70 : BindingExpression (hash=25035015): Found data context element: TextBox (hash=23243381) (OK)
System.Windows.Data Warning: 78 : BindingExpression (hash=25035015): Activate with root item VM (hash=48624771)
System.Windows.Data Warning: 108 : BindingExpression (hash=25035015): At level 0 - for VM.TextField found accessor RuntimePropertyInfo(TextField)
System.Windows.Data Warning: 104 : BindingExpression (hash=25035015): Replace item at level 0 with VM (hash=48624771), using accessor RuntimePropertyInfo(TextField)
System.Windows.Data Warning: 101 : BindingExpression (hash=25035015): GetValue at level 0 from VM (hash=48624771) using RuntimePropertyInfo(TextField): 'This is a test.'
System.Windows.Data Warning: 80 : BindingExpression (hash=25035015): TransferValue - got raw value 'This is a test.'
System.Windows.Data Warning: 89 : BindingExpression (hash=25035015): TransferValue - using final value 'This is a test.'
更改文本框中的文本(添加另一个“.”)会导致此输出:
System.Windows.Data Warning: 90 : BindingExpression (hash=25035015): Update - got raw value 'This is a test..'
System.Windows.Data Warning: 94 : BindingExpression (hash=25035015): Update - using final value 'This is a test..'
System.Windows.Data Warning: 102 : BindingExpression (hash=25035015): SetValue at level 0 to VM (hash=48624771) using RuntimePropertyInfo(TextField): 'This is a test..'
System.Windows.Data Warning: 95 : BindingExpression (hash=25035015): Got PropertyChanged event from VM (hash=48624771)
System.Windows.Data Warning: 101 : BindingExpression (hash=25035015): GetValue at level 0 from VM (hash=48624771) using RuntimePropertyInfo(TextField): 'This is a test..'
System.Windows.Data Warning: 80 : BindingExpression (hash=25035015): TransferValue - got raw value 'This is a test..'
System.Windows.Data Warning: 89 : BindingExpression (hash=25035015): TransferValue - using final value 'This is a test..'
编辑:
https://msdn.microsoft.com/en-us/library/system.diagnostics.presentationtracesources(v=vs.100).aspx
看起来它应该适用于其他一些事情,而不仅仅是绑定。