views:

1484

answers:

4

I'm writing a fairly big interface using Silverlight. As I progress, the xaml file is getting fairly big and is becoming proportionally uglier.

Questions

  1. Are there any resources out there to make the xaml more readable? For example, how would I display the order of attributes (e.g. height and Width first) so that it looks the most tidy?
  2. Another issue is that there are multiple ways to implement an interface with grids and stack panels. Is there a preferred approach when using one or the other?

I am looking for advice and links to other resources that can be used as examples.

+2  A: 

This may be the same as the XAML best practices question, where the recommendation was to take a look at http://dotnet.org.za/rudi/archive/2009/01/13/xaml-guidelines-released.aspx

JaredReisinger
A: 

SilverLight like any other UI language has the size complexity problem

Much has been written about this problem in the HTML world, and the same rules apply

  • Use a testable pattern like MVP, MVC etc - There are test frameowrks for SilverLight
  • Keeping resource in separate files - A page layout should just be layout. Style, themes etc are shared resources in general
  • Use custom controls - try to avoid using the generic built in controls as they come, wrap them up in a custom control with all your default properties and handlers etc. When you then use this control on a page layout there is less attribute baggage to go with it

I prefer stackpanels over grids for their simplicity - It's a bit like the HTML worlds table vs .css layouts war

Have a look at other peoples SilverLight efforts with SilverLight Spy, and you might feel better about your own :-)

TFD
+2  A: 

If you have lots of complex XAML, you could try to break it down into several UserControls to make it more modular and have less XAML in each file.

Here is a tutorial http://silverlight.net/learn/tutorials/usercontrols.aspx

And here is a video http://silverlight.net/learn/learnvideo.aspx?video=52036

TJB
This is also very awesome, thanks!
JustSmith
A: 

Check out the series on best practices for Silverlight on:

Silverlight 2 Best Practices - 4 articles

The author has 4 articles on this.