tags:

views:

31

answers:

2

e.g.

TextBox has a Text property, but I cannot bind to it, if I am going to bind, I have to bind to the TextProperty dependency property.

e.g.

textbox.Text = new Binding("mypath"); does not work

and I need

textbox.SetBinding(TextBoxBase.TextProperty, "mypath")

BUT, and this is a huge but, I don't know that it is property "textbox.Text" until runtime. I'm trying to set the binding via relection information, so I know I have a framework element, and I know i have some property. it might be text, it might be itemssource, or something else.

so given an arbitrary property that is backed by a dependency property identifier, how can i find the dependency property identifier for that property?

+2  A: 

While not required, the strongly encouraged convention is to append the word Property to the CLR property when naming the DependencyProperty field. I would start by looking for that.

Gideon Engelberth
+1  A: 

The System.ComponentModel.DependencyPropertyDescriptor class may help you out here.

However, my recommendation would be to ask, from a larger perspective, why do you believe you need to choose that binding at runtime? I suspect there's probably a better way.

FMM
+1, that's probably the best way. You need to use the FromName method
Thomas Levesque
at runtime, because I'm writing a convention over configuration binding system, kinda like caliburn micro, but instead of hard code mapping the default properties, i want to be able to bind based on things like DefaultProperty for a given control
jrwren