18 March 2009

Silverlight: the simpliest master pages ever (plus links to subpages)

I gave a presentation about Silverlight today at school. It went great and benefited me as well, as it took me away from all the wedding preparations and made me look at some old code and notes (well, some new too, I'm staying in the Cream's 'Light).

So, two things tonight. First, master pages. You probably have read Jesse Liberty's and Gerard Leblanc's articles - they're great and full of useful information, but I'll try simplifying things as much as possible.

Now, let's say you have your subpages as controls and you want to have a header/footer/sidebar.

  1. Start with a Grid layout, (Grid is the best one in general, more on that maybe someday), fill the right cells with that common header/footer/whatever.
  2. In the biggest cell, the one for subpages, place a ScrollViewer.
  3. Now, tell me, what is a ScrollViewer? A ContentControl. It means it has a Content property. It means it hosts a single control. What control could it be, hum?
  4. theScrollViewer.Content = theSubpage; - that's the whole navigation code!
Ok, now the subpages. I used to think until today that this was impossible, and that it was one of the main reasons using Silverlight for building typical websites wasn't a great idea. But the guys from SilverlightShow proved me wrong with their recent article about Interaction between Silverlight and the Browser:

I won't post any code here, just refer you to that article, my excuses being the lack of time and that the idea is not mine. As for translationg the idea into a working solution, I'm sure you'll do it easily.

Now we just need a way to handle the "back" button and the whole navigation history (thanks to one of today's listeners for bringing that up). However, my Silverlight sites don't go over 10 content pages, so tracking navigation history doesn't really have a point. And hey, it's Silverlight, it's super easy to do!

1 comment:

  1. Checkout the SL 3.0 Navigation framework as well...