Page view counter

Simple Expander – Silverlight Toolkit

[Updated 16:00 GMT-5 to include working version and link to code:  Expander.zip ]

 

The new Silverlight Toolkit includes a Expander control that, in its simplest form, is incredibly easy to add to your program,

 

Expander 
[Composite image]

 

To create the simplest expander, add a reference to Microsoft.Windows.Controls to your project,

ExpanderReferences

and add the namespace at the top of your xaml file

xmlns:controls="clr-namespace:Microsoft.Windows.Controls;assembly=Microsoft.Windows.Controls"

First Expander

A simple expander takes a direction, text for the header, and content; in this case an ellipse:

<controls:Expander Grid.Row="0" Grid.Column="1" 
      ExpandDirection="Down" Header="Click to Expose Ellipse">
  <controls:Expander.Content>
    <Ellipse Width="40" Height="40" Fill="red" />
  </controls:Expander.Content>
</controls:Expander>
(Special thanks to Justin Blunk)

You can vary the direction of the expansion, and you can vary what is in the header. Of course, you can do much more with templates, but that is for another day (and probably best shown in a video.  To give you a sense of the flexibility, however, I've created a second expander that opens to the right and whose header is not a string of text but is managed by a TextBlock. Also note that in this case the contents are not a single object, but rather a set of objects maintained in a stack panel.  I've not databound any of the contents, but that is easily done as well.  Here's the code, followed by the before and after images.

<controls:Expander  
  ExpandDirection="Right" 
  Grid.Row="1"
  Grid.Column="0"
  Grid.ColumnSpan="2" BorderThickness="0" >
  <controls:Expander.Header>
    <TextBlock Text="Please fill in your secret code word" />
  </controls:Expander.Header>
  <controls:Expander.Content>
      <StackPanel Orientation="Horizontal">
        <TextBlock Text="secret codeword" FontSize="14" 
                   Margin="5" VerticalAlignment="Bottom"/>
        <PasswordBox PasswordChar="?" FontSize="14" 
                     Margin="5" Width="120" Height="30" 
                     VerticalAlignment="Bottom"/>
      </StackPanel>
    </controls:Expander.Content>
</controls:Expander>

It is all in the Xaml, there is no C# code needed.

ExpanderCode

Here's the working example, streaming from Silverlight Streamling Live Services

 

Published Monday, December 01, 2008 12:32 PM by jesseliberty
Filed under: ,

Comments

# re: Simple Expander – Silverlight Toolkit

Perhaps the ajax toolkit needs a "If Silverlight is installed load this xap, otherwise display this jpg" widget. It would be useful for blogs like yours, where I'm guessing the vast majority of users already have Silverlight installed, so it would be more useful to actually show the app instead of just a picture of it.

Monday, December 01, 2008 1:48 PM by jackbond

# re: Simple Expander – Silverlight Toolkit

Thanks.

It seems that it will launch a new Toolkit version every month.

Monday, December 01, 2008 1:48 PM by shinedraw

# Silverlight Cream for December 01, 2008 -- #443

In this issue: Alex Golesh, Silverlight SDK, John Stockton, Page Brooks(2), Mike Snow(2), Terence Tsang

Tuesday, December 02, 2008 1:20 AM by Community Blogs

# 2008 December 02 - Links for today &laquo; My (almost) Daily Links

Pingback from  2008 December 02 - Links for today &laquo; My (almost) Daily Links

# Dew Drop - December 2, 2008 | Alvin Ashcraft's Morning Dew

Pingback from  Dew Drop - December 2, 2008 | Alvin Ashcraft's Morning Dew

Tuesday, December 02, 2008 8:45 AM by Dew Drop - December 2, 2008 | Alvin Ashcraft's Morning Dew

# re: Simple Expander – Silverlight Toolkit

Can I use one expander for multiple controls?  Or will I have to use one control like a grid or canvas and nest additional controls inside of it?

Thank you,

Tuesday, July 07, 2009 1:56 PM by FLN777