Xamarin.ios 暴露儿童';s属性进行绑定

Xamarin.ios 暴露儿童';s属性进行绑定,xamarin.ios,xamarin,xamarin.forms,Xamarin.ios,Xamarin,Xamarin.forms,假设我们有一个包含条目(或任何其他视图)的CustomView: public class CustomView : ContentView { public CustomView() { var entry = new Entry(); Content = entry; } } 如何公开条目的文本属性以使视图的文本属性可绑定?因此视图的文本属性应该是双向可绑定的,并且应该与条目的文本属性同步。您可以创建自己的可绑定属性。在本例中,由于它

假设我们有一个包含条目(或任何其他视图)的CustomView:

public class CustomView : ContentView
{
    public CustomView()
    {
        var entry = new Entry();
        Content = entry;
    }
}

如何公开条目的文本属性以使视图的文本属性可绑定?因此视图的文本属性应该是双向可绑定的,并且应该与条目的文本属性同步。

您可以创建自己的可绑定属性。在本例中,由于它是一个条目,请确保默认绑定模式为双向。然后您可以将条目的BindingContext设置为当前对象,并将ContentView.Text绑定到Entry.TextProperty

公共类CustomView:ContentView
{
公共自定义视图()
{
var条目=新条目();
entry.SetBinding(entry.TextProperty,“Text”);
entry.BindingContext=this;
}
公共静态只读BindableProperty TextProperty=
Create(“Text”、typeof(string)、typeof(CustomView)、default(string)、BindingMode.TwoWay);
公共字符串文本{
获取{return(string)GetValue(TextProperty);}
set{SetValue(TextProperty,value);}
}
}

这是我第一次尝试的。此解决方案有一个问题:每次键入文本字段时,它都会取消字段焦点(隐藏键盘)。