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


C# DataTemplate.SetBinding方法代码示例

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


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

示例1: ImageCellListPage

		public ImageCellListPage ()
		{
			Title = "ImageCell List Gallery - Legacy";

			Device.OnPlatform (iOS: () => {
				if (Device.Idiom == TargetIdiom.Tablet) {
					Padding = new Thickness (0, 0, 0, 60);
				}
			});

			var dataTemplate = new DataTemplate (typeof (ImageCell));
			var stringToImageSourceConverter = new GenericValueConverter (
				obj => new FileImageSource {
					File = (string) obj
				}
				);
	
			dataTemplate.SetBinding (TextCell.TextProperty, new Binding ("Text"));
			dataTemplate.SetBinding (TextCell.TextColorProperty, new Binding ("TextColor"));
			dataTemplate.SetBinding (TextCell.DetailProperty, new Binding ("Detail"));
			dataTemplate.SetBinding (TextCell.DetailColorProperty, new Binding ("DetailColor"));
			dataTemplate.SetBinding (ImageCell.ImageSourceProperty, new Binding ("Image", converter: stringToImageSourceConverter));

			Random rand = new Random(250);

			var albums = new [] {
				"crimsonsmall.jpg",
				"oasissmall.jpg",
				"cover1small.jpg"
			};

			var label = new Label { Text = "I have not been selected" };

			var listView = new ListView {
				AutomationId = "ImageCellListView",
				ItemsSource = Enumerable.Range (0, 100).Select (i => new ImageCellTest {
					Text = "Text " + i,
					TextColor = i % 2 == 0 ? Color.Red : Color.Blue,
					Detail = "Detail " + i,
					DetailColor = i % 2 == 0 ? Color.Red : Color.Blue,
					Image = albums[rand.Next(0,3)]
				}),
				ItemTemplate = dataTemplate
			};

			listView.ItemSelected += (sender, args) => label.Text = "I was selected";

			Content = new StackLayout { Children = { label, listView } };

		}
开发者ID:Costo,项目名称:Xamarin.Forms,代码行数:50,代码来源:ImageCellListPage.cs

示例2: CellTypeList

		// TODO Add gallerys for ViewCell, ListView and TableView
		public CellTypeList ()
		{
			var itemList = new List<CellNavigation> {
				new CellNavigation ("TextCell List", new TextCellListPage ()),
				new CellNavigation ("TextCell Table", new TextCellTablePage ()),
				new CellNavigation ("ImageCell List", new ImageCellListPage ()),
				new CellNavigation ("ImageCell Url List", new UrlImageCellListPage()),
				new CellNavigation ("ImageCell Table", new ImageCellTablePage ()),
				new CellNavigation ("SwitchCell List", new SwitchCellListPage ()),
				new CellNavigation ("SwitchCell Table", new SwitchCellTablePage ()),
				new CellNavigation ("EntryCell List", new EntryCellListPage ()),
				new CellNavigation ("EntryCell Table", new EntryCellTablePage ()),
				new CellNavigation ("ViewCell Image url table", new UrlImageViewCellListPage())
			};
			
			ItemsSource = itemList;

			var template = new DataTemplate (typeof (TextCell));
			template.SetBinding (TextCell.TextProperty, new Binding ("CellType"));

			ItemTemplate = template;
			ItemSelected += (s, e) => {
				if (SelectedItem == null)
					return;

				var cellNav = (CellNavigation) e.SelectedItem;
				Navigation.PushAsync (cellNav.Page);
				SelectedItem = null;
			};
		}		
开发者ID:Costo,项目名称:Xamarin.Forms,代码行数:31,代码来源:CellTypeList.cs

示例3: SetBindingOverridesValue

		public void SetBindingOverridesValue()
		{
			var template = new DataTemplate (typeof (MockBindable));
			template.SetValue (MockBindable.TextProperty, "value");
			template.SetBinding (MockBindable.TextProperty, new Binding ("."));

			MockBindable bindable = (MockBindable) template.CreateContent();
			Assume.That (bindable.GetValue (MockBindable.TextProperty), Is.EqualTo (bindable.BindingContext));

			bindable.BindingContext = "binding";
			Assert.That (bindable.GetValue (MockBindable.TextProperty), Is.EqualTo ("binding"));
		}
