With years of experience working with Silverlight development, we have found some of the best practices that must be utilized while working with Silverlight and we are sharing this with you. This will help you while writing XAML codes. Follow these guidelines whenever you are editing these codes (XAML codes).
some best practices for XAML coding:
- Avoid using unnecessary xmnl name spaces in the XAML file. Using unnecessary files increases the burden on the load time of Silverlight page. (make use of re shaper to identify unnecessary usage of xmnl name spaces).
- Avoid adding similar name spaces several times in a single XAML page. This leads to the damage of XAML code while maintaining the website and it also causes various memory issues.
- Remember to choose an easy name for xmnl name space so that you can recognize them easily. This makes it easy for you to identify the multiple uses of namespaces in the file.
- It is recommended that you use local controls or local converters as prefix for your xmnl namespace. Just using local as a prefix will make no sense. For different xmnl name spaces, it is advisable to use relevant names to easily distinguish between them in a proper manner.
- In case , you have added some control without any elements then always remember to close it by using a self close tag “/>” instead of the hard closing tag . This makes XAML code more clean and tidy.
- Avoid using unnecessary resource keys that are not in use. Using many of them, leads to maximum memory usage. Further you may sometimes find animation issues.
- Use extra panels like Grid, Stack panel only when needed.
- In case you are in need of using panels, then go for grid panels first. This is because Grid has flexible user interface layout and resizing your application provides a tremendous effect.
- Leave your controls without names inside the Silverlight page to avoid unnecessary object creations during the load time.
- Prefer to name only those elements that you will use from your code or from XAML. In case of MVVM pattern, control naming can be removed in most of the cases.
- If you wish to hide the content then go for visibility property instead of opacity property. Zero opacity will definitely hide the content but will take more space in memory as well as user interface. While visibility property crashes the control from user interface and creates space for other controls in the same place.
- Always remember to do proper formatting of your XAML code in order to provide better look of code.
- Always prefer to use comments in XAML as and when needed. This helps to keep a track of work and is really useful to guide you when you again get back to work.
Our best practices of Microsoft Silverlight business applications are definitely going to help you a lot and for more such informational articles, stay tuned to our blogs. Regarding any guidance to Silverlight development, get connected with our expert Silverlight or XAML developers at Softqube Technologies.