In addition to the other answers, I would also suggest that your ViewModels extend DependencyObject .
Some people think that DependencyObjects are a lot of weight (and they can be if you create thousands of instances of them) and a little complicated for new users (there are most definitely situations where this is true). However, there are other benefits to DependencyObjects, such as automatic support for property change notifications and the speed of binding evaluations.
Here is my DP fragment (save as DependencyProperty.snippet in C: \ Users [YOUR NAME HERE] \ Documents \ Visual Studio [2010, 2008] \ Code Snippets \ Visual C # \ My Code Snippets):
<?xml version="1.0" encoding="utf-8"?> <CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet"> <CodeSnippet Format="1.0.0"> <Header> <SnippetTypes> <SnippetType>Expansion</SnippetType> </SnippetTypes> <Title>SnippetFile1</Title> <Author>will</Author> <Description> </Description> <HelpUrl> </HelpUrl> <Shortcut>dp</Shortcut> </Header> <Snippet> <Declarations> <Literal Editable="true"> <ID>PropertyName</ID> <ToolTip>Property name</ToolTip> <Default>PropertyName</Default> <Function> </Function> </Literal> <Literal Editable="false"> <ID>ClassName</ID> <ToolTip>Class name</ToolTip> <Default>ClassName</Default> <Function>ClassName()</Function> </Literal> <Literal Editable="true"> <ID>Type</ID> <ToolTip>Property type</ToolTip> <Default>object</Default> <Function> </Function> </Literal> <Literal Editable="true"> <ID>DefaultValue</ID> <ToolTip>Default value</ToolTip> <Default>null</Default> <Function> </Function> </Literal> </Declarations> <Code Language="csharp"><![CDATA[#region $PropertyName$ /// <summary> /// The <see cref="DependencyProperty"/> for <see cref="$PropertyName$"/>. /// </summary> public static readonly DependencyProperty $PropertyName$Property = DependencyProperty.Register( $PropertyName$Name, typeof($Type$), typeof($ClassName$), new UIPropertyMetadata($DefaultValue$)); /// <summary> /// The name of the <see cref="$PropertyName$"/> <see cref="DependencyProperty"/>. /// </summary> public const string $PropertyName$Name = "$PropertyName$"; /// <summary> /// $end$ /// </summary> public $Type$ $PropertyName$ { get { return ($Type$)GetValue($PropertyName$Property); } set { SetValue($PropertyName$Property, value); } } #endregion ]]></Code> </Snippet> </CodeSnippet> </CodeSnippets>
Will
source share