Blog Stats
  • Posts - 9
  • Articles - 2
  • Comments - 23
  • Trackbacks - 13

 

Binding in XAML

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>




Feedback

# re: Binding in XAML

Gravatar i want to answering one fucking quetion: where is brian???????
8/27/2007 8:23 AM | gad

Post a comment





 

Please add 4 and 6 and type the answer here:

 

 

Copyright © Bander Alsharfi