开发者

Rebinding all properties of all elements in the visual tree?

开发者 https://www.devze.com 2023-01-07 14:44 出处:网络
I know that 开发者_Python百科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.

I know that 开发者_Python百科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.

0

精彩评论

暂无评论...
验证码 换一张
取 消