Silverlight: Use reflection to get the BindingExpression (and value) for controls having a ContentPr
Posted
by sfx
on Stack Overflow
See other posts from Stack Overflow
or by sfx
Published on 2010-03-22T22:31:00Z
Indexed on
2010/03/22
22:51 UTC
Read the original article
Hit count: 293
Hello,
I need to use reflection to get the binding value in a control that is a DataGridTemplateColumn (e.g HyperLinkButton). Does anyone know how I might do this? It seems simple enough to do this with a TextBlock because it has a “TextProperty” dependency property, but I can’t seem to get a binding expression from a control that does not have an immediate “TextProperty”. Here is the code I’m using to acquire the binding expression for a TextBlock:
FrameworkElement fe = (FrameworkElement)dependencyObj;
FieldInfo fi = fe.GetType().GetField("TextProperty");
BindingExpression bindingExpression = fe.GetBindingExpression((DependencyProperty)fi.GetValue(null))
However, the following code never works for a dependency object that is a HyperLinkButton:
FieldInfo fi = fe.GetType().GetField("ContentProperty");
Does anyone know how I might be able to get the BindingExpression (and binding value) for the content of a HyperLinkButton?
Cheers,
sfx
© Stack Overflow or respective owner