【问题标题】:Binding basis using a Flex Layout xamarin使用 Flex Layout xamarin 的绑定基础
【发布时间】:2020-07-16 09:22:38
【问题描述】:

在这种情况下,可以用绑定替换new FlexBasis(0.3f, true) 吗?

FlexLayout ftk = new FlexLayout
{
    Direction = FlexDirection.Row
};
FrameMenu customFrameAide = new FrameMenu();
FlexLayout.SetBasis(customFrameAide, new FlexBasis(0.3f, true));
ftk.Children.Add(customFrameAide);

【问题讨论】:

    标签: c# xamarin binding


    【解决方案1】:

    是否可以通过绑定替换新的 FlexBasis(0.3f, true) ?

    当然可以。如果我们检查源代码,BasisFlexLayout 中的可绑定属性

    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");  
    

    【讨论】:

      猜你喜欢
      • 2019-07-11
      • 2019-11-14
      • 2011-02-28
      • 1970-01-01
      • 2022-06-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多