Enter a color in a textbox and change the color fill in a rectangle

Wow! This is exciting isn’t it?  With just a few lines of XAML you can change the fill of a rectangle.  Oh I am just so excited!

Using a few lines of XAML, on the phone, in Silverlight or in WPF, you can fill a rectangle using text that you type in a textbox!

Here is the XAML, I added it to the C# VS Express WPF, using the default WPF Application:

        <TextBox x:Name="textbox1" Width="200" Margin="152,56,152,215"></TextBox>
        <Rectangle x:Name="Box" Width="100" Height="50"
                Fill="{Binding ElementName=textbox1, Path=Text}">           


As with an earlier blog about comboboxes, the line:

Fill="{Binding ElementName=textbox1, Path=Text}">

Does the bulk of the work, the Fill of the rectangle uses binding to the element with the name of textbox1 and the path is Text, which is what you type into the textbox.


I am really excited about this:

excited red monster

Comments (0)