开发者ID:Costo,项目名称:Xamarin.Forms,代码行数:12,代码来源:DataTemplateTests.cs

示例4: EntryCellListPage

		public EntryCellListPage ()
		{
			Title = "EntryCell List Gallery - Legacy";

			Device.OnPlatform (iOS: () => {
				if (Device.Idiom == TargetIdiom.Tablet) {
					Padding = new Thickness (0, 0, 0, 60);
				}
			});

			var dataTemplate = new DataTemplate (typeof(EntryCell));
			dataTemplate.SetBinding (EntryCell.LabelProperty, new Binding ("Label"));
			dataTemplate.SetBinding (EntryCell.LabelColorProperty, new Binding ("LabelColor"));
			dataTemplate.SetBinding (EntryCell.PlaceholderProperty, new Binding ("Placeholder"));

			var label = new Label {
				Text = "I have not been selected"
			};

			var listView = new ListView {
				ItemsSource = Enumerable.Range (0, 100).Select (i => new EntryCellTest {
					Label = "Label " + i,
					LabelColor =  i % 2 == 0 ? Color.Red : Color.Blue,
					Placeholder = "Placeholder " + i,
					PlaceholderColor =  i % 2 == 0 ? Color.Red : Color.Blue,
				}),
				ItemTemplate = dataTemplate
			};

			listView.ItemSelected += (sender, args) => {
				label.Text = "I have been selected";
			};

			

			Content = new StackLayout { Children = { label, listView } };
		}
开发者ID:Costo,项目名称:Xamarin.Forms,代码行数:37,代码来源:EntryCellListPage.cs

示例5: Init

		protected override void Init ()
		{
			var cells = new [] {
				new NavPageNameObject ("Close Master"),
				new NavPageNameObject ("Page 1"),
				new NavPageNameObject ("Page 3"),
				new NavPageNameObject ("Page 4"),
				new NavPageNameObject ("Page 5"),
				new NavPageNameObject ("Page 6"),
				new NavPageNameObject ("Page 7"),
				new NavPageNameObject ("Page 8"),
			};

			var template = new DataTemplate (typeof (TextCell));
			template.SetBinding (TextCell.TextProperty, "PageName");

			var listView = new ListView { 
				ItemTemplate = template,
				ItemsSource = cells
			};

			listView.BindingContext = cells;

			listView.ItemTapped += (sender, e) => {
				var cellName = ((NavPageNameObject)e.Item).PageName;
				if (cellName == "Close Master") {
					IsPresented = false;
				} else {
					Detail = new CustomNavDetailPage (cellName);
				}
			};

			var master = new ContentPage {
				Padding = new Thickness(0, 20, 0, 0),
				Title = "Master",
				Content = listView
			};
				
			Master = master;
			Detail = new CustomNavDetailPage ("Initial Page");

			MessagingCenter.Subscribe<NestedNavPageRootView> (this, "PresentMaster", (sender) => {
				IsPresented = true;
			});
		}
开发者ID:Costo,项目名称:Xamarin.Forms,代码行数:45,代码来源:Issue892.cs

示例6: ListViewTest

			public ListViewTest ()
			{
				Title = "List Page";

				var items = new[] {
					new TabbedPageWithListName () { Name = "Jason" },
					new TabbedPageWithListName () { Name = "Ermau" },
					new TabbedPageWithListName () { Name = "Seth" }
				};

				var cellTemplate = new DataTemplate (typeof(TextCell));
				cellTemplate.SetBinding (TextCell.TextProperty, "Name");

				Content = new ListView () {
					ItemTemplate = cellTemplate,
					ItemsSource = items
				};
			}
开发者ID:Costo,项目名称:Xamarin.Forms,代码行数:18,代码来源:TabbedPageWithList.cs

