Friday, October 12, 2012

proprt... A C# snippet to speed up the writing of Windows 8/MVVM Properties

The Brain Dump - Windows 8 ViewModel Property Code Snippet

Visual Studio provides a bunch of good code snippets for creating boilerplate code. For example if you type “prop” you get this in intellisense

image

You’ll see a few nice property snippets.

  • prop – creates a basic automatic property
  • propa – creates an attached property
  • propdp – creates a dependency property
  • propfull – creates a public property with a private backing field
  • propg – creates a basic automatic property but the set is marked private

I use these constantly but hit an issue when building my Windows 8 apps. For ViewModels in Windows 8, the default templates take advantage of a wonderful attribute CallerMemberName in the OnPropertyChanged method of the ViewModel base class. This allows you to create properties that support notifications in a very simple manner. Like this

image

...

SNAGHTMLc3f5c09..."

Funny... I was just looking for something like this. I love the inter-tubes...

No comments: