您可以创建自己的 BindableProperties。在这种情况下,由于它是一个条目,因此请确保默认绑定模式为 2-way。然后你可以将Entry的BindingContext设置为当前对象,并将ContentView.Text绑定到Entry.TextProperty。
public class CustomView : ContentView
{
public CustomView ()
{
var entry = new Entry ();
entry.SetBinding (Entry.TextProperty, "Text");
entry.BindingContext = this;
}
public static readonly BindableProperty TextProperty =
BindableProperty.Create ("Text", typeof(string), typeof(CustomView), default(string), BindingMode.TwoWay);
public string Text {
get { return (string)GetValue (TextProperty); }
set { SetValue (TextProperty, value); }
}
}