Search code examples
c#wpfmvvmsystem.componentmodel

Is there a way to automatically create DependencyProperty in MVVM


More of a usability question. I'm building a big MVVM application, and I find myself copying / modifying this piece of code all over the place:

public NodeKind Kind
{
    get { return (NodeKind)this.GetValue(KindProperty); }
    set { this.SetValue(KindProperty, value); }
}

public static readonly DependencyProperty KindProperty = DependencyProperty.Register(
        "Kind", typeof(NodeKind), typeof(DashboardNode));

Is there a way in Visual Studio to generate this code with a shortcut or something? I have Resharper and VS 2015, and I can't find the command that would automatically do that for me.


Solution

  • If you use ReSharper the dependencyProperty snippet is generating this. Without ReSharper the propdp snippet is creating the same.