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 Saturday, March 15, 2008 10:00 AM by jesseliberty

Comments

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

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!>

Saturday, March 15, 2008 10:53 AM by wisecarver

# Silverlight Cream for March 15, 2008 -- #225

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

Saturday, March 15, 2008 3:45 PM by Community Blogs

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

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

Saturday, March 15, 2008 11:10 PM by Dew Drop - March 15, 2008 | Alvin Ashcraft's Morning Dew

# Source for the Tip of the Day

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

Sunday, March 16, 2008 9:14 PM by Jesse Liberty - Silverlight Geek

# Source for the Tip of the Day

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

Sunday, March 16, 2008 9:41 PM by Mirrored Blogs

# Source for the Tip of the Day

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

Sunday, March 16, 2008 9:41 PM by Blogs

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

Follow-up on the Silverlight 2 Applications structure:

silverlight.net/.../37852.aspx

Monday, March 17, 2008 8:10 AM by wisecarver

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

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

Greetings Thomas

Monday, March 17, 2008 8:47 AM by Thomas H.

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

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.

Monday, March 17, 2008 10:50 AM by jesseliberty

# Tip of the Day - Binding to a Collection

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

Monday, March 17, 2008 10:55 AM by Microsoft Silverlight content

# How do I Write that In JavaScript?

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

Monday, March 17, 2008 11:06 AM by Jesse Liberty - Silverlight Geek

# How do I Write that In JavaScript?

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

Monday, March 17, 2008 11:12 AM by Blogs

# How do I Write that In JavaScript?

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

Monday, March 17, 2008 11:58 AM by Mirrored Blogs

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

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.

Monday, March 17, 2008 1:27 PM by dave_dyson

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

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

Wednesday, February 11, 2009 3:45 AM by rosemol