Click here to Skip to main content
13,247,608 members (16,159 online)
Click here to Skip to main content
Add your own
alternative version


7 bookmarked
Posted 3 Aug 2010

Some Best Practices for Silverlight Application Development (XAML)

Rate this:
Please Sign up or sign in to vote.
Some of the best practices you should follow while developing in WPF/Silverlight

I have been working with WPF/Silverlight since March 2008 and have learnt a lot of things. I wrote a lot of articles on Silverlight and published them on my blog. Today, I decided to share some of the best practices you should follow while developing in WPF/Silverlight. Hope this will help you guys while writing XAML code. Read and try to be strict with the guidelines whenever you are modifying your XAML.

Feedback is always appreciated. Hence, don’t forget to leave your comments at the end. If you have any more points, please share them. I will review them and add those here.

Some of the XAML coding best practices are mentioned below:

  • Don’t use unnecessary “xmlns” namespaces in the XAML file. This overburdens the load time of the Silverlight page (If you are using Resharper, you can do this very easily as it will change the color of the unnecessary items to Grey).
  • Don’t add the same namespaces multiple times in a single XAML page. It screws up the XAML code at the time of maintenance and also loads the assembly namespace multiple times causing various memory issues at runtime.
  • Use proper name for your “xmlns” namespace prefix. For example: xmlns:commonControls is more meaningful than xmlns:cctrl. This avoids multiple declarations of namespaces.
  • Try avoiding “xmlns” namespace prefix name as “local”. Instead use “localControls” or “localConverters”, etc.
  • When adding a control that has no elements inside it, better to close it by self-closing tag “/>” instead of the hard closing tag (</TAG>)
  • Remove all unnecessary resource keys if they are not in use. These increases the memory uses and you may sometimes encounter some animation issues due to this. If you need it at a later point of time, you are always welcome to add it.
  • Don’t use extra panels (e.g. Grid, StackPanel, Canvas, etc.) unless they are required.
  • Always try to use Grid as your panel first and if you require other panels, use them.
  • Never try to give a name to all of your controls inside your Silverlight page as it takes unnecessary object creation at the time of load. Name only those elements which you want to use from your code behind and/or from your XAML. If you are using MVVM pattern, you can remove the naming of your controls in almost all the cases.
  • Use the Visibility property of the controls instead of the Opacity property to hide the content.
  • Use proper formatting of your XAML code. This gives better look of code and is also easy to maintain in the future.
  • Use comments in XAML whenever required.
  • Try to use StaticResource instead of DynamicResource as it increases the performance and also it throws exceptions at development time. Hence, it is easier to identify the root cause.
  • Remove unnecessary styles if they are not required at all.
  • Try to add your styles in a separate file if you want to share them across your application. If they are specific to a single page, then add them in the page resource.

</img />
</img />


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Kunal Chowdhury «IN»
Software Developer (Senior)
India India
Kunal Chowdhury is a Microsoft "Windows Platform Development" MVP (Most Valuable Professional), a Codeproject Mentor, Telerik Developer Expert, Nokia Developer Champion, Windows 10 Champion, Microsoft Rockstar, Speaker in various Microsoft events, Author, passionate Blogger and a Software Engineer by profession.

He is currently working in an MNC located in India. He has a very good skill over XAML, C#, Silverlight, Windows Phone, WPF and Windows Store (WinRT) app development. He posts his findings, articles, tutorials in his technical blog and CodeProject.

Book authored:

Connect with me on:

My CodeProject Awards/Prizes:

You may also be interested in...


Comments and Discussions

GeneralMy vote of 3 Pin
AssassinX1892-Sep-10 7:14
memberAssassinX1892-Sep-10 7:14 
GeneralRe: My vote of 3 Pin
KunalChowdhury7-Sep-10 9:44
mentorKunalChowdhury7-Sep-10 9:44 
GeneralRe: My vote of 3 Pin
KunalChowdhury7-Sep-10 9:45
mentorKunalChowdhury7-Sep-10 9:45 
GeneralMy vote of 4 Pin
DBA-Sully10-Aug-10 4:58
memberDBA-Sully10-Aug-10 4:58 
AnswerRe: My vote of 4 Pin
KunalChowdhury7-Sep-10 9:43
mentorKunalChowdhury7-Sep-10 9:43 
GeneralMy vote of 4 Pin
tec-goblin9-Aug-10 22:23
membertec-goblin9-Aug-10 22:23 
AnswerRe: My vote of 4 Pin
KunalChowdhury7-Sep-10 9:40
mentorKunalChowdhury7-Sep-10 9:40 
GeneralMy vote of 4 Pin
V.SivaRamaKriShnaRaju9-Aug-10 21:03
memberV.SivaRamaKriShnaRaju9-Aug-10 21:03 
GeneralRe: My vote of 4 Pin
KunalChowdhury7-Sep-10 9:41
mentorKunalChowdhury7-Sep-10 9:41 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.171114.1 | Last Updated 3 Aug 2010
Article Copyright 2010 by Kunal Chowdhury «IN»
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid