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


C# Grid.Layout方法代码示例

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


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

示例1: TestBasicHorizontalLayout

		public void TestBasicHorizontalLayout ()
		{
			var platform = new UnitPlatform ();
			var layout = new Grid ();
			layout.Platform = platform;

			var label1 = new Label {Platform = platform, IsPlatformEnabled = true};
			var label2 = new Label {Platform = platform, IsPlatformEnabled = true};
			var label3 = new Label {Platform = platform, IsPlatformEnabled = true};

			layout.Children.AddHorizontal (new View[] {
				label1,
				label2,
				label3
			});

			layout.Layout (new Rectangle (0, 0, 912, 912));

			Assert.AreEqual (912, layout.Width);
			Assert.AreEqual (912, layout.Height);

			Assert.AreEqual (new Rectangle (0, 0, 300, 912), label1.Bounds);
			Assert.AreEqual (new Rectangle (306, 0, 300, 912), label2.Bounds);
			Assert.AreEqual (new Rectangle (612, 0, 300, 912), label3.Bounds);
		}
开发者ID:Costo,项目名称:Xamarin.Forms,代码行数:25,代码来源:GridTests.cs

示例2: TestAutoLayoutWithSpans

		public void TestAutoLayoutWithSpans ()
		{
			var platform = new UnitPlatform ();
			var layout = new Grid ();
			layout.Platform = platform;

			var label1 = new Label { Platform = platform, IsPlatformEnabled = true, WidthRequest = 150, Text = "label1" };
			var label2 = new Label { Platform = platform, IsPlatformEnabled = true, HeightRequest = 50, Text = "label2" };
			var label3 = new Label { Platform = platform, IsPlatformEnabled = true, Text = "label3" };

			layout.ColumnDefinitions = new ColumnDefinitionCollection { 
				new ColumnDefinition {Width = GridLength.Auto},
				new ColumnDefinition {Width = GridLength.Auto},
				new ColumnDefinition {Width = GridLength.Auto},
			};
			layout.RowDefinitions = new RowDefinitionCollection {
				new RowDefinition {Height = GridLength.Auto},
				new RowDefinition {Height = GridLength.Auto},
				new RowDefinition {Height = GridLength.Auto},
			};
			layout.Children.Add (label1, 0, 2, 0, 1);
			layout.Children.Add (label2, 2, 3, 0, 2);
			layout.Children.Add (label3, 1, 2);

			layout.Layout (new Rectangle (0, 0, 1002, 462));

			Assert.AreEqual (1002, layout.Width);
			Assert.AreEqual (462, layout.Height);

			Assert.AreEqual (new Rectangle (0, 0, 150, 20), label1.Bounds);
			Assert.AreEqual (new Rectangle (156, 0, 100, 50), label2.Bounds);
			Assert.AreEqual (new Rectangle (50, 56, 100, 20), label3.Bounds);
		}
开发者ID:Costo,项目名称:Xamarin.Forms,代码行数:33,代码来源:GridTests.cs

示例3: TestAutoLayout

		public void TestAutoLayout ()
		{
			var platform = new UnitPlatform ();
			var layout = new Grid ();
			layout.Platform = platform;

			var label1 = new Label {Platform = platform, IsPlatformEnabled = true};
			var label2 = new Label {Platform = platform, IsPlatformEnabled = true};
			var label3 = new Label {Platform = platform, IsPlatformEnabled = true};

			layout.ColumnDefinitions = new ColumnDefinitionCollection { 
				new ColumnDefinition {Width = GridLength.Auto},
				new ColumnDefinition {Width = GridLength.Auto},
				new ColumnDefinition {Width = GridLength.Auto},
			};
			layout.RowDefinitions = new RowDefinitionCollection {
				new RowDefinition {Height = GridLength.Auto},
				new RowDefinition {Height = GridLength.Auto},
				new RowDefinition {Height = GridLength.Auto},
			};
			layout.Children.Add (label1, 0, 0);
			layout.Children.Add (label2, 1, 1);
			layout.Children.Add (label3, 2, 2);


			layout.Layout (new Rectangle (0, 0, 1000, 1000));

			Assert.AreEqual (1000, layout.Width);
			Assert.AreEqual (1000, layout.Height);

			Assert.AreEqual (new Rectangle (0, 0, 100, 20), label1.Bounds);
			Assert.AreEqual (new Rectangle (106, 26, 100, 20), label2.Bounds);
			Assert.AreEqual (new Rectangle (212, 52, 100, 20), label3.Bounds);
		}
