Xamarin.Forms 数据绑定

/**********************/

代码演示

/**********************/

using Xamarin.Forms;

namespace momo
{
	public partial class momoPage : ContentPage
	{
		public momoPage()
		{
			//InitializeComponent();

			Label label = new Label {
				Text = "Opacity Binding Demo",
				FontSize = Device.GetNamedSize(NamedSize.Large,typeof(Label)),
				VerticalOptions = LayoutOptions.CenterAndExpand,
				HorizontalOptions = LayoutOptions.Center
			};

			Slider slider = new Slider {
				VerticalOptions = LayoutOptions.CenterAndExpand
			};

			label.BindingContext = slider;

			label.SetBinding(Label.OpacityProperty,"Value");

			Padding = new Thickness(10, 0);
			Content = new StackLayout {
				Children = { label, slider }
			};
		}
	}
}


/**********************/

XAML演示

/**********************/



	
		


using Xamarin.Forms;

namespace momo
{
	public partial class momoPage : ContentPage
	{
		public momoPage()
		{
			InitializeComponent();
		}
	}
}

可以缩短标记。为Reference提供支持的公共类是ReferenceExtension,它定义了其内容属性为name。BindingExtension(不是公共类)的内容属性是Path,因此无需Name和Path参数和等号:

		




来源:Microsoft_Press_eBook_CreatingMobileAppswithXamarinForms_PDF.pdf ---- Chapter 16 Data binding

你可能感兴趣的:(Xamarin.Forms)