views:

32

answers:

2

The example of this would be:

A textBox is bound to some data. There is a second text box which is not bind to anything. So I want to bind text box 2 to the same data 1st textBox is bound.

In other words I wan't to know if the DependencyObject stores some reference to it's data-bindings? If not, what is the way to find out all data-bindings of a specific object?

A: 

You can do this in code by calling the SetBinding method.

Peter van Kekem
I know how to set Binding I don't know how to get the reference to an existing binding.
Vitalij
I have looked in DependencyObject, it doesn't contain any reference to binding source, so I want to know where I can get this reference from.
Vitalij
GetBinding() :)
Peter van Kekem
+1  A: 

Try this

Xaml

<TextBox Name="c_textBox1" Text="{Binding Text1}"/>
<TextBox Name="c_textBox2" Text="No Binding"/>

Then we can set the binding of the TextProperty for c_textBox2 to the same as c_textBox1 with this code behind

BindingExpression bindingExpression = c_textBox1.GetBindingExpression(TextBox.TextProperty);
Binding parentBinding = bindingExpression.ParentBinding;
c_textBox2.SetBinding(TextBox.TextProperty, parentBinding);
Meleak
Thanks! That's what I have been looking for!
Vitalij
No problem :) Used this alot in a previous project where the bindings in a DataGrid wouldn't update so we had to force it with bindingExpression.UpdateSource
Meleak