Помимо к другим ответам, я бы также предложил расширить ваши ViewModels DependencyObject .
Некоторые люди считают, что объекты DependencyObject имеют большой вес (и они могут быть, если вы создаете их тысячи экземпляров) и немного сложны для новых пользователей (наиболее определенно есть ситуации, когда это действительно так). Однако у DependencyObjects есть и другие преимущества, такие как автоматическая поддержка уведомлений об изменении свойств и скорость оценки привязки.
Вот мой фрагмент DP (сохранить как DependencyProperty.snippet в C: \ Users [ВАШЕ ИМЯ ЗДЕСЬ] \ Documents \ Visual Studio [2010, 2008] \ Фрагменты кода \ Visual C # \ Мои фрагменты кода):
<?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>