當前位置: 首頁>>代碼示例>>C#>>正文


C# ContentPage.SetBinding方法代碼示例

本文整理匯總了C#中Xamarin.Forms.ContentPage.SetBinding方法的典型用法代碼示例。如果您正苦於以下問題:C# ContentPage.SetBinding方法的具體用法?C# ContentPage.SetBinding怎麽用?C# ContentPage.SetBinding使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Xamarin.Forms.ContentPage的用法示例。


在下文中一共展示了ContentPage.SetBinding方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: TabbedPageDemoPageCS

		public TabbedPageDemoPageCS ()
		{
			var booleanConverter = new NonNullToBooleanConverter ();

			ItemTemplate = new DataTemplate (() => {
				var nameLabel = new Label {
					FontSize = Device.GetNamedSize (NamedSize.Large, typeof(Label)),
					FontAttributes = FontAttributes.Bold,
					HorizontalOptions = LayoutOptions.Center
				};
				nameLabel.SetBinding (Label.TextProperty, "Name");

				var image = new Image { WidthRequest = 200, HeightRequest = 200 };
				image.SetBinding (Image.SourceProperty, "PhotoUrl");

				var familyLabel = new Label {
					FontSize = Device.GetNamedSize (NamedSize.Medium, typeof(Label)),
					FontAttributes = FontAttributes.Bold
				};
				familyLabel.SetBinding (Label.TextProperty, "Family");

				var subFamilyLabel = new Label {
					FontSize = Device.GetNamedSize (NamedSize.Medium, typeof(Label)),
					FontAttributes = FontAttributes.Bold
				};
				subFamilyLabel.SetBinding (Label.TextProperty, "Subfamily");

				var tribeLabel = new Label {
					FontSize = Device.GetNamedSize (NamedSize.Medium, typeof(Label)),
					FontAttributes = FontAttributes.Bold
				};
				tribeLabel.SetBinding (Label.TextProperty, "Tribe");

				var genusLabel = new Label {
					FontSize = Device.GetNamedSize (NamedSize.Medium, typeof(Label)),
					FontAttributes = FontAttributes.Bold
				};
				genusLabel.SetBinding (Label.TextProperty, "Genus");

				var subFamilyStackLayout = new StackLayout {
					Orientation = StackOrientation.Horizontal,
					Children = {
						new Label { Text = "Subfamily:", HorizontalOptions = LayoutOptions.FillAndExpand }, 
						subFamilyLabel
					}
				};				
				subFamilyStackLayout.SetBinding (VisualElement.IsVisibleProperty, new Binding ("Subfamily", BindingMode.Default, booleanConverter));

				var tribeStackLayout = new StackLayout { 
					Orientation = StackOrientation.Horizontal,
					Children = {
						new Label { Text = "Tribe:", HorizontalOptions = LayoutOptions.FillAndExpand },
						tribeLabel
					}	
				};
				tribeStackLayout.SetBinding (VisualElement.IsVisibleProperty, new Binding ("Tribe", BindingMode.Default, booleanConverter));

				var contentPage = new ContentPage {
					Icon = "monkeyicon.png",
					Content = new StackLayout {
						Padding = new Thickness (5, 25),
						Children = {
							nameLabel,
							image,
							new StackLayout {
								Padding = new Thickness (50, 10),
								Children = {
									new StackLayout { 
										Orientation = StackOrientation.Horizontal,
										Children = {
											new Label { Text = "Family:", HorizontalOptions = LayoutOptions.FillAndExpand },
											familyLabel
										}
									},
									subFamilyStackLayout,
									tribeStackLayout,
									new StackLayout {
										Orientation = StackOrientation.Horizontal,
										Children = {
											new Label { Text = "Genus:", HorizontalOptions = LayoutOptions.FillAndExpand },
											genusLabel
										}
									} 
								}
							} 

						}
					}
				};
				contentPage.SetBinding (TitleProperty, "Name");

				return contentPage;
			});

			ItemsSource = MonkeyDataModel.All;
		}
開發者ID:B3ND3R,項目名稱:recipes,代碼行數:96,代碼來源:TabbedPageDemoPageCS.cs


注:本文中的Xamarin.Forms.ContentPage.SetBinding方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。