开发者ID:Costo,项目名称:Xamarin.Forms,代码行数:34,代码来源:GridTests.cs

示例4: TestStarLayoutWithSpans

		public void TestStarLayoutWithSpans ()
		{
			var platform = new UnitPlatform ();
			var layout = new Grid ();
			layout.Platform = platform;

			var label1 = new Label {Platform = platform, IsPlatformEnabled = true};
			var label2 = new Label {Platform = platform, IsPlatformEnabled = true};
			var label3 = new Label {Platform = platform, IsPlatformEnabled = true};

			layout.ColumnDefinitions = new ColumnDefinitionCollection { 
				new ColumnDefinition {Width = new GridLength (1, GridUnitType.Star)},
				new ColumnDefinition {Width = new GridLength (1, GridUnitType.Star)},
				new ColumnDefinition {Width = new GridLength (1, GridUnitType.Star)},
			};
			layout.RowDefinitions = new RowDefinitionCollection {
				new RowDefinition {Height = new GridLength (1, GridUnitType.Star)},
				new RowDefinition {Height = new GridLength (1, GridUnitType.Star)},
				new RowDefinition {Height = new GridLength (1, GridUnitType.Star)},
			};
			layout.Children.Add (label1, 0, 2, 0, 1);
			layout.Children.Add (label2, 2, 3, 0, 2);
			layout.Children.Add (label3, 1, 2);

			layout.Layout (new Rectangle (0, 0, 1002, 462));

			Assert.AreEqual (1002, layout.Width);
			Assert.AreEqual (462, layout.Height);

			Assert.AreEqual (new Rectangle (0, 0, 666, 150), label1.Bounds);
			Assert.AreEqual (new Rectangle (672, 0, 330, 306), label2.Bounds);
			Assert.AreEqual (new Rectangle (336, 312, 330, 150), label3.Bounds);
		}
开发者ID:Costo,项目名称:Xamarin.Forms,代码行数:33,代码来源:GridTests.cs

示例5: TestAbsoluteLayoutWithSpans

		public void TestAbsoluteLayoutWithSpans ()
		{
			var platform = new UnitPlatform ();
			var layout = new Grid ();
			layout.Platform = platform;

			var label1 = new Label {Platform = platform, IsPlatformEnabled = true};
			var label2 = new Label {Platform = platform, IsPlatformEnabled = true};
			var label3 = new Label {Platform = platform, IsPlatformEnabled = true};

			layout.ColumnDefinitions = new ColumnDefinitionCollection { 
				new ColumnDefinition {Width = new GridLength (150)},
				new ColumnDefinition {Width = new GridLength (150)},
				new ColumnDefinition {Width = new GridLength (150)},
			};
			layout.RowDefinitions = new RowDefinitionCollection {
				new RowDefinition {Height = new GridLength (30)},
				new RowDefinition {Height = new GridLength (30)},
				new RowDefinition {Height = new GridLength (30)},
			};
			layout.Children.Add (label1, 0, 2, 0, 1);
			layout.Children.Add (label2, 2, 3, 0, 2);
			layout.Children.Add (label3, 1, 2);


			layout.Layout (new Rectangle (0, 0, 1000, 1000));

			Assert.AreEqual (1000, layout.Width);
			Assert.AreEqual (1000, layout.Height);

			Assert.AreEqual (new Rectangle (0, 0, 306, 30), label1.Bounds);
			Assert.AreEqual (new Rectangle (312, 0, 150, 66), label2.Bounds);
			Assert.AreEqual (new Rectangle (156, 72, 150, 30), label3.Bounds);
		}
开发者ID:Costo,项目名称:Xamarin.Forms,代码行数:34,代码来源:GridTests.cs

