开发者

How can I find the dependency property identifier for a given member property that exposes a dependency property?

e.g.

TextBox has a Text property, but开发者_如何学JAVA 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?


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.


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.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