Here we give an example of snippet usage by showing how to create a dependency property within C# code using propdp
snippet. (Creating dependency and attached properties in code would be a pain without snippets).
We are going to create a dependency property RotationAngle
of type double
within the SpinningControl
class.
Within that RotationAngle.cs
file, move the cursor to the place you want the dependency property to be at and type propdp<tab>
.
The snippet will expand into the following text:
#region MyProperty Dependency Property public int MyProperty { get { return (int)GetValue(MyPropertyProperty); } set { SetValue(MyPropertyProperty, value); } } public static readonly DependencyProperty MyPropertyProperty = DependencyProperty.Register ( "MyProperty", typeof(int), typeof(MainPage), new PropertyMetadata(0) ); #endregion MyProperty Dependency Property
The changeable strings are selected in orange. Once you change a selectable string, for example, MyProperty
to RotationAngle
and press Tab, the matching strings will change throughout the entire snippet and the next selectable string will be selected. You should change MyProperty
to RotationAngle
, int
to double
, and 0
to 0.0
. Once you are done, press Enter to exit the snippet-editing mode. The following is how the resulting code should look:
#region RotationAngle Dependency Property public double RotationAngle { get { return (double)GetValue(RotationAngleProperty); } set { SetValue(RotationAngleProperty, value); } } public static readonly DependencyProperty RotationAngleProperty = DependencyProperty.Register ( "RotationAngle", typeof(double), typeof(SpinningControl), new PropertyMetadata(0.0) ); #endregion RotationAngle Dependency Property
Congratulations! You have just created your first dependency property using
propdp
snippet.