当前位置: 首页>>代码示例>>C#>>正文


C# ContentPage.SetBinding方法代码示例

本文整理汇总了C#中ContentPage.SetBinding方法的典型用法代码示例。如果您正苦于以下问题:C# ContentPage.SetBinding方法的具体用法?C# ContentPage.SetBinding怎么用?C# ContentPage.SetBinding使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ContentPage的用法示例。


在下文中一共展示了ContentPage.SetBinding方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: TemplatedTabbedGallery

		public TemplatedTabbedGallery()
		{
			Title = "Templated Tabbed Gallery";
			_items = new ObservableCollection<Item> {
				CreateItem(),
				CreateItem()
			};

			ItemsSource = _items;

			ItemTemplate = new DataTemplate (() => {
				var page = new ContentPage();
				page.SetBinding (TitleProperty, "Title");
				page.SetBinding (IconProperty, "Icon");

				var layout = new StackLayout();

				var label = new Label();
				label.SetBinding (Label.TextProperty, "Content");
				layout.Children.Add (label);

				var add = new Button ();
				add.SetBinding (Button.TextProperty, "InsertTabText");
				add.Clicked += (sender, args) => _items.Insert (_items.IndexOf ((Item)add.BindingContext) + 1, CreateItem());
				layout.Children.Add (add);

				var titleNum = 0;
				var change = new Button ();
				change.SetBinding (Button.TextProperty, "ChangeTitleText");
				change.Clicked += (sender, args) => ((Item) change.BindingContext).Title = ("Title: " + titleNum++);
				layout.Children.Add (change);

				var move = new Button ();
				move.SetBinding (Button.TextProperty, "MoveTabText");
				move.Clicked += (sender, args) => {
					int originalIndex = _items.IndexOf ((Item) add.BindingContext);
					int index = originalIndex + 1;
					if (index == _items.Count)
						index = 0;

					_items.Move (originalIndex, index);
				};
				layout.Children.Add (move);

				var remove = new Button ();
				remove.SetBinding (Button.TextProperty, "RemoveTabText");
				remove.Clicked += (sender, args) => {
					if (_items.Count == 0) {
						layout.Children.Add (new Label {
							Text = "No more tabs"
						});
					}
					_items.Remove ((Item)remove.BindingContext);
				};
				layout.Children.Add (remove);

				var reset = new Button ();
				reset.SetBinding (Button.TextProperty, "ResetAllTabsText");
				reset.Clicked += (sender, args) => {
					_count = 0;
					ItemsSource = _items = new ObservableCollection<Item> { CreateItem(), CreateItem() };
				};
				layout.Children.Add (reset);

				var nextPage = new Button ();
				nextPage.SetBinding (Button.TextProperty, "NextPageText");
				nextPage.Clicked += (sender, args) => {
					int index = _items.IndexOf ((Item) nextPage.BindingContext) + 1;
					if (index == _items.Count)
						index = 0;

					SelectedItem = _items[index];
				};
				layout.Children.Add (nextPage);

				page.Content = new ScrollView { 
					Padding = new Thickness (20, 0),
					Content = layout 
				};

				return page;
			});
		}
开发者ID:Costo,项目名称:Xamarin.Forms,代码行数:83,代码来源:TemplatedTabbedGallery.cs

示例2: TemplatedCarouselGallery

		public TemplatedCarouselGallery()
		{
			NavigationPage.SetHasNavigationBar (this, false);

			_items = new ObservableCollection<Item> {
				CreateItem(),
				CreateItem(),
			};

			ItemsSource = _items;

			ItemTemplate = new DataTemplate (() => {
				var page = new ContentPage ();

				page.Padding = new Thickness (0,30,0,0);
				page.SetBinding (TitleProperty, "Title");

				var layout = new StackLayout { Spacing = 0 };

				var label = new Label();
				label.SetBinding (Label.TextProperty, "Content");
				layout.Children.Add (label);

				var swipeHereLabel = new Label {
					Text = "Swipe Here",
					HeightRequest = 40
				};

				layout.Children.Add (swipeHereLabel);

				var add = new Button ();
				add.SetBinding (Button.TextProperty, "InsertTabText");
				add.Clicked += (sender, args) => _items.Insert (_items.IndexOf ((Item)add.BindingContext) + 1, CreateItem());
				layout.Children.Add (add);

				var change = new Button ();
				change.SetBinding (Button.TextProperty, "ChangeTitleText");
				change.Clicked += (sender, args) => ((Item) change.BindingContext).Title = (new Random().Next().ToString());
				layout.Children.Add (change);

				var remove = new Button ();
				remove.SetBinding (Button.TextProperty, "RemoveTabText");
				remove.Clicked += (sender, args) => _items.Remove ((Item)remove.BindingContext);
				layout.Children.Add (remove);

				var reset = new Button ();
				reset.SetBinding (Button.TextProperty, "ResetAllTabsText");
				reset.Clicked += (sender, args) => {
					_count = 0;
					ItemsSource = _items = new ObservableCollection<Item> { CreateItem(), CreateItem() };
				};
				layout.Children.Add (reset);

				var nextPage = new Button ();
				nextPage.SetBinding (Button.TextProperty, "NextPageText");
				nextPage.Clicked += (sender, args) => {
					int index = _items.IndexOf ((Item) nextPage.BindingContext) + 1;
					if (index == _items.Count)
						index = 0;

					SelectedItem = _items[index];
				};
				layout.Children.Add (nextPage);

				var delayReset = new Button { Text = "Delayed reset" };
				delayReset.SetBinding (Button.TextProperty, "DelayedResetText");
				delayReset.Clicked += (sender, args) => {
					ItemsSource = null;

					Task.Delay (5000).ContinueWith (t => {
						_count = 0;
						ItemsSource = _items = new ObservableCollection<Item> { CreateItem(), CreateItem() };
					}, TaskScheduler.FromCurrentSynchronizationContext());
				};

				layout.Children.Add (delayReset);

				page.Content = new ScrollView { 
					Padding = new Thickness (60, 0),
					Content = layout 
				};
				return page;
			});
		}
