Excellent guidelines by Paul Stovell

I just discovered that Paul Stovell posted a set of XAML and WPF coding guidelines.  I really like his advice on resource organization.  He provides a scalable way to structure your project’s directory system such that it is easy to determine where a resource declaration should be placed, and a naming convention which makes it easy to find where a resource is declared.

The one suggestion I would have added is that resource keys and x:Name values should not simply reiterate the type name of the object.  An object’s key/name should reflect how it is used, as well as the type name…sort of like hungarian notation only not as cryptic.  There are some situations where this is not possible, such as declaring an instance of a value converter in a commonly merged resource file, but it usually is.  For example:

<!– Bad –>

<SolidColorBrush x:Key=”BlueBrush” Color=”Blue” />

<!– Good –>

<SolidColorBrush x:Key=”DaytimeSkyBackgroundBrush” Color=”Blue” />

If you were to look at those two resource declarations in a project you’ve never seen before, wouldn’t it be easier to immediately grasp the purpose of the second brush?

Comments are closed.

%d bloggers like this: