【发布时间】:2020-07-01 17:42:47
【问题描述】:
我在自定义控件中有一个输入字段。我已经为它创建了可绑定属性。
这是我的代码:
public string MyEntry
{
get => (string)GetValue(MyEntryProperty);
set => SetValue(MyEntryProperty, value);
}
public static BindableProperty MyEntryProperty = BindableProperty.Create(
propertyName: "MyEntry",
returnType: typeof(string),
declaringType: typeof(MyView),
defaultValue: string.Empty,
defaultBindingMode: BindingMode.TwoWay,
propertyChanged:MyEntryPropertyChanged );
public static void MyEntryPropertyChanged(BindableObject bindable, object oldValue, object newValue)
{
var cView = (MyView)bindable;
cView.myent.Text = (string)newValue;
}
然后在我的实际视图 xaml 中:
但它不起作用。?有什么建议吗?
【问题讨论】:
-
属性不是Text,而是叫
MyEntryProperty。这将是正确的绑定<MyEntry MyEntry={Binding Something}/>... 但我不确定它是否可能具有声明类型和具有相同名称的属性。 -
你到底想做什么?似乎您只需要使用
Entry而无需使用自定义条目。 -
更新了 xaml。基本上自定义控件具有输入字段,我正在尝试通过可绑定属性捕获输入字段文本,但它不起作用。
标签: c# xaml xamarin xamarin.forms