如何绑定控制扩展器内部的contentemplate

时间:2010-08-19 14:15:01

标签: xaml silverlight-4.0 expander

我在Expasnders contentemplate中有一个文本框,我试图从扩展器外部绑定,但实际上不可能,我在扩展器中有另一个文本框,如下所示:

和扩展器外部的这个标记的完全重复,当txtTitle改变时,扩展器内的文本框更新它的文本proeprty,外部的文本框不更改,如何从扩展器外部绑定到txtTitle?

我将尝试用一些示例xaml来说明它(听起来很有趣)。

<TextBox Text="{Binding ElementName=ExpandertxtBox, Path=Text}" />

<toolkit:Expander>
<toolkit:Expander.ContentTemplate>
<TextBox Name="ExpandertxtBox" />
</toolkit:Expander.ContentTemplate>
</toolkit:Expander>

问题是绑定不会起作用,因为ExpandertxtBox在contentemplate中,我正在尝试从外部绑定,所以如何访问它,什么是正确的绑定路径?

1 个答案:

答案 0 :(得分:0)

我完成了创建此方法来处理我的问题

private void SetFilterBinding(object ctrl, object value, FilterOperator fo, string ctrlproperty, string dbproperty)
{
    var fd = new FilterDescriptor(dbproperty, fo, value);
    BindingOperations.SetBinding(fd, FilterDescriptor.ValueProperty, new Binding{ Path = new PropertyPath(ctrlproperty), Source = ctrl});
    nodeDomainDataSource.FilterDescriptors.Add(fd);
}