是否可以通过绑定替换新的 FlexBasis(0.3f, true) ?
当然可以。如果我们检查源代码,Basis 是 FlexLayout 中的可绑定属性
public static readonly BindableProperty BasisProperty;
所以如果你想在后面的代码中设置绑定。
首先,如果Basis会在运行时发生变化,则需要实现接口INotifyPropertyChanged。
在 ContentPage(或 ViewModel)中
public partial class MainPage : ContentPage,INotifyPropertyChanged
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
FlexBasis basis;
public FlexBasis Basis {
get {
return basis;
}
set
{
basis = value;
OnPropertyChanged("Basis");
}
}
并设置如下绑定(customFrameAide 似乎是 FlexLayout 的子类,对吧?)
customFrameAide.SetBinding(FlexLayout.BasisProperty, "Basis");