示例7: ListViewCustomCellPage

			public ListViewCustomCellPage(ListViewCachingStrategy strategy)
			{
				DataTemplate it = new DataTemplate(typeof(CustomCell));
				it.SetBinding(CustomCell.TextProperty, "Title");
				it.SetBinding(CustomCell.DetailProperty, "SubTitle");
				ListView listV = new ListView(strategy)
				{
					HasUnevenRows = true,
					ItemTemplate = it,
					ItemsSource = GetData()
				};
				Content = listV;
			}
开发者ID:ytn3rd,项目名称:Xamarin.Forms,代码行数:13,代码来源:Bugzilla39486.cs

示例8: ListViewTextCellPage

			public ListViewTextCellPage()
			{
				DataTemplate it = new DataTemplate(typeof(TextCell));
				it.SetBinding(TextCell.TextProperty, "Title");
				it.SetBinding(TextCell.DetailProperty, "SubTitle");
				ListView listV = new ListView
				{
					HasUnevenRows = true,
					ItemTemplate = it,
					ItemsSource = GetData()
				};
				Content = listV;
			}
开发者ID:ytn3rd,项目名称:Xamarin.Forms,代码行数:13,代码来源:Bugzilla39486.cs

示例9: SetBindingInvalid

		public void SetBindingInvalid()
		{
			var template = new DataTemplate (typeof (MockBindable));
			Assert.That (() => template.SetBinding (null, new Binding (".")), Throws.InstanceOf<ArgumentNullException>());
			Assert.That (() => template.SetBinding (MockBindable.TextProperty, null), Throws.InstanceOf<ArgumentNullException>());
		}
开发者ID:Costo,项目名称:Xamarin.Forms,代码行数:6,代码来源:DataTemplateTests.cs

示例10: CorePageView


//.........这里部分代码省略.........
				new ListViewCoreGalleryPage { Title = "ListView Gallery" },
				new OpenGLViewCoreGalleryPage { Title = "OpenGLView Gallery" },
				new PickerCoreGalleryPage { Title = "Picker Gallery" },
				new ProgressBarCoreGalleryPage { Title = "ProgressBar Gallery" },
				new ScrollGallery { Title = "ScrollView Gallery" }, 
				new ScrollGallery(ScrollOrientation.Horizontal) { Title = "ScrollView Gallery Horizontal" },
				new ScrollGallery(ScrollOrientation.Both) { Title = "ScrollView Gallery 2D" },
				new SearchBarCoreGalleryPage { Title = "SearchBar Gallery" },
				new SliderCoreGalleryPage { Title = "Slider Gallery" },
				new StepperCoreGalleryPage { Title = "Stepper Gallery" },
				new SwitchCoreGalleryPage { Title = "Switch Gallery" },
				new TableViewCoreGalleryPage { Title = "TableView Gallery" },
				new TimePickerCoreGalleryPage { Title = "TimePicker Gallery" },
				new WebViewCoreGalleryPage { Title = "WebView Gallery" },
				//pages
 				new RootContentPage ("Content") { Title = "RootPages Gallery" },
				new MasterDetailPageTabletPage { Title = "MasterDetailPage Tablet Page" },
				// legacy galleries
				new AbsoluteLayoutGallery { Title = "AbsoluteLayout Gallery - Legacy" }, 
				new BoundContentPage { Title = "BoundPage Gallery - Legacy" }, 
				new BackgroundImageGallery { Title = "BackgroundImage gallery" },
				new ButtonGallery { Title = "Button Gallery - Legacy" }, 
				new CarouselPageGallery { Title = "CarouselPage Gallery - Legacy" },
				new CellTypesListPage { Title = "Cells Gallery - Legacy" },
				new ClipToBoundsGallery { Title = "ClipToBounds Gallery - Legacy" }, 
				new ControlTemplatePage { Title = "ControlTemplated Gallery - Legacy" },
				new ControlTemplateXamlPage { Title = "ControlTemplated XAML Gallery - Legacy" },
				new DisposeGallery { Title = "Dispose Gallery - Legacy" }, 
				new EditorGallery { Title = "Editor Gallery - Legacy" },
				new EntryGallery { Title = "Entry Gallery - Legacy" }, 
				new FrameGallery  { Title = "Frame Gallery - Legacy" }, 
				new GridGallery { Title = "Grid Gallery - Legacy" }, 
				new GroupedListActionsGallery { Title = "GroupedListActions Gallery - Legacy" }, 
				new GroupedListContactsGallery { Title = "GroupedList Gallery - Legacy" },
				new ImageGallery  { Title = "Image Gallery - Legacy" },
				new ImageLoadingGallery  { Title = "ImageLoading Gallery - Legacy" },
				new InputIntentGallery { Title = "InputIntent Gallery - Legacy" },
				new LabelGallery { Title = "Label Gallery - Legacy" },
				new LayoutAddPerformance { Title = "Layout Add Performance - Legacy" },
				new LayoutOptionsGallery { Title = "LayoutOptions Gallery - Legacy" },
				new LineBreakModeGallery { Title = "LineBreakMode Gallery - Legacy" },
				new ListPage { Title = "ListView Gallery - Legacy" },
				new ListScrollTo { Title = "ListView.ScrollTo" },
				new ListRefresh { Title = "ListView.PullToRefresh" },
				new ListViewDemoPage { Title = "ListView Demo Gallery - Legacy" },
				new MapGallery { Title = "Map Gallery - Legacy" }, 
				new MinimumSizeGallery { Title = "MinimumSize Gallery - Legacy" },
				new MultiGallery { Title = "Multi Gallery - Legacy" },
				new NavigationMenuGallery { Title = "NavigationMenu Gallery - Legacy" },
				new NavigationPropertiesGallery { Title = "Navigation Properties" },
