Page view counter

Just Built My First SL3 / Dev 10 App

As you no doubt know we released Beta 1 of Visual Studio 2010 today   (the usual caution applies: I would advise only installing this on a machine you are prepared to repave!).  [Update - the Landing Page for all things related to VS 2010 Beta1 is here. ]

I installed it and Silverlight 3 on my laptop running Windows 7 (yowza!) and then fired it up and created an incredibly simple app as follows:

NewVS10Project

In the new project dialog shown cropped here, I chose to build to the latest version of the .NET Framework (marked Red-circle 1), then chose C# as the language I’d build in (2); narrowed the types of projects by choosing Silverlight (3) and finally chose a Silverlight application (4). 

At the bottom (not shown) I picked the directory and named the project Element Binding.

NewVS10ProjectDialog

 

 

As in previous versions, I’m prompted to choose either a web-based or a simple test application (I chose the latter) but I then had to choose to build to Silverlight 3 rather than 2).

VS10WhichVersion

Visual Studio opens on a new Silverlight 3 application and here is where everything changes.  No longer does the design surface say preview; now it says “Design” and means every syllable.  I created columns and rows much as I would in Blend (by clicking in the margins of the grid:

VS10CreatingColumns

I then dragged a slider into the first column and a text block into the second. WooHoo!

VS10DragControls

I then set the values for the slider to be 0 to 100 and the small increment to be 1 and the large increment to be 100. Finally, I set the properties for the TextBlock, the most important of which being its Text; which I set by clicking on the symbol next to Text (shown circled below) to choose Apply DataBinding

VS10ApplyDataBinding

The Source Dialog opens, and choosing ElementName brings up a list of the elements to which you can bind. Clicking on Slider1 (the slider control) caused the instruction “Use the Path pane to choose propoerties for the Source“ to appear as shown circled in the figure below,

VS10BindingToAnElement

Clicking on the Path pane opened a list of all of Slider’s properties. The property I wanted to bind to was Value, and I clicked on that. I had the option of choosing additional properties or options, but that was all I needed and in fact when I closed the dialog the value of the slider was immediately reflected in the text block in the designer. A quick test run of the application demonstrated that the TextBlock was now bound to the value of the slider, with no need for an event or an intervening data object! 

Sweet.

The application runs as intended,

VS10BoundElement

and here is the complete source, all of which is Xaml:

   1: <UserControl x:Class="ElementBinding.Page"
   2:    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
   3:    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
   4:    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
   5:    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
   6:    mc:Ignorable="d"
   7:    d:DesignHeight="100"
   8:    d:DesignWidth="200">
   9:    <Grid x:Name="LayoutRoot"
  10:          Background="White"
  11:          Height="62">
  12:       <Grid.RowDefinitions>
  13:          <RowDefinition Height="3*" />
  14:          <RowDefinition Height="1*" />
  15:       </Grid.RowDefinitions>
  16:       <Grid.ColumnDefinitions>
  17:          <ColumnDefinition Width="200*" />
  18:          <ColumnDefinition Width="200*" />
  19:       </Grid.ColumnDefinitions>
  20:       <Slider Height="22"
  21:               Margin="0,20,0,0"
  22:               Name="slider1"
  23:               VerticalAlignment="Top"
  24:               Maximum="100"
  25:               SmallChange="1"
  26:               Value="50"
  27:               LargeChange="10" />
  28:       <TextBlock Grid.Column="1"
  29:                  Height="21"
  30:                  HorizontalAlignment="Left"
  31:                  Margin="5,0,0,0"
  32:                  Name="textBlock1"
  33:                  Text="{Binding ElementName=slider1, Path=Value}"
  34:                  VerticalAlignment="Center"
  35:                  Width="95"
  36:                  FontFamily="Verdana"
  37:                  FontSize="18" />
  38:    </Grid>
  39: </UserControl>

 

The key new Silverlight 3 feature is found on line 53 where we bind directly to the Slider.

This is just too much fun.

ecq100

Example-Code Quality, GuaranteedThis code was compiled with Silverlight 3 (Beta) using Visual Studio 10 (Beta) on Windows 7 (RC).  For more on this guarantee, please see this page.

Published Wednesday, May 20, 2009 1:59 AM by jesseliberty
Filed under:

Comments

# re: Just Built My First SL3 / Dev 10 App

line 33 :)

can't wait to get my hands on vs 2010 beta 1

Wednesday, May 20, 2009 4:03 AM by 22khz

# re: Just Built My First SL3 / Dev 10 App

Where can I get the Silverlight 3 tool for Dev10

Wednesday, May 20, 2009 4:30 AM by tjkim

