从dropdownbutton中的dropdowncontent绑定到后面的代码 [英] Binding to code behind from dropdowncontent in dropdownbutton
问题描述
我创建了一个用户控件,其中包含一个下拉按钮.
dropdownbuttons dropdowncontent包含许多复选框,这些复选框应该绑定到usercontrol本身的布尔属性(为了安全起见,直到按下ok并将布尔值复制到datacontext时,将其用作数据库搜索的搜索条件) ).
但是{StaticResource Self}不起作用,也没有寻找祖先类型.可能是因为复选框位于下拉按钮的dropdowncontent区域中.
问题是:如何在XAML中通过下拉按钮dropdowncontent绑定到用户控件上的属性(即,文件背后的代码中定义的属性)?
谢谢!
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!
推荐答案
我认为您必须使用 delegate
尝试以下示例:
在页面后面的代码中:
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:
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
这篇关于从dropdownbutton中的dropdowncontent绑定到后面的代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!