Resharper Templates for DependencyProperties

Here are some Resharper Templates for Dependency Properties in WPF and UWP.
I’ve had these for a while and now decided to make them public in case anyone has any use for them.

Simple Dependency Property

C# 7.0+

1
2
3
4
5
6
7
8
9
10
11
/// <summary>
/// Dependency property registration for the wrapper <see cref="$name$"/> property.
/// </summary>
public static readonly DependencyProperty $name$Property =
    DependencyProperty.Register("$name$", typeof($type$), typeof($ownerType$), new PropertyMetadata($default$));

public $type$ $name$
{
    get => ($type$)GetValue($name$Property);
    set => SetValue($name$Property, value);
}

Older C# versions

1
2
3
4
5
6
7
8
9
10
11
/// <summary>
/// Dependency property registration for the wrapper <see cref="$name$"/> property.
/// </summary>
public static readonly DependencyProperty $name$Property =
    DependencyProperty.Register("$name$", typeof($type$), typeof($ownerType$), new PropertyMetadata($default$));

public $type$ $name$
{
    get { return ($type$)GetValue($name$Property); }
    set { SetValue($name$Property, value); }
}

Dependency Property with PropertyChanged Callback

C# 7.0+

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
/// <summary>
/// Dependency property registration for the wrapper <see cref="$name$"/> property.
/// </summary>
public static readonly DependencyProperty $name$Property =
    DependencyProperty.Register("$name$", typeof($type$), typeof($ownerType$), new PropertyMetadata($default$, On$name$PropertyChanged));

private static void On$name$PropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
    $code$
}

public $type$ $name$
{
    get => ($type$)GetValue($name$Property);
    set => SetValue($name$Property, value);
}

Older C# versions

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
/// <summary>
/// Dependency property registration for the wrapper <see cref="$name$"/> property.
/// </summary>
public static readonly DependencyProperty $name$Property =
    DependencyProperty.Register("$name$", typeof($type$), typeof($ownerType$), new PropertyMetadata($default$, On$name$PropertyChanged));

private static void On$name$PropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
    $code$
}

public $type$ $name$
{
    get { return ($type$)GetValue($name$Property); }
    set { SetValue($name$Property, value); }
}

Kommentar verfassen