以编程方式从控件中检索MultiBindingExpression

时间:2013-10-14 08:31:09

标签: wpf binding

如何从使用MultiBinding限制的控件中检索(使用代码隐藏)绑定表达式?

1 个答案:

答案 0 :(得分:1)

使用BindingOperations.GetMultiBindingExpression方法。

示例:

        <TextBlock x:Name="MyTextBlock">
            <TextBlock.Text>
                <MultiBinding Converter="{StaticResource myConverter}">
                    <Binding ElementName="lst" Path="Items.Count" />
                    <Binding ElementName="txtName" Path="Text" />
                    <Binding ElementName="txtAge" Path="Text" />
                </MultiBinding>
            </TextBlock.Text>
        </TextBlock>

从代码中获取它:

TextBlock textblock = FindName("MyTextBlock") as TextBlock;
var bindingExpression = BindingOperations.GetMultiBindingExpression(textblock, TextBlock.TextProperty);

希望这有帮助