Get Binded Property Name - TypedBinding
vanKraster
201
Reputation points
I want to get the Property Name (string) or PropertyInfo (object) of the binded proberty inside a TypedBinding....
For now I use this and it works only if parent doesn't have a x:DataType
private static MethodInfo _bindablePropertyGetContextMethodInfo = typeof(BindableObject).GetMethod("GetContext", BindingFlags.NonPublic | BindingFlags.Instance);
private static FieldInfo _bindablePropertyContextBindingFieldInfo;
public static Binding GetBinding(this BindableObject self, BindableProperty property)
{
object bindablePropertyContext = _bindablePropertyGetContextMethodInfo.Invoke(self, new[] { property });
if (bindablePropertyContext != null)
{
FieldInfo propertyInfo = _bindablePropertyContextBindingFieldInfo =
_bindablePropertyContextBindingFieldInfo ??
bindablePropertyContext.GetType().GetField("Binding");
var valued = propertyInfo.GetValue(bindablePropertyContext);
if (valued is Binding)
return (Binding)valued;
else return null;
}
return null;
if it has a datatype the valued is of type
{Xamarin.Forms.Internals.TypedBinding<ViewModelNameAndPath,string>}
And it can't be casted to Binding, if I cast to BaseBinding it doesn't have the Path property.... How can I achieve this ?
Thanks
Developer technologies .NET Xamarin
5,380 questions
Sign in to answer