Skip Navigation LinksHome > SSW Standards > Rules > SSW Rules to Better WPF & Silverlight

I've been putting together Development Guidelines for my employer and in the process have reviewed many published standards (in the .Net arena) from around the world. In each category, the suggestions at SSW are always among the best. Leon Bambrick -
 

Do you agree with them all? Are we missing some? Let us know what you think.

  1. Do you follow Composite Application Guidance (formerly code-named "Prism") in your Silverlight (and WPF) Projects?

    The Composite Application Guidance from the patterns & practices team at Microsoft is designed to help you more easily build loosely coupled, independently evolvable modular WPF and Silverlight client applications which take advantage of the capabilities of WPF and Silverlight.

    With Composite Application Library (CAL), you can only adopt the components your application requires. For example, you could change your communication approach from .NET Framework events to use the Event Aggregator, which allows you to send loosely coupled messages between modules.

    Composite Application Guidance

  2. Do you use the MVVM pattern in your Silverlight (and WPF) Projects?

    The term MVVM means Model-View-ViewModel design pattern. This pattern is an adaptation of the MVC and MVP patterns in which the view model provides a data model and behavior to the view but allows the view to declaratively bind to the view model. The view becomes a mix of XAML and C# (as WPF or Silverlight controls), the model represents the data available to the application, and the view model prepares the model in order to bind it to the view.

    The most important aspect of WPF or Silverlight that makes MVVM a great pattern to use is the data binding infrastructure. By binding properties of a view to a ViewModel, you get loose coupling between the two and entirely remove the need for writing code in a ViewModel that directly updates a view. In a sense, Views and unit tests are just two different types of ViewModel consumers. Having a suite of tests for an application's ViewModels provides free and fast regression testing, which helps reduce the cost of maintaining an application over time.

    a good article about MVVM

  3. Do you avoid using Thread.Sleep in your Silverlight application?

    Calling Thread.Sleep on your Silverlight application causes the UI thread to sleep. That means the application is not responsive.
    If you want to delay something, you can use a storyboard.

    Thread.Sleep(5000);
    this.Dispatcher.BeginInvoke(new Action(() =>
                                                {
                                                    //Try to reconnect in the background
                                                    Connect.Execute(null);
                                                }));
    Bad: Using Thread.Sleep() causes your Silverlight application to freeze
    
     
     
     
    Storyboard sb = new Storyboard() { Duration = TimeSpan.FromSeconds(5) };
    
    sb.Completed += (ds, de) => this.Dispatcher.BeginInvoke(new Action(() =>
                                                                            {
                                                                                //Try to reconnect in the background
                                                                                Connect.Execute(null);
                                                                            }));
    sb.Begin();                
                    

    GOOD: Use a Storyboard with a duration of the delay and once the Storyboard is finished running

Acknowledgements

Adam Cogan
James Zhou


Benefit from our knowledge and experience!

SSW is the industry leader in Custom Software Development, Software Auditing & Developer Training.

Call us on +61 2 9953 3000 or email us for a free consultation

What does it cost? I’m not in Australia. Can you still help?