如何从使用MultiBinding限制的控件中检索(使用代码隐藏)绑定表达式?
答案 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);
希望这有帮助