Geeks With Blogs
Bander Alsharfi yet another WinFX fan!

I didn't understand your question well, were you talking about databinding or control binding?
Anyway down below are 2 scenarios to explain basic control binding, If you meant databinding; let me know.

In this scenario we will bind a Rectangle to a Slider control, where the Slider controls the Rectangle's width, so when the Slider's value increases the Rectangle's width increases too.

<Window x:Class="Window1"

xmlns="http://schemas.microsoft.com/winfx/avalon/2005"

xmlns:x="http://schemas.microsoft.com/winfx/xaml/2005"

Title="ControlsBinding"

Width="210"

Height="180"

>

<StackPanel>

<Slider Name="WidthSlider" Maximum="200" Minimum="10" />

<Rectangle Fill="SteelBlue" Height="100" Width="{Binding ElementName=WidthSlider, Path=Value}" />

</StackPanel>

</Window>

Note also that shapes like Rectangle derive from FrameworkElement, which means that they participate in the layout system. The impact is that in the control below, as the Rectangle increases in size, so the ellipse shrinks to fill the remaining avilable space.

<Window x:Class="Window1"

xmlns="http://schemas.microsoft.com/winfx/avalon/2005"

xmlns:x="http://schemas.microsoft.com/winfx/xaml/2005"

Title="Controls Binding"

Width="410"

Height="180"

>

<StackPanel>

<Slider Name="WidthSlider" Maximum="200" Minimum="10" />

<StackPanel Orientation="Horizontal">

<Rectangle Fill="SteelBlue" Height="100" Width="{Binding ElementName=WidthSlider, Path=Value}" />

<Ellipse Fill="Teal" Width="150" Height="100"/>

</StackPanel>

</StackPanel>

</Window>



Posted on Saturday, January 21, 2006 11:55 AM | Back to top


Comments on this post: Binding in XAML

# re: Binding in XAML
Requesting Gravatar...
i want to answering one fucking quetion: where is brian???????
Left by gad on Aug 27, 2007 8:23 AM

# re: Binding in XAML
Requesting Gravatar...
I have one doubt. I am having a control, for which i need to set the Margin-> Top property alone which is of one image control's top property value. Rest of the margin properties should follow its own default.

The scenario is, i am displaying a textbox, which should be on the same top position where the image's top is. There are many such images, whenever i click on each image, this textbox/block should be available on the same top position.
Left by Aravind on Oct 31, 2008 6:02 AM

Your comment:
 (will show your gravatar)


Copyright © Bander Alsharfi | Powered by: GeeksWithBlogs.net