Friday, January 13, 2012

Visual Studio Templates for Silverlight

For Visual Studio and Silverlight there are nice templates available online. If you are a new developers this templates will be very useful, also for experience developers they should be a handy tool in their toolbox. In this post we will learn how to install the project item templates and use them. I assume every .NET developer should have used the inbuilt visual studio template's and understand how helpful they can be.

The five template are :-
1) Silverlight Client Access Policy File:-
This templates adds a file named clientaccesspolicy.xml in the root folder of the Silverlight project.Silverlight 4 supports two different mechanisms for services to enable cross-domain access clientaccesspolicy.xml or crossdomain.xml file. This file need to be at the root of the domain where the service is hosted, I tend to use clientaccesspolicy.xml file because it provides more granular control over allowed domains and can also be used to set configuration for Sockets.A very good explanation can be found here http://www.devtoolshed.com/explanation-cross-domain-and-client-access-policy-files-silverlight

Either way, when you are done  the policy file needs to go in the ROOT of the domain. This is important as it is not the application root, but the root web. Even if your app is located at   foo.com/myapp, the policy file needs to be at  foo.com/clientaccesspolicy.xml.

2) Value Converter:-
This templates adds a file for converter.

3) C# Trigger Template for Silverlight:-
This templates adds a file for trigger.

4) C# Behavior Template for Silverlight:-
This templates adds a file for behavior.

5) C# Action Template for Silverlight:-
This templates adds a file for action.

How to get the templates ?
Open Visual Studio, open an existing silverlight project or create new one.
Right click on the Silverlight Project –> Add -> New Item ->(left side) select Online Templates -> Silverlight


Organizing the templates
This templates will create files and place them under the root folder. What I do is usually create folders in the silverlight project named as behaviors,triggers,actions,converters. How this helps? eventually and gradually when the projects files increase its easy to locate code-files and manage them effectively.

Code Snippets
I know there are code snippets available for the same, I like the templates because a single click will generate the file with basic code and it opens the popular open-file dialog where you can name the file.




No comments:

Post a Comment