#if HAVE_OPENTK
				new OpenGLGallery { Title = "OpenGLGallery - Legacy" },
#endif
				new PickerGallery {Title = "Picker Gallery - Legacy"}, 
				new ProgressBarGallery { Title = "ProgressBar Gallery - Legacy" }, 
				new RelativeLayoutGallery { Title = "RelativeLayout Gallery - Legacy" },
				new ScaleRotate { Title = "Scale Rotate Gallery - Legacy" }, 
				new SearchBarGallery { Title = "SearchBar Gallery - Legacy" },
				new SettingsPage { Title = "Settings Page - Legacy" }, 
				new SliderGallery { Title = "Slider Gallery - Legacy" },
				new StackLayoutGallery { Title = "StackLayout Gallery - Legacy" }, 
				new StepperGallery { Title = "Stepper Gallery - Legacy" },
				new StyleGallery {Title = "Style Gallery"},
				new StyleXamlGallery {Title = "Style Gallery in Xaml"},
				new SwitchGallery { Title = "Switch Gallery - Legacy" }, 
				new TableViewGallery { Title = "TableView Gallery - Legacy" }, 
				new TemplatedCarouselGallery { Title = "TemplatedCarouselPage Gallery - Legacy" }, 
				new TemplatedTabbedGallery { Title = "TemplatedTabbedPage Gallery - Legacy" }, 
 				new UnevenViewCellGallery { Title = "UnevenViewCell Gallery - Legacy" }, 
				new UnevenListGallery { Title = "UnevenList Gallery - Legacy" }, 
				new ViewCellGallery { Title = "ViewCell Gallery - Legacy" }, 
				new WebViewGallery {Title = "WebView Gallery - Legacy"},
			};

			titleToPage = pages.ToDictionary (o => o.Title);

			// avoid NRE for root pages without NavigationBar
			if (navigationBehavior == NavigationBehavior.PushAsync && rootPage.GetType () == typeof (CoreNavigationPage)) {
				pages.Add (new NavigationBarGallery ((NavigationPage)rootPage) { Title = "NavigationBar Gallery - Legacy" });
			}

			var template = new DataTemplate (typeof(TextCell));
			template.SetBinding (TextCell.TextProperty, "Title");

			BindingContext = pages;
			ItemTemplate = template;
			ItemsSource = pages;

			ItemSelected += async (sender, args) => {
				if (SelectedItem == null)
					return;

				var item = args.SelectedItem;
				var page = item as Page;
				if (page != null)
					await PushPage (page);

				SelectedItem = null;
			};
		}
