Silverlight: programmatically binding management properties

The big picture: I have a custom child control that generates various text fields, datepickers, combos, etc. based on the properties that I set. This control is embedded in various places in my SL application.

I usually use the MVVM pattern, and I want to bind the values โ€‹โ€‹of these dynamic controls to my main page view model.

I always know that there will be 8 controls on the form, so I can have dependency properties to bind the controls. Then, controls that reference this control can use the data binding that was entered when the MVVM template was saved.

Question: how to program values โ€‹โ€‹of dynamic controls for dependency properties?

Thanks Mark

+6
silverlight mvvm binding
source share
2 answers

Suppose you created a simple TextBox dynamically, and you want to add a binding to the Text property: -

Binding binding = new Binding("SomeProperty"); binding.Mode = BindingMode.TwoWay; txtBox.SetBinding(TextBox.TextProperty, binding); 

Where txtBox is a dynamically created TextBox that you want to observe / mutate.

+10
source share

Mark, I'm not quite sure I understood the implications in your question, but did you consider the Binding class? For example:

 Customer customer = new Customer(); TextBox box = new TextBox(); Binding binding = new Binding("FullName"); binding.Source = customer; box.SetBinding(TextBox.TextProperty, binding); 

This binds the Text dependency property of the TextBox to the FullName property of the client object.

+8
source share

All Articles