Debug WPF issues by using PresentationTraceSources

May include but is not limited to: animation, data binding, dependency properties

Since .NET 3.5, we get a nice and neat class, PresentationTraceSources to debug some kinds of WPF-specific things, like animation, data binding and dependency properties. To make it work, first you’ll need to set a reference to the CLR namespace System.Diagnostics in your XAML code. This is how could it be done:

<Window xmlns:diag=”clr-namespace:System.Diagnostics;assembly=WindowBase” />

Then with the new XML schema prefix diag, you can use PresentationTraceSources to emit error information. You should use the attached property TraceLevel, which is an enumeration, with the following members:

  • None: no additional information will be emitted.
  • Low: traces some additional information.
  • Medium: traces a medium amount of additional information.
  • High: traces all additional information.

All hail MSDN, the best resource available. I liked the explanation very much, and copied it here, so you’ll all know that TraceLevel.Medium produces medium amount of additional information. What a shame that we won’t know what counts to be additional, and what is just basic info.

Anyway, the attached property can be set on the following classes: BindingBase and its derivatives, BindingExpressionBase and the derived types, Object- and XmlDataProvider. Oh, and an example on how to use this property:

  <Binding Path=”myProperty” diag:PresentationTraceSources.TraceLevel=”Low” />

Tags: , ,

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: