Click here to Skip to main content
15,881,852 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
I have created a usercontrol, containing a dropdownbutton.

The dropdownbuttons dropdowncontent contains a number of checkboxes, which are supposed to be bound to boolean properties of the usercontrol itself (for safe keeping until a ok is pressed and the booleans gets copied to the datacontext where it is used as search criteria in a database search).

But {StaticResource Self} does not work and neither does looking for the ancestor type. Propably because the checkboxes are in the dropdowncontent area of the dropdownbutton.

The question is: How do I in XAML bind to properties on my usercontrol (that is, properties defined in the code behind file) from a dropdownbuttons dropdowncontent?

Thanks!
Posted

1 solution

Hi,

I think you must use delegate

Try this example:
In your code behind page:
protected void Page_Load(object sender, EventArgs e)
{
   //Do something?...
  ucOverride.SendValue += delegate(bool checkedOverride)
   {
      if (checkedOverride == true)
      {
          // Do somthing here?...
          //...
      }
   };
   //Do something?...
}


In you custom control page code behind:
C#
public delegate void SendData(bool checkedOverride);
public event SendData SendValue;


protected void btnOk_Click(object sender, EventArgs e)
{
  //UpdatePanel1.Update();
  bool checkeds = false;
  if (chkOverride.Checked)
  {
     checkeds = true;
  }
  else
  {
     checkeds = false;
  }
  if (SendValue != null)
  {
            SendValue(checkeds);
  }
}



Hope this could help...

Please remember to mark the replies as answers if they help and unmark them if they provide no help.

Regards,

Algem
 
Share this answer
 
Comments
Member 7454184 1-Jul-11 2:45am    
I should have told you I am using WPF... but you led me on the right track.

My mind was running in view/viewmodel track. I never even thought about using the values of the usercontrol's children directly. Thanks for giving me that thought.

Here's a link to some explanations about my trouble binding from dropdownbutton's content: http://www.telerik.com/community/forums/wpf/buttons/raddropdownbutton-dropdowncontent-property-breaks-logical-tree-inheritance.aspx

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