15 best practices developed by WPF/Silverlight (forward)

Recommended for you: Get network issues from WhatsUp Gold. Not end users.

English provenance: ;

Author: Kunal Chowdhury

The original name: Some Best Practices for Silverlight Application Development (XAML)


◆Do not use the xmlns namespace useless in the XAML file, it will cause Silverlight page loading time is too long.

◆Do not add more of the same namespace in a single XAML page, it will destroy the maintainability of XAML code, the same name run repeatedly loaded namespaces may cause memory problems.

◆Use the proper name for the xmlns namespace prefix, for example, xmlns:commonControls is more useful than xmlns:cctrl, so you can avoid future namespace declarations.

◆Try to avoid using the local prefix in the Xmlns namespace, the best is replaced by the localControls or localConverters, in the same assembly may have two or more namespaces (such as Controls or Converters), in this case, use the appropriate prefix will help to distinguish them.

◆When adding an element free controls, it is best to use a self closing tag “ /> ” close, do not use hard closing tag “ </tag> ”, XAML code will look more relaxed.

◆If the resource is not used, it is best to remove the unnecessary resource key, they will consume more memory, you might encounter a lot of problems, if you will use them, you can add them at any time.

◆Do not use additional panel (such as Grid, StackPanel, Canvas etc.).

◆If you need to use other panel, should first try to Grid, Grid has a flexible UI layout, is very useful to adjust the application size.

◆Don't try to give all the controls in a Silverlight page has a name, because in the load will create some unnecessary objects, only for those behind will be used in the control of a name, if you are using MVVM mode, you can remove almost all control name.

◆Use the Visibility attribute controls instead of Opacity attribute hidden content, the value of the Opacity property is set to 0 can play hide the role, but the memory footprint and UI space is not reduced, on the contrary, the Visibility property will release the memory and the UI space, so it can be placed between the limited space for other controls.

◆Use the correct format in XAML code, this will make the code more good-looking, and easy to maintain.

◆As far as possible to add notes to XAML, when after a long time before you see the code, can you remember that writing motivation, in addition, if people collaboration, reasonable notes will reduce code reading and understanding of other people's time, promote cooperation of productivity.

◆Use StaticResource instead of DynamicResource, first it will improve performance, secondly in development can run abnormal information, facilitates debugging.

◆Remove unwanted style.

◆If you want to share your styles across applications, it is best to add your style in a separate file, if only for a particular page, it is best to add them on the page in a resource file.


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download

Posted by Pearl at November 14, 2013 - 2:08 AM