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