For those who don't know what is VS code snippet.
Code snippet is one type of macro which insert a block of code upon activation.ie if we have to use a block of code frequently we could make that as a snippet and insert whenever we want.Here you will get details about the snippets very well.
Dependency property was introducd in WPF which is very useful in so many situations.But it's syntax is little bit big so that we can't remember always.So I usually prefer snippet for creating DPs in WPF.It's very easy
Right click->Insert Snippet->NetFX30->Define a Dependency Propertyor
Type 'propdp' ->Tab
After getting the snippet we can change it's parameters according to our requirement.
DP Snippet in Silverlight
It was working well until I used the same in Silverlight.The default dp snippet in VS inserts a DP which uses metadata object of type UIPropertyMetadata.But this class is not available in Silverlight.Compile time error!!!!!
So I modified the dp snippet code to make it compatible with Silverlight.Using this you can insert DPs in silverlight without compilation error.
Steps
- Download the snippet file from here.
- Open Visual studio
- Tools->Code snippet manager
- Select language 'C#'
- Click 'Import'
- Locate the downloaded .snippet file.
- Select the folder for storing snippt.
- Click Finish.
- You can see the snippet in the code snippet manager.
- Now in Silverlight project you can use this snippet.
Happy coding!!!
If you are interested in testing more snippets get more from http://gotcodesnippets.com/
No comments:
Post a Comment