by Andrej Tozon
29. June 2009 21:26
Binding to elements is yet another feature, known to WPF-ers since v1. Silverlight 3 now allows bindings between UI elements and their properties, without having to use other classes as a workaround. There are numerous cases of when to use such binding, mostly to automate user interface, starting from the basic example of connecting a TextBox to a Slider (also included in the sample below). The interesting point to this binding is that it also works two-way: the TextBox not only displays the current value of the Slider, entering a new value also updates the Slider.
To make the sample a bit more interesting, I included a new kind of panel, which stores the current mouse coordinates when moving it over the panel. I added two TextBoxes and bound them to the panel to display these coordinates. There’s also an ellipse, which… well, see for yourself ;)
Additional Reading
http://community.irritatedvowel.com/blogs/pete_browns_blog/archive/2009/06/24/
From-Silverlight-in-Action-2nd-Edition_3A00_-UI-Element-Binding.aspx
Run the sample online
Source code below: