views:

428

answers:

3

Can someone help me translate this to CLR code:

<ContentControl Content="{Binding}" />
A: 

This works for me:

Dim dc = ccDetails.GetValue(ContentControl.DataContextProperty)
ccDetails.SetValue(ContentControl.ContentProperty, dc)

Would love to hear about better ideas.

Shimmy
This is a one-time setvalue, not a binding declaration. I think you would find that this doesn't update when an INotifyPropertyChanged event fires.
bendewey
It worked for me even a property changed, I made a shallow unreliable test, I guess I will use itowlson's answer, thanks.
Shimmy
A: 

I believe it would be something similar to this:

public void SetupManualBinding()
{
    var cc = new ContentControl();
    var binding = new Binding();
    cc.SetBinding(ContentControl.ContentProperty, binding);
}
bendewey
Nope, that will set the *value* of Content to a Binding object. It won't *bind* the ContentProperty.
itowlson
@itowlson thanks, updated to binding, my fault.
bendewey
+1  A: 

Use the SetBinding method:

ccDetails.SetBinding(ContentControl.ContentProperty, new Binding())
itowlson
I was affraid to use it, I thought that Binding inherits DataContext only when initialized in Xaml under an existing DataContexed control, I just leaned that it's dynamic, thanks.
Shimmy