重新绑定视觉树中所有元素的所有属性? [英] Rebinding all properties of all elements in the visual tree?

查看:147
本文介绍了重新绑定视觉树中所有元素的所有属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道我可以重新绑定特定类型元素的特定属性的所有实例,如在此方法中重新绑定所有文本块的Text属性。

  public void Rebind()
{
foreach(LayoutRoot.GetDescendents()中的var textBlock OfType< TextBlock>())
{
BindingExpression bindExp = textBlock.GetBindingExpression(TextBlock.TextProperty);
if(bindExp!= null)
{
Binding bind = bindExp.ParentBinding;
textBlock.SetBinding(TextBlock.TextProperty,bind);
}
}
}

我想要能够要做的是重新绑定所有属性,其中包含可视化树中所有元素的绑定。更具体地说,我想重新绑定使用特定值转换器的所有绑定。

解决方案

FrameworkElement 不提供枚举当前适用于它的绑定表达式的集合。



为了实现这一点,您需要首先收集所有可能应用的依赖属性(至少在每个元素类型,但会增加进一步的复杂性),然后在每个元素上尝试 GetBindingExpression 。真正的丑陋和真实的慢。



设计这个要求的时间。


I know that I can rebind all instances of a specific property for a specific type of element, as in this method that rebinds the Text property of all Textblocks.

public void Rebind()
{
  foreach (var textBlock in LayoutRoot.GetDescendents().OfType<TextBlock>())
  {
    BindingExpression bindExp = textBlock.GetBindingExpression(TextBlock.TextProperty);
    if (bindExp != null)
    {
      Binding bind = bindExp.ParentBinding;
      textBlock.SetBinding(TextBlock.TextProperty, bind);
    }
  }
}

What I want to be able to do though is rebind all properties that have bindings for all elements in the visual tree. More specifically I would like to rebind all bindings that use a specific value converter. How might I do so?

解决方案

This isn't realistically acheivable since FrameworkElement provides no way to enumerate the set of binding expressions that currently apply to it.

In order to achieve this you would need to have first collected all the dependency properties that may apply (at least at a per element type but that adds further complications) and then attempt GetBindingExpression on each per element. Real ugly and real slow.

Time to design this requirement out.

这篇关于重新绑定视觉树中所有元素的所有属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