示例6: TestAddedBP

		public void TestAddedBP ()
		{
			var platform = new UnitPlatform ();

			var labela0 = new Label {Platform = platform, IsPlatformEnabled = true};
			var labela1 = new Label { Platform = platform, IsPlatformEnabled = true };
			Grid.SetColumn (labela1, 1);
			var labelb1 = new Label {Platform = platform, IsPlatformEnabled = true};
			Grid.SetRow (labelb1, 1);
			Grid.SetColumn (labelb1, 1);
			var labelc = new Label {Platform = platform, IsPlatformEnabled = true};
			Grid.SetRow (labelc, 2);
			Grid.SetColumnSpan (labelc, 2);

			var layout = new Grid {
				Platform = platform,
				Children = {
					labela0,
					labela1,
					labelb1,
					labelc
				}
			};

			layout.ColumnDefinitions = new ColumnDefinitionCollection {
				new ColumnDefinition { Width = GridLength.Auto },
				new ColumnDefinition { Width = GridLength.Auto },
			};
			layout.RowDefinitions = new RowDefinitionCollection {
				new RowDefinition { Height = GridLength.Auto},
				new RowDefinition { Height = GridLength.Auto},
				new RowDefinition { Height = GridLength.Auto},
			};

			layout.Layout (new Rectangle (0, 0, 1000, 1000));

			Assert.AreEqual (1000, layout.Width);
			Assert.AreEqual (1000, layout.Height);

			Assert.AreEqual (new Rectangle (0, 0, 100, 20), labela0.Bounds);
			Assert.AreEqual (new Rectangle (106, 0, 100, 20), labela1.Bounds);
			Assert.AreEqual (new Rectangle (106, 26, 100, 20), labelb1.Bounds);
			Assert.AreEqual (new Rectangle (0, 52, 206, 20), labelc.Bounds);
		}
开发者ID:Costo,项目名称:Xamarin.Forms,代码行数:44,代码来源:GridTests.cs

示例7: ChildrenLayoutRespectAlignment

		public void ChildrenLayoutRespectAlignment ()
		{
			var platform = new UnitPlatform ();
			var grid = new Grid { 
				ColumnDefinitions = { new ColumnDefinition { Width = new GridLength (300) } },
				RowDefinitions = { new RowDefinition { Height = new GridLength (100) } },
				Platform = platform,
			};
			var label = new Label { 
				Platform = platform, 
				IsPlatformEnabled = true,
				VerticalOptions = LayoutOptions.Center,
				HorizontalOptions = LayoutOptions.End,
			};

			grid.Children.Add (label);
			grid.Layout (new Rectangle (0, 0, 500, 500));

			Assert.AreEqual (new Rectangle (200, 40, 100, 20), label.Bounds);
		}
开发者ID:Costo,项目名称:Xamarin.Forms,代码行数:20,代码来源:GridTests.cs

示例8: TestTableExpandedSpan

		public void TestTableExpandedSpan ()
		{
			var platform = new UnitPlatform ();
			var layout = new Grid ();
			layout.Platform = platform;

			var label1 = new Label {Platform = platform, IsPlatformEnabled = true};
			var label2 = new Label {Platform = platform, IsPlatformEnabled = true};
			var label3 = new Label {Platform = platform, IsPlatformEnabled = true};

			layout.ColumnDefinitions = new ColumnDefinitionCollection { 
				new ColumnDefinition { Width = new GridLength (1, GridUnitType.Star) },
				new ColumnDefinition { Width = new GridLength (1, GridUnitType.Star) },
			};
			layout.RowDefinitions = new RowDefinitionCollection {
				new RowDefinition { Height = GridLength.Auto},
				new RowDefinition { Height = GridLength.Auto}
			};

			layout.Children.Add (label1, 0, 2, 0, 1);
			layout.Children.Add (label2, 0, 1, 1, 2);
			layout.Children.Add (label3, 1, 2, 1, 2);

			layout.Layout (new Rectangle (0, 0, 1000, 1000));

			Assert.AreEqual (1000, layout.Width);
			Assert.AreEqual (1000, layout.Height);

			Assert.AreEqual (new Rectangle (0, 0, 1000, 20), label1.Bounds);
			Assert.AreEqual (new Rectangle (0, 26, 497, 20), label2.Bounds);
			Assert.AreEqual (new Rectangle (503, 26, 497, 20), label3.Bounds);
		}
开发者ID:Costo,项目名称:Xamarin.Forms,代码行数:32,代码来源:GridTests.cs

示例9: TestEnd

		public void TestEnd ()
		{
			var platform = new UnitPlatform ();
			var layout = new Grid ();
			layout.Platform = platform;

			var label1 = new Label { Platform = platform, IsPlatformEnabled = true, HorizontalOptions = LayoutOptions.End, VerticalOptions = LayoutOptions.EndAndExpand };

			layout.Children.AddVertical (label1);
			layout.ColumnDefinitions = new ColumnDefinitionCollection { 
				new ColumnDefinition () {Width = new GridLength (1, GridUnitType.Star)},
			};
			layout.RowDefinitions = new RowDefinitionCollection { 
				new RowDefinition () {Height = new GridLength (1,GridUnitType.Star)},
			};

			layout.Layout (new Rectangle (0, 0, 1000, 1000));

			Assert.AreEqual (new Rectangle (900, 980, 100, 20), label1.Bounds);
		}