开发者ID:Costo,项目名称:Xamarin.Forms,代码行数:101,代码来源:CoreGallery.cs

示例11: CoreRootView

		public CoreRootView ()
		{
			var roots = new [] {
				new CoreViewContainer ("SwapRoot - CarouselPage", typeof(CoreCarouselPage)), 
				new CoreViewContainer ("SwapRoot - ContentPage", typeof(CoreContentPage)),
				new CoreViewContainer ("SwapRoot - MasterDetailPage", typeof(CoreMasterDetailPage)),
				new CoreViewContainer ("SwapRoot - NavigationPage", typeof(CoreNavigationPage)),
				new CoreViewContainer ("SwapRoot - TabbedPage", typeof(CoreTabbedPage)),
			};

			var template = new DataTemplate (typeof(TextCell));
			template.SetBinding (TextCell.TextProperty, "Name");

			ItemTemplate = template;
			ItemsSource = roots;

#if PRE_APPLICATION_CLASS
			ItemSelected += (sender, args) => MessagingCenter.Send (this, Messages.ChangeRoot, ((CoreViewContainer)args.SelectedItem).PageType);
#else			
			ItemSelected += (sender, args) => {
				var app = Application.Current as App;
				if (app != null) {
					var page = (Page)Activator.CreateInstance (((CoreViewContainer)args.SelectedItem).PageType);
					app.SetMainPage (page);
				}		
			};
#endif
		}
开发者ID:Costo,项目名称:Xamarin.Forms,代码行数:28,代码来源:CoreGallery.cs

示例12: UrlImageCellListPage

		public UrlImageCellListPage()
		{
			Device.OnPlatform (iOS: () => {
				if (Device.Idiom == TargetIdiom.Tablet) {
					Padding = new Thickness (0, 0, 0, 60);
				}
			});

			var dataTemplate = new DataTemplate (typeof (ImageCell));
			var stringToImageSourceConverter = new GenericValueConverter (
				obj => new UriImageSource() {
					Uri = new Uri ((string) obj)
				});

			dataTemplate.SetBinding (TextCell.TextProperty, new Binding ("Text"));
			dataTemplate.SetBinding (TextCell.TextColorProperty, new Binding ("TextColor"));
			dataTemplate.SetBinding (TextCell.DetailProperty, new Binding ("Detail"));
			dataTemplate.SetBinding (TextCell.DetailColorProperty, new Binding ("DetailColor"));
			dataTemplate.SetBinding (ImageCell.ImageSourceProperty,
				new Binding ("Image", converter: stringToImageSourceConverter));

			var albums = new List<string> ();
			for (int i = 0; i < 30; i++) {
				albums.Add (string.Format ("http://cdn.instructables.com/FCP/9TOJ/GCJ0ZQV5/FCP9TOJGCJ0ZQV5.MEDIUM.jpg?ticks={0}",i ));
			}


			var random = new Random();
			var label = new Label { Text = "I have not been selected" };

			var listView = new ListView {
				AutomationId = "ImageUrlCellListView",
				ItemsSource = Enumerable.Range (0, 300).Select (i => new ImageCellTest {
					Text = "Text " + i,
					TextColor = i % 2 == 0 ? Color.Red : Color.Blue,
					Detail = "Detail " + i,
					DetailColor = i % 2 == 0 ? Color.Red : Color.Blue,
					Image = albums [random.Next (0, albums.Count - 1)]
				}),
				ItemTemplate = dataTemplate
			};

			listView.ItemSelected += (sender, args) => label.Text = "I was selected";

			Content = new StackLayout { Children = { label, listView } };

		}
开发者ID:Costo,项目名称:Xamarin.Forms,代码行数:47,代码来源:ImageCellListPage.cs


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