美文网首页
5. Binding绑定

5. Binding绑定

作者: shannoon | 来源:发表于2017-01-11 19:00 被阅读24次

1. 绑定模式,三种:

1.1 双向Binding(TwoWay)

  • 声明属性
public static readonly BindableProperty TextProperty = BindableProperty.Create(nameof(Text), typeof(string), typeof(RoundEntryView), defaultBindingMode: BindingMode.TwoWay);
        public string Text
        {
            get
            {
                return (string)this.GetValue(TextProperty);
            }
            set
            {
                this.SetValue(TextProperty, value);
            }
        }
  • 使用属性
"{Binding Model.VerifyCode, Mode=TwoWay}"
Paste_Image.png

2. xaml文件和xaml.cs文件分别做属性绑定

2.1 Xaml文件的绑定

                         ImageSize="{Binding UiModel.SelectedImageSize}"

绑定到自己的cs文件 ,格式如下:

                                           ViewModel="{Binding Path=BindingContext, Source={x:Reference PopupPage}}" />

2.2 xaml.cs文件的绑定方式SetBinding

绑定图片视图的图片源

            RoundedBoxViewasd.SetBinding(BackgroundColorProperty,new Binding("UiModel.BackgroundColor"));

如何使用SetBinding方法,看下面的API即可

    public static void SetBinding(this BindableObject self, BindableProperty targetProperty, string path, BindingMode mode = BindingMode.Default, IValueConverter converter = null, string stringFormat = null)

相关文章

网友评论

      本文标题:5. Binding绑定

      本文链接:https://www.haomeiwen.com/subject/pjvrbttx.html