Shimmy Weitzhandler
Shimmy Weitzhandler

Reputation: 104821

How do I programmatically bind a ContentControl's content to the DataContext?

Can someone help me translate this to CLR code:

<ContentControl Content="{Binding}" />

Upvotes: 2

Views: 3419

Answers (3)

itowlson
itowlson

Reputation: 74842

Use the SetBinding method:

ccDetails.SetBinding(ContentControl.ContentProperty, new Binding())

Upvotes: 2

bendewey
bendewey

Reputation: 40265

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);
}

Upvotes: 0

Shimmy Weitzhandler
Shimmy Weitzhandler

Reputation: 104821

This works for me:

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

Would love to hear about better ideas.

Upvotes: 0

Related Questions