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


C# ListView.LoadFromXaml方法代码示例

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


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

示例1: DataTemplateChildrenDoesNotParticipateToParentNameScope

		public void DataTemplateChildrenDoesNotParticipateToParentNameScope ()
		{
			var xaml = @"
				<ListView
				xmlns=""http://xamarin.com/schemas/2014/forms""
				xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml""
				x:Name=""listview"">
					<ListView.ItemTemplate>
						<DataTemplate>
						    <TextCell Text=""{Binding name}"" x:Name=""textcell""/>
						</DataTemplate>
					</ListView.ItemTemplate>
				</ListView>";

			var listview = new ListView ();
			listview.LoadFromXaml (xaml);	

			Assert.AreSame (listview, ((Forms.Internals.INameScope)listview).FindByName ("listview"));
			Assert.IsNull (((Forms.Internals.INameScope)listview).FindByName ("textcell"));
		}
开发者ID:Costo,项目名称:Xamarin.Forms,代码行数:20,代码来源:NameScopeTests.cs

示例2: CollectionItemsInDataTemplate

		public void CollectionItemsInDataTemplate ()
		{
			var xaml = @"<?xml version=""1.0"" encoding=""UTF-8""?>
				<ListView 
					xmlns=""http://xamarin.com/schemas/2014/forms"" 
					xmlns:x=""http://schemas.microsoft.com/winfx/2009/xaml"" 
					ItemsSource=""{Binding}"">
			        <ListView.ItemTemplate>
			          <DataTemplate>
			            <ViewCell>
			              <ViewCell.View>
			                <StackLayout>
			                  <Label Text=""{Binding}""></Label>
			                  <Label Text=""{Binding}""></Label>
			                </StackLayout>
			              </ViewCell.View>
			            </ViewCell>
			          </DataTemplate>
			        </ListView.ItemTemplate>
			      </ListView>";
			var listview = new ListView ();
			var items = new [] { "Foo", "Bar", "Baz" };
			listview.BindingContext = items;
				
			listview.LoadFromXaml (xaml);

			ViewCell cell0 = null;
			Assert.DoesNotThrow (() => {
				cell0 = (ViewCell)listview.TemplatedItems.GetOrCreateContent (0, items [0]);
			});
			ViewCell cell1 = null;
			Assert.DoesNotThrow (() => {
				cell1 = (ViewCell)listview.TemplatedItems.GetOrCreateContent (1, items [1]);
			});

			Assert.AreNotSame (cell0, cell1);
			Assert.AreNotSame (cell0.View, cell1.View);
			Assert.AreNotSame (((StackLayout)cell0.View).Children [0], ((StackLayout)cell1.View).Children [0]);
			Assert.AreNotSame (((StackLayout)cell0.View).Children [1], ((StackLayout)cell1.View).Children [1]);

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

示例3: ElementsCreatedFromDataTemplateHaveTheirOwnNameScope

		public void ElementsCreatedFromDataTemplateHaveTheirOwnNameScope ()
		{
			var xaml = @"
				<ListView
				xmlns=""http://xamarin.com/schemas/2014/forms""
				xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml""
				x:Name=""listview"">
					<ListView.ItemTemplate>
						<DataTemplate>
						    <TextCell Text=""{Binding name}"" x:Name=""textcell""/>
						</DataTemplate>
					</ListView.ItemTemplate>
				</ListView>";

			var listview = new ListView ();
			listview.LoadFromXaml (xaml);	
			Assert.IsNotNull (Forms.Internals.NameScope.GetNameScope (listview));
			Assert.That (Forms.Internals.NameScope.GetNameScope (listview), Is.TypeOf<Forms.Internals.NameScope> ());

			var cell0 = listview.ItemTemplate.CreateContent () as Element;
			var cell1 = listview.ItemTemplate.CreateContent () as Element;

			Assert.IsNotNull (Forms.Internals.NameScope.GetNameScope (cell0));
			Assert.That (Forms.Internals.NameScope.GetNameScope (cell0), Is.TypeOf<Forms.Internals.NameScope> ());
			Assert.IsNotNull (Forms.Internals.NameScope.GetNameScope (cell1));
			Assert.That (Forms.Internals.NameScope.GetNameScope (cell1), Is.TypeOf<Forms.Internals.NameScope> ());

			Assert.AreNotSame (Forms.Internals.NameScope.GetNameScope (listview), Forms.Internals.NameScope.GetNameScope (cell0));
			Assert.AreNotSame (Forms.Internals.NameScope.GetNameScope (listview), Forms.Internals.NameScope.GetNameScope (cell1));
			Assert.AreNotSame (Forms.Internals.NameScope.GetNameScope (cell0), Forms.Internals.NameScope.GetNameScope (cell1));

			Assert.IsNull (((Forms.Internals.INameScope)listview).FindByName ("textcell"));
			Assert.NotNull (((Forms.Internals.INameScope)cell0).FindByName ("textcell"));
			Assert.NotNull (((Forms.Internals.INameScope)cell1).FindByName ("textcell"));

			Assert.AreNotSame (((Forms.Internals.INameScope)cell0).FindByName ("textcell"), ((Forms.Internals.INameScope)cell1).FindByName ("textcell"));

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

示例4: ElementsFromCollectionsAreNotReused

		public void ElementsFromCollectionsAreNotReused ()
		{
			var xaml = @"<ListView 
						xmlns=""http://xamarin.com/schemas/2014/forms""
						xmlns:x=""http://schemas.microsoft.com/winfx/2009/xaml""
						xmlns:local=""clr-namespace:Xamarin.Forms.Xaml.UnitTests;assembly=Xamarin.Forms.Xaml.UnitTests""
						ItemsSource=""{Binding}"">
							<ListView.ItemTemplate>
								<DataTemplate>
									<local:ViewCellWithCollection>
										<local:ViewCellWithCollection.Children>
											<local:ViewList>
												<Label />
												<Label />
											</local:ViewList>
										</local:ViewCellWithCollection.Children>
									</local:ViewCellWithCollection>
								</DataTemplate>
							</ListView.ItemTemplate>
						</ListView>";

			var listview = new ListView ();
			var items = new [] { "Foo", "Bar", "Baz" };
			listview.BindingContext = items;
			listview.LoadFromXaml (xaml);
			var cell0 = (ViewCellWithCollection)listview.TemplatedItems.GetOrCreateContent (0, items[0]);
			var cell1 = (ViewCellWithCollection)listview.TemplatedItems.GetOrCreateContent (1, items[1]);

			Assert.AreNotSame (cell0, cell1);
			Assert.AreNotSame (cell0.Children, cell1.Children);
			Assert.AreNotSame (cell0.Children[0], cell1.Children[0]);

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

示例5: ResourcesDeclaredInDataTemplatesAreNotShared

		public void ResourcesDeclaredInDataTemplatesAreNotShared ()
		{
			var xaml = @"<ListView 
						xmlns=""http://xamarin.com/schemas/2014/forms""
						xmlns:x=""http://schemas.microsoft.com/winfx/2009/xaml""
						xmlns:sys=""clr-namespace:System;assembly=mscorlib""
						ItemsSource=""{Binding}"">
							<ListView.ItemTemplate>
								<DataTemplate>
									<ViewCell>
										<Label Text=""{Binding}"">
											<Label.Resources>
												<ResourceDictionary>
													<sys:Object x:Key=""object""/>
												</ResourceDictionary>
											</Label.Resources>
										</Label>
									</ViewCell>
								</DataTemplate>
							</ListView.ItemTemplate>
						</ListView>";

			var listview = new ListView ();
			var items = new [] { "Foo", "Bar", "Baz" };
			listview.BindingContext = items;

			listview.LoadFromXaml (xaml);
			var cell0 = (ViewCell)listview.TemplatedItems.GetOrCreateContent (0, items[0]);
			var cell1 = (ViewCell)listview.TemplatedItems.GetOrCreateContent (1, items[1]);
			Assert.AreNotSame (cell0, cell1);

			var label0 = (Label)cell0.View;
			var label1 = (Label)cell1.View;
			Assert.AreNotSame (label0, label1);
			Assert.AreEqual ("Foo", label0.Text);
			Assert.AreEqual ("Bar", label1.Text);

			var res0 = label0.Resources;
			var res1 = label1.Resources;
			Assert.AreNotSame (res0, res1);

			var obj0 = res0 ["object"];
			var obj1 = res1 ["object"];

			Assert.NotNull (obj0);
			Assert.NotNull (obj1);

			Assert.AreNotSame (obj0, obj1);
		}
开发者ID:Costo,项目名称:Xamarin.Forms,代码行数:49,代码来源:Issue1545.cs


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