Thursday 9 August 2012

TraceListeners, Data Bindings, Styles etc

Its been a while since I've posted and this is more of a link dump than anything else to aid other people debugging their applications.  WPF is a complicated beast and sometimes debugging (bindings, styles, etc) can be a tiresome task.  Here are a bunch of links to useful information about the web:
Dependency Properties might be set in multiple places - this is an article on MSDN describing precedence in setting dependency properties in styles or XAML.  The main take-home thing to remember here is that styles do not override values set for dependency properties at the XAML level.  You'll see that XAML comes in at #3, style triggers next, then style setters.

Secondly, if you're using a data template, applying styles via keys in a resource dictionary is probably a safer bet than assuming that key's in the resource dictionary for that TargetType will be respected.

Finally, check out this article from the WPF Disciples website about debugging using trace listeners.  This works in SharpDevelop too, you'll need to add an application config if it does not exist via the Misc > app.config option, or add existing to the project.

Also, for a great explanation of the finer points of MeasureOverride and ArrangeOverride etc, see Dr WPF's great article ItemsControl: 'P' Is For Panel, part of his excellent A-Z series on WPF.  I highly recommend going through all of the posts in this series.