Reader small image

You're reading from  Instant Silverlight 5 Animation

Product typeBook
Published inJan 2013
Reading LevelIntermediate
PublisherPackt
ISBN-139781849687140
Edition1st Edition
Languages
Right arrow
Author (1)
Nick Polyak
Nick Polyak
author image
Nick Polyak

Nick Polyak is a technology enthusiast who enjoys building software and learning new technologies. For the past six years, Nick worked primarily on Silverlight/WPF projects, and prior to that he worked with C++ and Java. Nick is looking forward to harnessing the new capabilities coming with HTML5 and modern JavaScript libraries. Nick got his Ph.D. from Rensselaer Polytechnic Institute in 1998. He did his research in Wavelet based image processing and published a number of papers on the subject. More recently Nick published several articles on codeproject.com some of which (a Prism tutorial and an article on MVVM) became quite popular. Nick is the owner of the AWebPros.com consulting company.
Read more about Nick Polyak

Right arrow

Appendix D. Using snippets

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.

lock icon
The rest of the chapter is locked
You have been reading a chapter from
Instant Silverlight 5 Animation
Published in: Jan 2013Publisher: PacktISBN-13: 9781849687140
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime

Author (1)

author image
Nick Polyak

Nick Polyak is a technology enthusiast who enjoys building software and learning new technologies. For the past six years, Nick worked primarily on Silverlight/WPF projects, and prior to that he worked with C++ and Java. Nick is looking forward to harnessing the new capabilities coming with HTML5 and modern JavaScript libraries. Nick got his Ph.D. from Rensselaer Polytechnic Institute in 1998. He did his research in Wavelet based image processing and published a number of papers on the subject. More recently Nick published several articles on codeproject.com some of which (a Prism tutorial and an article on MVVM) became quite popular. Nick is the owner of the AWebPros.com consulting company.
Read more about Nick Polyak