开发者ID:Costo,项目名称:Xamarin.Forms,代码行数:20,代码来源:GridTests.cs

示例10: NestedInvalidateMeasureDoesNotCrash

		public void NestedInvalidateMeasureDoesNotCrash ()
		{
			var grid = new Grid {
				Platform = new UnitPlatform (),
				IsPlatformEnabled = true
			};

			var child = new Label {
				IsPlatformEnabled = true
			};
			grid.Children.Add (child);

			var child2 = new Label {
				IsPlatformEnabled = true
			};
			grid.Children.Add (child2);

			bool fire = true;
			child.SizeChanged += (sender, args) => {
				if (fire)
					((IVisualElementController)child).InvalidateMeasure(InvalidationTrigger.Undefined);
				fire = false;
			};

			grid.Layout (new Rectangle (0, 0, 100, 100));

			foreach (var delayAction in delayActions) {
				delayAction ();
			}
		}
开发者ID:Costo,项目名称:Xamarin.Forms,代码行数:30,代码来源:GridTests.cs

示例11: TestHorizontalExpandMiddle

		public void TestHorizontalExpandMiddle ()
		{
			var platform = new UnitPlatform ();
			var layout = new Grid ();
			layout.Platform = platform;

			var label1 = new Label {Platform = platform, IsPlatformEnabled = true};
			var label2 = new Label {Platform = platform, IsPlatformEnabled = true};
			var label3 = new Label {Platform = platform, IsPlatformEnabled = true};

			layout.ColumnDefinitions = new ColumnDefinitionCollection {
				new ColumnDefinition { Width = GridLength.Auto },
				new ColumnDefinition { Width = new GridLength (1, GridUnitType.Star) },
				new ColumnDefinition { Width = GridLength.Auto },
			};

			layout.Children.Add (label1, 0, 0);
			layout.Children.Add (label2, 1, 0);
			layout.Children.Add (label3, 2, 0);

			layout.Layout (new Rectangle (0, 0, 1000, 1000));

			Assert.AreEqual (1000, layout.Width);
			Assert.AreEqual (1000, layout.Height);

			Assert.AreEqual (new Rectangle (0, 0, 100, 1000), label1.Bounds);
			Assert.AreEqual (new Rectangle (106, 0, 1000 - 212, 1000), label2.Bounds);
			Assert.AreEqual (new Rectangle (900, 0, 100, 1000), label3.Bounds);
		}
开发者ID:Costo,项目名称:Xamarin.Forms,代码行数:29,代码来源:GridTests.cs

示例12: EditorSpanningOnMultipleAutoRows

		//Issue 1893
		public void EditorSpanningOnMultipleAutoRows ()
		{
			var grid0 = new Grid {
				ColumnDefinitions = {
					new ColumnDefinition { Width = GridLength.Auto },
					new ColumnDefinition { Width = new GridLength (1, GridUnitType.Star) },
				},
				RowDefinitions = {
					new RowDefinition { Height = GridLength.Auto },
					new RowDefinition { Height = GridLength.Auto },
				},
				Platform = new UnitPlatform (GetResizableSize),
				IsPlatformEnabled = true,
			};

			var label0 = new Label { IsPlatformEnabled = true };
			var editor0 = new Editor { IsPlatformEnabled = true };
			grid0.Children.Add (label0, 0, 0);
			grid0.Children.Add (editor0, 1, 2, 0, 2);

			grid0.Layout (new Rectangle (0, 0, 156, 200));
			Assert.AreEqual (new Rectangle (106, 0, 50, 40), editor0.Bounds);

			var grid1 = new Grid {
				ColumnDefinitions = {
					new ColumnDefinition { Width = GridLength.Auto },
					new ColumnDefinition { Width = new GridLength (1, GridUnitType.Star) },
				},
				RowDefinitions = {
					new RowDefinition { Height = GridLength.Auto },
				},
				Platform = new UnitPlatform (GetResizableSize),
				IsPlatformEnabled = true,
			};

			var label1 = new Label { IsPlatformEnabled = true };
			var editor1 = new Editor { IsPlatformEnabled = true };
			grid1.Children.Add (label1, 0, 0);
			grid1.Children.Add (editor1, 1, 0);

			grid1.Layout (new Rectangle (0, 0, 156, 200));
			Assert.AreEqual (new Rectangle (106, 0, 50, 40), editor1.Bounds);
		}
开发者ID:Costo,项目名称:Xamarin.Forms,代码行数:44,代码来源:GridTests.cs

