我听说WPF和XF绑定甚至其XAML语法之间有些不同,但我对WPF了解不多。
无论什么
如何使用级联绑定并控制组件,避免暴露其内部视图?
我总是使用这种方法,对我来说效果很好,看看它是否也适合你:
public class FlakeEntry2 : StackLayout
{
private Entry Entry;
private Label ErrorLabel;
public FlakeEntry2()
{
Entry = new Entry { };
ErrorLabel = new Label
{
FontAttributes = FontAttributes.Italic,
TextColor = Color.Red,
};
this.Entry.SetBinding(Entry.TextProperty, new Binding(nameof(EntryText), source: this));
// You'll need to do the same to label's and other properties you need expose, but you get rid of the 'OnChanged' methods
Children.Add(Entry);
Children.Add(ErrorLabel);
}
#region Text property which I am trying to bind
public static readonly BindableProperty EntryTextProperty = BindableProperty.Create(
propertyName: nameof(EntryText),
returnType: typeof(string),
declaringType: typeof(FlakeEntry2),
defaultValue: null,
defaultBindingMode: BindingMode.TwoWay);
public string EntryText
{
get { return GetValue(EntryTextProperty)?.ToString(); }
set { SetValue(EntryTextProperty, value); }
}
#endregion
}
不应更改XAML或VM上的任何内容。