私はBindingExpression
にアクセスするXamarin.Forms
で利用可能な任意のパブリックAPIがあるとは思わない - しかし、あなたは関連するBinding
ので、BindingExpression
public static class BindingObjectExtensions
{
public static Binding GetBinding(this BindableObject self, BindableProperty property)
{
var methodInfo = typeof(BindableObject).GetTypeInfo().GetDeclaredMethod("GetContext");
var context = methodInfo?.Invoke(self, new[] { property });
var propertyInfo = context?.GetType().GetTypeInfo().GetDeclaredField("Binding");
return propertyInfo?.GetValue(context) as Binding;
}
public static object GetBindingExpression(this Binding self)
{
var fieldInfo = self?.GetType().GetTypeInfo().GetDeclaredField("_expression");
return fieldInfo?.GetValue(self);
}
}
使用例をアクセスするためにリフレクションを使用することができます - 結合ゲット - 式
var expr = this.GetBinding(TextProperty).GetBindingExpression();
使用例 - 結合パスを取得(更新07/27)
//to access path - you can directly use the binding object
var binding = this.GetBinding(TextProperty);
var path = binding?.Path;
出典
2017-07-27 05:17:35
Ada
優れています。私はこれまでにこのようなことをしてきました。 Xamarinチームは、何の理由もなく私たちからものを隠すのが好きです。 –
これをテストします。 –
BindablePropertyを取得する方法を説明するビットを追加することがありますか? _associatedObject.GetBinding(Entry.TextProperty)のような静的なエントリから見ている人は、 – Andrey