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


C# ContentPage.FindByName方法代码示例

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


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

示例1: TestCase001

		public void TestCase001 ()
		{
			var xaml = @"<?xml version=""1.0"" encoding=""UTF-8"" ?>
			<ContentPage
			xmlns=""http://xamarin.com/schemas/2014/forms""
			xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml""
			xmlns:local=""clr-namespace:Xamarin.Forms.Xaml.UnitTests;assembly=Xamarin.Forms.Xaml.UnitTests""
			Title=""Home"">
				<local:TestCases.InnerView>
					<Label x:Name=""innerView""/>
				</local:TestCases.InnerView>
				<ContentPage.Content>
					<Grid RowSpacing=""9"" ColumnSpacing=""6"" Padding=""6,9"" VerticalOptions=""Fill"" HorizontalOptions=""Fill"" BackgroundColor=""Red"">
						<Grid.Children>
							<Label x:Name=""label0""/>
							<Label x:Name=""label1""/>
							<Label x:Name=""label2""/>
							<Label x:Name=""label3""/>
						</Grid.Children>
					</Grid>
				</ContentPage.Content>
			</ContentPage>";
			var contentPage = new ContentPage ().LoadFromXaml (xaml);
			var label0 = contentPage.FindByName<Label> ("label0");
			var label1 = contentPage.FindByName<Label> ("label1");

			Assert.NotNull (GetInnerView (contentPage));
//			Assert.AreEqual ("innerView", GetInnerView (contentPage).Name);
			Assert.AreEqual (GetInnerView (contentPage), ((Forms.Internals.INameScope)contentPage).FindByName ("innerView"));
			Assert.NotNull (label0);
			Assert.NotNull (label1);
			Assert.AreEqual (4, contentPage.Content.Descendants ().Count ());
		}
开发者ID:Costo,项目名称:Xamarin.Forms,代码行数:33,代码来源:TestCases.cs

示例2: BindingCanNotBeReused

		public void BindingCanNotBeReused()
		{
			string xaml = @"<ContentPage xmlns=""http://xamarin.com/schemas/2014/forms""
						 xmlns:x=""http://schemas.microsoft.com/winfx/2009/xaml""
						 x:Class=""Xamarin.Forms.Controls.Issue1545"">
						<ListView x:Name=""List"" ItemsSource=""{Binding}"">
							<ListView.ItemTemplate>
								<DataTemplate>
									<TextCell Text=""{Binding}"" />
								</DataTemplate>
							</ListView.ItemTemplate>
						</ListView>
				</ContentPage>";

			ContentPage page = new ContentPage().LoadFromXaml (xaml);

			var items = new[] { "Fu", "Bar" };
			page.BindingContext = items;

			ListView lv = page.FindByName<ListView> ("List");
			
			TextCell cell = (TextCell)lv.TemplatedItems.GetOrCreateContent (0, items[0]);
			Assert.That (cell.Text, Is.EqualTo ("Fu"));
			
			cell = (TextCell)lv.TemplatedItems.GetOrCreateContent (1, items[1]);
			Assert.That (cell.Text, Is.EqualTo ("Bar"));
		}
开发者ID:Costo,项目名称:Xamarin.Forms,代码行数:27,代码来源:Issue1545.cs

示例3: ElementsCanNotBeReused

		public void ElementsCanNotBeReused()
		{
			string xaml = @"<ContentPage xmlns=""http://xamarin.com/schemas/2014/forms""
						 xmlns:x=""http://schemas.microsoft.com/winfx/2009/xaml""
						 x:Class=""Xamarin.Forms.Controls.Issue1545"">
							<ContentPage.Resources>
							<ResourceDictionary>
							<Color x:Key=""color"">#ff00aa</Color>
							</ResourceDictionary>
							</ContentPage.Resources>

						<ListView x:Name=""List"" ItemsSource=""{Binding}"">
							<ListView.ItemTemplate>
								<DataTemplate>
									<ViewCell>
									<StackLayout>
										<Label Text=""{Binding}"" BackgroundColor=""{StaticResource color}""/>
									</StackLayout>
									</ViewCell>
								</DataTemplate>
							</ListView.ItemTemplate>
						</ListView>
				</ContentPage>";

			ContentPage page = new ContentPage().LoadFromXaml (xaml);

			var items = new[] { "Fu", "Bar" };
			page.BindingContext = items;

			ListView lv = page.FindByName<ListView> ("List");

			ViewCell cell0 = (ViewCell)lv.TemplatedItems.GetOrCreateContent (0, items[0]);


			Assert.That (((Label)((StackLayout)cell0.View).Children[0]).Text, Is.EqualTo ("Fu"));

			ViewCell cell1 = (ViewCell)lv.TemplatedItems.GetOrCreateContent (1, items[1]);
			Assert.That (((Label)((StackLayout)cell1.View).Children[0]).Text, Is.EqualTo ("Bar"));

			Assert.AreNotSame (cell0, cell1);
			Assert.AreNotSame (cell0.View, cell1.View);
			Assert.AreNotSame (((StackLayout)cell0.View).Children [0], ((StackLayout)cell1.View).Children [0]);
			Assert.AreEqual (Color.FromHex ("ff00aa"), ((StackLayout)cell1.View).Children [0].BackgroundColor);
		}
开发者ID:Costo,项目名称:Xamarin.Forms,代码行数:44,代码来源:Issue1545.cs

