Click here to Skip to main content
15,895,142 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi!

I have created customcontrol which includes controls like textblock, buttons, sliders etc. In customcontrol I have created public properties for vital controlproperties what I like to show outside to client who is using my customcontrol. For example my textblock text property in mycontrol

/// Public property of customcontrol header
public string Header
     {
          get { return txtBlockHeader.Text;  }
          set { txtBlockHeader.Text = value; }
      }


In clientside I can see my customcontrol and I can see my customcontrol property "Header" like I usually do with properties, BUT when I try to set databinding between my dataClass property and my customcontrol property I hit the wall. Here how I try to make bindings

//create bidings between dataClass property and customcontrol property
Binding binding = new Binding("Header");
binding.Mode = BindingMode.TwoWay;
binding.Source = dataClass;

//here I cant find Setbinding method like I usually do...
MyCustomControl.Header.SetBinding(....


Hope you got idea :)

Cheers!
Posted

Try changing the Header property to,

C#
public string Header
     {
          get { return txtBlockHeader.GetValue(TextBox.TextProperty).ToString();  }
          set { txtBlockHeader.SetValue(TextBox.TextProperty, value); }
      }


:thumbsup: Mark it as Answer is it really helped you.
 
Share this answer
 
Comments
paleGegg0 20-Dec-10 5:03am    
thank you! Problem solved. Helped me a lot :)
Hi Raistu,

Maybe there is some misunderstanding, but:
You declared the Header property as string and expect to have it a SetBinding - method? So either expose the TextBlockControl (txtBlockHeader) through the Header property, or let the Control handle the Binding.
 
Share this answer
 
Comments
paleGegg0 20-Dec-10 5:03am    
thank you! Problem solved. Helped me a lot :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900