Binding inside your user control isn’t exactly obvious either.
It can be very difficult then to bind a property on those elements…
Let’s illustrate with a simple example: we want to display a list of products in a System. Data Error: 2 : Cannot find governing Framework Element or Framework Content Element for target element.
By default any binding for a Text Box is not updated until the field loses focus.
This didn’t suit my needs for an application I’m currently working on because I wanted the Binding source to be updated whenever something is entered into the Text Box.
Let’s say you try this: You will not receive an error for trying to set the user control’s data context.
You will, however, discover that all data binding has stopped working. Rather than explain why this is happening, let me simply share the solution.
It would be better to govern how often the binding source’s new values are pushed to the binding target. One solution is to create a value converter which governs the data flow between source and target.
The converter can keep a time stamp which it uses to determine when the new source values can be pushed to the target.
In the demo, the rapidly changing data source is called Random Number Engine.
It has a public property named Current, which returns a random number. When the value changes, the Property Changed event is raised so that the binding system will attempt to push that new value into a Text Block in the UI.
With WPF this is done easily by setting the Update Source Trigger property to Property Changed in the Binding definition, unfortunately this is not available for Silverlight.