3

We can bind properties of controls to Data Context like

Is there any way to bind control to existing Control in Code behind ?

If i already have text box in My Data context is there any way to bind this textbox in XAML to another text box.

Wajeed Shaikh
  • 3,078
  • 1
  • 23
  • 30

1 Answers1

5

You cannot bind all the properties from one control to another control in datacontext automatically. But you can bind your entire control from DataContext into ContentControl as Content.

Let's say you have 'MyTextBox' property in your current DataContext. Then in XAML you can do the following:

 <ContentControl Content="{Binding MyTextBox}" />  

Which probably should work (if you do not assign MyTextBox as child somewhere else also)

Snowbear
  • 16,924
  • 3
  • 43
  • 67
  • 1
    It works as I want. Previously i was Using Whats Difference or which is Better way ? – Wajeed Shaikh Mar 01 '11 at 04:42
  • 2
    @010, ContentControl is a base for building controls which have something to be displayed inside them. In your case there will be no difference between `ContentControl` and `ContentPresenter`. See some more details here: http://stackoverflow.com/questions/1287995/whats-the-difference-between-contentcontrol-and-contentpresenter – Snowbear Mar 01 '11 at 08:56