开发者ID:Costo,项目名称:Xamarin.Forms,代码行数:84,代码来源:TemplatedCarouselGallery.cs

示例3: BackgroundImageGallery

		public BackgroundImageGallery ()
		{
			var contentIntabs = new Button { Text = "Tabbed children" };
			contentIntabs.Clicked += async (sender, args) => {
				await Navigation.PushModalAsync (new TabbedPage {
					ItemTemplate = new DataTemplate (() => {
						var page = new ContentPage();
						page.SetBinding (BackgroundImageProperty, ".");
						return page;
					}),

					ItemsSource = new[] {
						"oasis.jpg",
						"crimson.jpg"
					}
					/*ItemsSource = new[] {
					"http://www.zemwallpaper.com/wp-content/uploads/2014/05/Desktop-background-download-21.jpg",
					"http://www.zemwallpaper.com/wp-content/uploads/2014/05/Desktop-background-download-31.jpg",
					"http://www.zemwallpaper.com/wp-content/uploads/2014/05/Desktop-background-download-61.jpg",
					"http://www.zemwallpaper.com/wp-content/uploads/2014/05/Desktop-background-download-71.jpg"
				};*/
				});
			};

			var contentInCarosel = new Button { Text = "Carousel children" };
			contentInCarosel.Clicked += async (sender, args) => {
				await Navigation.PushModalAsync (new CarouselPage {
					ItemTemplate = new DataTemplate (() => {
						var page = new ContentPage();
						page.SetBinding (BackgroundImageProperty, ".");
						return page;
					}),

					ItemsSource = new[] {
						"oasis.jpg",
						"crimson.jpg"
					}
					/*ItemsSource = new[] {
					"http://www.zemwallpaper.com/wp-content/uploads/2014/05/Desktop-background-download-21.jpg",
					"http://www.zemwallpaper.com/wp-content/uploads/2014/05/Desktop-background-download-31.jpg",
					"http://www.zemwallpaper.com/wp-content/uploads/2014/05/Desktop-background-download-61.jpg",
					"http://www.zemwallpaper.com/wp-content/uploads/2014/05/Desktop-background-download-71.jpg"
				};*/
				});
			};

			var navigation = new Button { Text = "NavigationPage"};
			navigation.Clicked += async (sender, args) => {
				await Navigation.PushModalAsync (new NavigationPage (new ContentPage {
						Content = new Label {
							Text = "Text",
							FontSize = 42
						}})
					{
						BackgroundImage = "oasis.jpg"
					}
				);
			};

			var carousel = new Button { Text = "CarouselPage" };
			carousel.Clicked += async (sender, args) => {
				await Navigation.PushAsync (new CarouselPage {
					BackgroundImage = "crimson.jpg",
					ItemsSource = new[] { "test1", "test2" }
				});
			};

			var tabbed = new Button { Text = "TabbedPage" };
			tabbed.Clicked += async (sender, args) => {
				await Navigation.PushAsync (new TabbedPage {
					BackgroundImage = "crimson.jpg",
					ItemsSource = new[] { "test1", "test2" }
				});
			};

			var master = new Button { Text = "MasterDetail" };
			master.Clicked += async (sender, args) => {
				await Navigation.PushModalAsync (new MasterDetailPage {
					Master = new ContentPage { Title = "Master" },
					Detail = new ContentPage(),
					BackgroundImage = "crimson.jpg",
				});
			};

			Content = new StackLayout {
				Children = {
					navigation,
					carousel,
					tabbed,
					master,
					contentIntabs,
					contentInCarosel
				}
				
			};
		}
开发者ID:Costo,项目名称:Xamarin.Forms,代码行数:96,代码来源:BackgroundImageGallery.cs


注:本文中的ContentPage.SetBinding方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。