Posted by: Stephen Oakman | July 27, 2009

Refining the removal of strings from WPF dependency properties

Following on from the previous post regarding removing the strings when registering Dependency Properties I wanted to fine tune it so we could remove the need for specifying the type we are defining the dependency properties on.

The way to do this is to cache a static instance of the DependencyPropertyHelper class in our class like so:

private static readonly DependencyPropertyHelper DependencyProperty = new DepenencyPropertyHelper<WorldViewModel>();

Now we can change our dependency property registrations from this:

public static readonly DependencyProperty CameraLookDirectionProperty =  
    DependencyPropertyHelper<WorldViewModel>.Register(x => x.CameraLookDirection); 

To this:

public static readonly DependencyProperty CameraLookDirectionProperty =  
    DependencyProperty.Register(x => x.CameraLookDirection); 


Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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

Categories

Follow

Get every new post delivered to your Inbox.