Welcome to irritatedVowel.com Sign in | Help

POKE 53280,0: Pete Brown's Blog

Silverlight, WPF, Windows Client Development, Woodworking, .NET Programming, CNC, Nature, and other topics.

Subscribe

Subscribe to my feed
Add to Technorati Favorites

My Book

Order my upcoming book, Silverlight in Action, covering Silverlight 4, ViewModel/MVVM, WCF RIA Services, MEF and more

About Pete Brown

Pete Brown is a Microsoft Developer Division Community Program Manager, focusing on Windows Client Development as well as a former Microsoft Silverlight MVP and INETA Speaker. Pete writes on a number of topics including Silverlight, WPF, .NET, woodworking and working as a consultant in the DC area. read more

Community Events


who's online

AddThis Social Bookmark Button

Silverlight 3 – UI Element to Element Binding

Silverlight 3 now allows UI elements to bind to each other’s properties. This is something WPF folks are pretty used to, but is new to the Silverlight world.

Element Binding is very simple to use. As of this writing, there are some restrictions as to what you can bind to (for example, Transforms were not supported at this time), but this will save a ton of the glue/proxy code many of us have been writing for the life of Silverlight 2.

To use Element Binding, simply include the ElementName property in the binding expression:

Text="{Binding Value, ElementName=SizeSlider}"

Here’s a simple example that uses a slider to resize a button. As the slider is moved, the value is displayed in the label, and the button is resized to that value.

<StackPanel Width="200" 
            VerticalAlignment="Center" 
            HorizontalAlignment="Center">

    <Slider x:Name="SizeSlider"
            Minimum="10"
            Maximum="200"
            Value="100" />
    
    <TextBlock x:Name="SizeLabel"
               Text="{Binding Value, ElementName=SizeSlider}" />

    <Button x:Name="MyButton"
            Content="Hello There"
            Width="{Binding Value, ElementName=SizeSlider}"
            Height="{Binding Value, ElementName=SizeSlider}" />

</StackPanel>

The screen shots below show the slider at 100, down to 24 and change, and up to 200. Notice that the textblock changes as does the size of the button, and all without a single line of code!

image image image

  Add to Technorati Favorites
Posted: Wednesday, March 18, 2009 2:30 PM by Pete.Brown
Filed under: ,

Comments

Community Blogs said:

For those of you watching the agenda for MIX09, the announcement of Silverlight 3 probably didn’t
# March 18, 2009 2:42 PM

DotNetShoutout said:

Thank you for submitting this cool story - Trackback from DotNetShoutout
# March 18, 2009 6:07 PM

Silverlight Playground said:

Links to Silverlight 3.0 resources
# March 19, 2009 4:31 AM

Rob Zelt - Lighting Up The Web said:

# March 22, 2009 2:40 PM

Delay's Blog said:

I came across a question on the Silverlight Toolkit support forum yesterday asking how to animate the
# April 9, 2009 4:10 PM

Frank La Vigne said:

# April 29, 2009 3:51 PM
Leave a Comment

(required) 

(required) 

(optional)

(required) 

Enter the text you see in the image:

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS