Page view counter

Tip of the Day Returns from Disney - Master Detail in Silverlight 2

Source Code 

 

Okay, its true, I was having so much fun at Disney World (and if you've not been on Soarin, then find a conference in Orlando, and sneak out to Soar, yowza!) that Tip of the Day kinda' sorta' stopped for a day or two. But we're back again with more in depth explorations of the tutorials, and responses to your email (which, I note did not slow down very much while I was on vacation, which is great!).

So, today I'd like to lay out a schedule and a project and over the next couple days pursue that project and a few other topics as well.

I've received quite a bit of email about data binding, and Tip of the Day seems like a good place to explore various aspects of this essential feature. I've created a relatively simple starter application that we can take apart, rebuild and then extend to explore various aspects of data binding; taking on other topics as we go.

MasterDetail

This Silverlight application consists of an outer grid that has been divided into two columns. In the left column I've placed a DataGrid and in the right column I've placed an inner grid with details about whatever book is selected in the DataGrid.  There is plenty to do to make this look nicer, but for now I'd like to focus on the simple layout and the data binding.

Here's the XAML that divides up the grids. I've collapsed the controls that populate the grids to make seeing the grids themselves somewhat easier,

Grids

The outermost grid is defined on line 5 and named LayoutRoot. It serves as the container for everything and is defined as having the size 800x600 and having a background color of Bisque.

This outer grid has one row (with a top and bottom margin). The rows are created on lines 11-15. On lines 16-22 are two columns, with two margins and a padding between the rows. The first column is fixed at 400 and the second column takes up the remaining space.

The first row and first column is populated by a DataGrid which is shown collapsed on line 23 (we'll return to that shortly).

The first row and third column (skipping one column for the padding) is a new grid named details.

In essence, the DataGrid holds the listing of all the books, the details shows all the data about the selected book.

The Details grid consists of six rows plus two margin rows, and two columns with padding between and a margin on either side. The left part of the details grid is set to 150, the right side gets all the remaining space (after allocation for the padding and margins).

The actual contents (data) for the details are shown collapsed on lines 64-88.

The layout is easier to see in the designer, especially if we add the attribute to each grid "ShowGridLines=True"

WithGridLiines

The steps to building this application, once we have the basic layout are

  1. Create the business object (the book)
  2. Create a collection of business objects (a list of books, a database of books)
  3. Bind a DataGrid to that collection
  4. Handle the selection changed event when the user clicks on a book
  5. Get the book object selected and present its details in the grid on the right

Piece of cake.

We'll start by creating the Business object and its collection in the next Tip of the Day.

Published 15 March 2008 10:00 AM by jesseliberty

Comments

# wisecarver said on 15 March, 2008 10:53 AM

Thanks Jesse.

If possible can you provide more in-depth info soon about Silverlight Application structures in VS2008?

I'm a bit confused at this point with the 'skinny' version of Silverlight we can easily create in VS2008 vs. 'all the junk' that's added if we add a Silverlight Application to an existing site in VS2008. ;-)

</Mo.Info.BeGood.And.WeLoveit!>

# Community Blogs said on 15 March, 2008 03:45 PM

Karen Corby provides us 3 SL2 controls, Carlos Figueira details the cross-domain policy file, Jesse Liberty

# Dew Drop - March 15, 2008 | Alvin Ashcraft's Morning Dew said on 15 March, 2008 11:10 PM

Pingback from  Dew Drop - March 15, 2008 | Alvin Ashcraft's Morning Dew

# Jesse Liberty - Silverlight Geek said on 16 March, 2008 09:14 PM

The Tip of the Day occasionally will delve deep into code (other days it will just provide a bit of useful

# Mirrored Blogs said on 16 March, 2008 09:41 PM

The Tip of the Day occasionally will delve deep into code (other days it will just provide a bit of useful

# Blogs said on 16 March, 2008 09:41 PM

The Tip of the Day occasionally will delve deep into code (other days it will just provide a bit of useful

# wisecarver said on 17 March, 2008 08:10 AM

Follow-up on the Silverlight 2 Applications structure:

silverlight.net/.../37852.aspx

# Thomas H. said on 17 March, 2008 08:47 AM

Great Sample! Any hint how to create such a sample with Java Script instead C#?

Greetings Thomas

# jesseliberty said on 17 March, 2008 10:50 AM

Thomas,

>>Any hint how to create such a sample with Java Script instead C#? <<

This is so important, I'm going to answer in a blog post.

# Microsoft Silverlight content said on 17 March, 2008 10:55 AM

Source Code - Same as Yesterday The Tip of the Day doesn&#39;t usually carry on a related series of postings

# Jesse Liberty - Silverlight Geek said on 17 March, 2008 11:06 AM

A comment was left in response to Master Detail in Silverlight 2 asking &quot; Any hint how to create

# Blogs said on 17 March, 2008 11:12 AM

A comment was left in response to Master Detail in Silverlight 2 asking &quot; Any hint how to create

# Mirrored Blogs said on 17 March, 2008 11:58 AM

A comment was left in response to Master Detail in Silverlight 2 asking &quot; Any hint how to create

# dave_dyson said on 17 March, 2008 01:27 PM

Please could you show me a snippet of

Jscript code which creates a collection of

(business) objects to pass to a Silverlight 2

data grid.

# rosemol said on 11 February, 2009 03:45 AM

if we r binding data fom an xml using linq....how it could be done....plz give sample code