示例13: StarColumnsWithSpansDoNotExpandAutos

		public void StarColumnsWithSpansDoNotExpandAutos ()
		{
			var grid = new Grid {
				RowDefinitions = {
					new RowDefinition {Height = GridLength.Auto},
					new RowDefinition {Height = GridLength.Auto},
				},
				ColumnDefinitions = {
					new ColumnDefinition {Width = new GridLength (1, GridUnitType.Auto)},
					new ColumnDefinition {Width = new GridLength (1, GridUnitType.Auto)},
					new ColumnDefinition {Width = new GridLength (1, GridUnitType.Star)}
				},
				Platform = new UnitPlatform (),
				IsPlatformEnabled = true
			};

			var spanBox = new BoxView {WidthRequest = 70, HeightRequest = 20, IsPlatformEnabled = true};
			var box1 = new BoxView {WidthRequest = 20, HeightRequest = 20, IsPlatformEnabled = true};
			var box2 = new BoxView {WidthRequest = 20, HeightRequest = 20, IsPlatformEnabled = true};
			var box3 = new BoxView {WidthRequest = 20, HeightRequest = 20, IsPlatformEnabled = true};

			grid.Children.Add (spanBox, 0, 3, 0, 1);
			grid.Children.Add (box1, 0, 1);
			grid.Children.Add (box2, 1, 1);
			grid.Children.Add (box3, 2, 1);

			grid.Layout (new Rectangle(0, 0, 300, 46));

			Assert.AreEqual (new Rectangle (0, 0, 300, 20), spanBox.Bounds);
			Assert.AreEqual (new Rectangle (0, 26, 20, 20), box1.Bounds);
			Assert.AreEqual (new Rectangle (26, 26, 20, 20), box2.Bounds);
			Assert.AreEqual (new Rectangle (52, 26, 248, 20), box3.Bounds);
		}
开发者ID:Costo,项目名称:Xamarin.Forms,代码行数:33,代码来源:GridTests.cs

示例14: StarRowsShouldOccupyTheSpace

		//Issue 1497
		public void StarRowsShouldOccupyTheSpace ()
		{
			var platform = new UnitPlatform ();
			var label = new Label { 
				Platform = platform,
				IsPlatformEnabled = true,
			};
			var Button = new Button {
				HorizontalOptions = LayoutOptions.FillAndExpand,
				VerticalOptions = LayoutOptions.EndAndExpand,
				Platform = platform,
				IsPlatformEnabled = true,
			};
			var grid = new Grid {
				RowDefinitions = new RowDefinitionCollection {
					new RowDefinition { Height = GridLength.Auto },
					new RowDefinition { Height = new GridLength (1, GridUnitType.Star) },
				},
				ColumnDefinitions = new ColumnDefinitionCollection {
					new ColumnDefinition {Width = new GridLength(1, GridUnitType.Star)},
				},
				Platform = platform,
				IsPlatformEnabled = true,
			};

			grid.Children.Add (label);
			grid.Children.Add (Button, 0, 1);

			grid.Layout (new Rectangle (0, 0, 300, 300));
			Assert.AreEqual (new Rectangle (0, 280, 300, 20), Button.Bounds);
		}
开发者ID:Costo,项目名称:Xamarin.Forms,代码行数:32,代码来源:GridTests.cs

示例15: TestVerticalExpandStart

		public void TestVerticalExpandStart ()
		{
			var platform = new UnitPlatform ();
			var layout = new Grid ();
			layout.Platform = platform;

			var label1 = new Label {Platform = platform, IsPlatformEnabled = true};
			var label2 = new Label {Platform = platform, IsPlatformEnabled = true};

			layout.RowDefinitions = new RowDefinitionCollection {
				new RowDefinition { Height = new GridLength (1, GridUnitType.Star) },
				new RowDefinition { Height = GridLength.Auto},
			};
			layout.Children.Add (label1, 0, 0);
			layout.Children.Add (label2, 0, 1);

			layout.Layout (new Rectangle (0, 0, 1000, 1000));

			Assert.AreEqual (1000, layout.Width);
			Assert.AreEqual (1000, layout.Height);

			Assert.AreEqual (new Rectangle (0, 0, 1000, 1000 - 20 - layout.RowSpacing), label1.Bounds);
			Assert.AreEqual (new Rectangle (0, 1000 - 20, 1000, 20), label2.Bounds);
		}
开发者ID:Costo,项目名称:Xamarin.Forms,代码行数:24,代码来源:GridTests.cs


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