0

I'm trying to set a binding passing properties as parameters but i can't find a way on how to do it. This works:

Binding bind = new Binding();
//Some code
var tb = Control as TextBlock;
tb.SetBinding(TextBlock.TextProperty, bind );

What i would like to works is similar to this:

public FrameworkElement Control {get;set;}
public string dp {get;set;}
public string TypeOfControl {get;set;}    

var tb = Control as typeof(TypeOfControl);
tb.SetBinding(typeof(TypeOfControl).dp, bind );

I've already tried to follow this: DependencyProperty from string

        var descriptor = DependencyPropertyDescriptor.FromName(dp,typeof(TextBlock), typeof(Control));
        descriptor.SetValue(Control, bind);

But i get null value from descriptor.

Tony Abrams
  • 4,505
  • 3
  • 25
  • 32
Noschema
  • 31
  • 6

1 Answers1

0

This seems to work:

        Type type = Control.GetType();
        var descriptor = DependencyPropertyDescriptor.FromName(DependencyPropertyName, type, type);
        var dp = descriptor.DependencyProperty;
        Control.SetBinding(dp, Bind);

Where DependencyPropertyName in my case (testing with TextBlock) is "Text". I thought that it had to be "TextProperty". That's why descriptor was always null.

Noschema
  • 31
  • 6