# re: Just Built My First SL3 / Dev 10 App

Silverlight 3, VS 2010 and Windows 7, now that is a stimulus package my machine can use.

Thanks Jesse.

Wednesday, May 20, 2009 5:39 AM by MoHassan

# re: Just Built My First SL3 / Dev 10 App

@22khz

I think Jesse meant 33, he was just testing us to see if we pay attention (to catch his mistakes) :-)

@tjkim;

You should be able to use the same SL3 tools Beta 3 with Dev10

@Jesse

I honestly think VS2010 will bring many new Devs to SL and WPF, who stayed away from Blend.

Nice work Jesse (as always)!

..Ben

Wednesday, May 20, 2009 8:05 AM by BenHayat

# re: Just Built My First SL3 / Dev 10 App

hi, I will download a copy right away,

btw its on line 33, you putted line 53

Wednesday, May 20, 2009 9:17 AM by Johangsl

# re: Just Built My First SL3 / Dev 10 App

got to say its nice to have a wysiwyg editor in visual studio for xaml.  Is it possible to do the cool animation stuff (you know the timeline kind) that blend can do in visual studio?

Wednesday, May 20, 2009 11:15 AM by obsid

# re: Just Built My First SL3 / Dev 10 App

Hi,

When I try to install Silverlight3_Tools on VS2010 I get the following error

Build 9.0.30729.XX of Visual Studio 2008 SP1 or Visual Web Developer 2008 SP1 must be installed before installation can continue.  See <A HREF="go.microsoft.com/fwlink for download information.

I installed Silvrelight 3 sdk, What am i missing

Thanks

Wednesday, May 20, 2009 4:53 PM by lee_sl

# re: Just Built My First SL3 / Dev 10 App

Having the same problem as you lee_sl :(

Wednesday, May 20, 2009 7:25 PM by billb

# re: Just Built My First SL3 / Dev 10 App

Looks like the new Cider editor is powerful enough to keep me out of Blend (for the most part). I'm downloading right now.

But I must admit to being a little disappointed by your example. I believe that data binding between controls is an anti-pattern. It couples your UI components to each other, rather than allowing them to bind to a common model. Please don't teach people bad habits.

Wednesday, May 20, 2009 10:37 PM by MichaelLPerry1971

# re: Just Built My First SL3 / Dev 10 App

MichaelLPerry1971...

I'm not convinced that binding one control to another is a bad habit, though I suppose programmers may disagree. It does couple two components to one another (that is the sole reason for having element binding) but in the very common case I show there are four choices:

1. Use an event

2. Use a common model

3. Bind directly to the element

4. Create a custom class that consists of a slider with a text box

Of the four, I would contend that #3 is the simplest, most straight forward, easiest to maintain and thus the best solution if what you are trying to accomplish is to display the value of the slider in the textblock.

So I suppose I respectfully disagree.

Wednesday, May 20, 2009 10:48 PM by jesseliberty

# re: Just Built My First SL3 / Dev 10 App

Obsid,

I will do a much longer post on this topic, but I have totally modified my opinion.  Given that VS2010 will not have the level of support for timelines and for templating that Blend will have, I intend to move to a two-tool solution as a working environment.

-j

Wednesday, May 20, 2009 10:49 PM by jesseliberty

# re: Just Built My First SL3 / Dev 10 App

lee: the order of operations you want is:

1. Install visual studio 2008

2. Install the vs 2008 sp1

3. Install vs 2010 beta 1

Works great.

Wednesday, May 20, 2009 10:50 PM by jesseliberty

# Silverlight Cream for May 20, 2009 -- #597

In this Issue: Nigel Sampson , Jonathan van de Veen , Rod Paddock , Alex Knight , Arturo Toledo , Tim

Thursday, May 21, 2009 2:17 AM by Community Blogs

# re: Just Built My First SL3 / Dev 10 App

Thanks Jesse for the instant update.

We are moving on with you .............

Friday, May 22, 2009 8:48 AM by gigyjoseph

# re: Just Built My First SL3 / Dev 10 App

I tried the following, it did not work.

<Rectangle Height="42.218" HorizontalAlignment="Left" Margin="73,93,0,0" Name="rectangle1" Stroke="Black" StrokeThickness="1" VerticalAlignment="Top" Width="176.649">

           <Rectangle.Projection>

               <PlaneProjection RotationX="{Binding Path=Value, ElementName=slider1, Mode=TwoWay}"/>

           </Rectangle.Projection>

       </Rectangle>

I seem to run across this problem regarding Projections even when I use Border and Image elements.  Is it restricted to only a few type class?

Wednesday, June 24, 2009 3:47 PM by dolph29