Observable Property VS snippet

When working with WPF and the observable properties a good UI needs, you need to enter class properties as full properties (not automatic properties). You need to do so this so you can call INotifyPropertyChanged's PropertyChanged event handler in the property's setter.

Full class properties are a pain to enter manually. There is a built-in Visual Studio snippet for full properties (type propfull and press the tab key twice), but it adds a plain vanilla setter. However, a custom snippet eliminates needing to manually add the PropertyChanged handler to the every view model manually, and it provides a SetField method to call the PropertyChanged changed handler.

Visual Studio's built-in snippets are located in this folder (this location varies slightly depending on which version of Visual Studio you're using). Looking at some of these snippets and their output helps make a little sense out of the XML needed to create a snippet. The code to create an observable property snippet is below.

Snippet as text:

Leave a Comment

Your email address will not be published. Required fields are marked *