示例4: ConverterIsInvoked

		public void ConverterIsInvoked ()
		{
			var xaml = @"
<ContentPage 							
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"">

<ContentPage.Resources>
<ResourceDictionary>
<local:SeverityColorConverter x:Key=""SeverityColorConverter"" />
</ResourceDictionary>
</ContentPage.Resources>
				<Label Text=""{Binding value, StringFormat='{0}'}"" 
					WidthRequest=""50"" 
					TextColor=""Black""
					x:Name=""label""
					BackgroundColor=""{Binding Severity, Converter={StaticResource SeverityColorConverter}}""
					XAlign=""Center"" YAlign=""Center""/>
</ContentPage>";

			var layout = new ContentPage ().LoadFromXaml (xaml);
			layout.BindingContext = new {Value = "Foo", Severity = "Bar"};
			var label = layout.FindByName<Label> ("label");
			Assert.AreEqual (Color.Blue, label.BackgroundColor);
			Assert.AreEqual (1, SeverityColorConverter.count);
		}
开发者ID:Costo,项目名称:Xamarin.Forms,代码行数:27,代码来源:Issue1549.cs

示例5: TestCase003

		public void TestCase003 ()
		{
			var xaml = @"<?xml version=""1.0"" encoding=""UTF-8"" ?>
				<ContentPage
					xmlns=""http://xamarin.com/schemas/2014/forms""
					xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml""
					Title=""People"">

					<StackLayout Spacing=""0"">
						<SearchBar x:Name=""searchBar""/>
						<ListView ItemsSource=""{Binding Path=.}"" RowHeight=""42"" x:Name=""listview"">
							<ListView.ItemTemplate>
								<DataTemplate>
									<ViewCell>
										<ViewCell.View>
											<StackLayout Orientation=""Horizontal"" HorizontalOptions=""FillAndExpand"" VerticalOptions=""CenterAndExpand"" BackgroundColor=""#fff4f4f4"">
												<BoxView WidthRequest=""10""/>
												<Grid WidthRequest=""42"" HeightRequest=""32"" VerticalOptions=""CenterAndExpand"" HorizontalOptions=""Start"">
													<Image WidthRequest=""32"" HeightRequest=""32"" Aspect=""AspectFill"" HorizontalOptions=""FillAndExpand"" Source=""Images/icone_nopic_members_42.png""/>
													<!--<Image WidthRequest=""32"" HeightRequest=""32"" Aspect=""AspectFill"" HorizontalOptions=""FillAndExpand"">
														<Image.Source>
															<UriImageSource Uri=""{Binding Picture}"" CacheValidity=""30""/>
														</Image.Source>
													</Image>-->
													<Image Source=""Images/cropcircle.png"" HorizontalOptions=""FillAndExpand"" VerticalOptions=""FillAndExpand"" WidthRequest=""32"" HeightRequest=""32"" Aspect=""Fill""/>
												</Grid>
												<Label Text=""{Binding FirstName}"" VerticalOptions=""CenterAndExpand""/>
												<Label Text=""{Binding LastName}"" Font=""HelveticaNeue-Bold, Medium"" VerticalOptions=""CenterAndExpand"" />
											</StackLayout>
										</ViewCell.View>
									</ViewCell>
								</DataTemplate>
							</ListView.ItemTemplate>
						</ListView>
					</StackLayout>
				</ContentPage>";
			var page = new ContentPage ().LoadFromXaml (xaml);
			var model = new List<object> { 
				new {FirstName = "John", LastName="Lennon", Picture="http://www.johnlennon.com/wp-content/themes/jl/images/home-gallery/2.jpg"},
				new {FirstName = "Paul", LastName="McCartney", Picture="http://t0.gstatic.com/images?q=tbn:ANd9GcRjNUGJ00Mt85n2XDu8CZM0w1em0Wv4ZaemLuIVmLCMwPMOLUO1SQ"},
				new {FirstName = "George", LastName="Harisson", Picture="http://cdn.riffraf.net/wp-content/uploads/2013/02/george-harrison-living.jpg"},
				new {FirstName = "Ringo", LastName="Starr", Picture="http://www.biography.com/imported/images/Biography/Images/Profiles/S/Ringo-Starr-306872-1-402.jpg"},
			};
			page.BindingContext = model;

			var listview = page.FindByName<ListView> ("listview");
			Cell cell = null;
			Assert.DoesNotThrow(() => { cell = listview.TemplatedItems[0]; });
			Assert.NotNull (cell);
			Assert.That (cell, Is.TypeOf<ViewCell> ());
			Assert.AreSame (model [0], cell.BindingContext);
		}
开发者ID:Costo,项目名称:Xamarin.Forms,代码行数:52,代码来源:TestCases.cs

示例6: Issue1415

		public void Issue1415 ()
		{
			var xaml = @"<?xml version=""1.0"" encoding=""utf-8"" ?>
						<ContentPage 
							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"">
							<Label x:Name=""label"" Text=""{Binding Converter={x:Static local:ReverseConverter.Instance}, Mode=TwoWay}""/>
						</ContentPage>";
			var page = new ContentPage ().LoadFromXaml (xaml);
			var label = page.FindByName<Label> ("label");
			Assert.NotNull (label);
			label.BindingContext = "foo";
			Assert.AreEqual ("oof", label.Text);
		}
开发者ID:Costo,项目名称:Xamarin.Forms,代码行数:15,代码来源:TestCases.cs


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