Esempio n. 1
0
		public void ConstraintsNotUsedInMeasureOverride ()
		{
			Rectangle r =new Rectangle { Width = 50, Height = 50 };
			MyContentControl c = new MyContentControl {
				Width = 80,
				Height = 80,
				Content = r
			};

			c.Measure (new Size (100, 100));
			Assert.AreEqual (new Size (80, 80), c.MeasureOverrideArg, "#1");
			Assert.AreEqual (new Size (50, 50), c.MeasureOverrideResult, "#2");

			Assert.AreEqual (new Size (50, 50), r.DesiredSize, "#3");
			Assert.AreEqual (new Size (80, 80), c.DesiredSize, "#4");
		}
Esempio n. 2
0
		public void MeasureAutoRows2 ()
		{
			double inf = double.PositiveInfinity;
			MyGrid grid = new MyGrid ();

			grid.AddColumns (new GridLength (50), new GridLength (50));
			grid.AddRows (GridLength.Auto, GridLength.Auto, GridLength.Auto);

			MyContentControl c = new MyContentControl (50, 50);
			grid.AddChild (c, 0, 0, 2, 1);
			grid.AddChild (new MyContentControl (50, 60), 0, 1, 1, 1);
			grid.AddChild (new MyContentControl (50, 20), 0, 1, 1, 1);

			grid.Measure (new Size (500, 400));
			grid.CheckMeasureArgs ("#1", new Size (50, inf), new Size (50, inf), new Size (50, inf));
			grid.CheckMeasureOrder ("#2", 0, 1, 2);
			Assert.AreEqual (new Size (100, 60), grid.DesiredSize, "#2");

			grid.ChangeRow (2, 1);
			grid.Reset ();
			grid.Measure (new Size (500, 400));
			grid.CheckMeasureArgs ("#3", new Size (50, inf));
			grid.CheckMeasureOrder ("#4", 2);
			Assert.AreEqual (new Size (100, 80), grid.DesiredSize, "#4");

			grid.InvalidateSubtree ();
			((FrameworkElement) c.Content).Height = 100;

			grid.Reset ();
			grid.Measure (new Size (500, 400));
			grid.CheckMeasureArgs ("#5", new Size (50, inf), new Size (50, inf), new Size (50, inf));
			Assert.AreEqual (new Size (100, 100), grid.DesiredSize, "#6");

			grid.Reset ();
			grid.ChangeRow (2, 2);
			grid.Measure (new Size (500, 400));
			grid.CheckMeasureArgs ("#7", new Size (50, inf));
			grid.CheckMeasureOrder ("#8", 2);
			Assert.AreEqual (new Size (100, 120), grid.DesiredSize, "#8");
		}
Esempio n. 3
0
		public void MeasureMaxAndMin3 ()
		{
			Grid g = new Grid ();
			var child = new MyContentControl (50, 50);
			g.AddColumns (new GridLength (50));
			g.AddRows (new GridLength (20), new GridLength (20));
			g.AddChild (child, 0, 0, 2, 2);

			g.RowDefinitions [0].MaxHeight = 5;
			g.RowDefinitions [1].MaxHeight = 30;

			CreateAsyncTest (g,
				() => {
					var arg = child.MeasureOverrideArg;
					Assert.AreEqual (25, arg.Height, "#1");
					g.RowDefinitions [0].MaxHeight = 10;
				}, () => {
					var arg = child.MeasureOverrideArg;
					Assert.AreEqual (30, arg.Height, "#2");
					g.RowDefinitions [0].MaxHeight = 20;
				}, () => {
					var arg = child.MeasureOverrideArg;
					Assert.AreEqual (40, arg.Height, "#3");
				}
			);
		}
Esempio n. 4
0
		public void MeasureMaxAndMin2 ()
		{
			MyGrid g = new MyGrid ();
			var child = new MyContentControl (50, 50);
			g.AddColumns (new GridLength (50));
			g.AddRows (new GridLength (50), new GridLength (50));
			g.AddChild (child, 0, 0, 1, 1);

			CreateAsyncTest (g,
				() => {
					g.CheckMeasureArgs ("#1", new Size (50, 50));
					g.CheckRowHeights ("#2", 50, 50);

					g.Reset ();
					g.InvalidateSubtree ();
					g.RowDefinitions [0].MaxHeight = 20;
				}, () => {
					g.CheckMeasureArgs ("#3", new Size (50, 20));
					g.CheckRowHeights ("#4", 20, 50);
				}
			);
		}
Esempio n. 5
0
		public void ChildInvalidatesGrid3 ()
		{
			var child = new MyContentControl (50, 50);
			MyGrid grid = new MyGrid ();
			grid.Children.Add (child);

			grid.Measure (new Size (100, 100));
			Assert.AreEqual (1, grid.MeasuredElements.Count, "#1");

			// Note that invalidating the measure of the content does
			// not invalidate the grid.
			((FrameworkElement) child.Content).InvalidateMeasure ();
			grid.Measure (new Size (100, 100));
			Assert.AreEqual (1, grid.MeasuredElements.Count, "#2");
		}
Esempio n. 6
0
		public void ChildInvalidatesGrid2 ()
		{
			var child = new MyContentControl (50, 50);
			MyGrid grid = new MyGrid ();
			grid.Children.Add (child);

			grid.Measure (new Size (100, 100));
			Assert.AreEqual (1, grid.MeasuredElements.Count, "#1");

			child.InvalidateMeasure ();
			grid.Measure (new Size (100, 100));
			Assert.AreEqual (2, grid.MeasuredElements.Count, "#2");
		}
Esempio n. 7
0
		public void ChildInvalidatesGrid ()
		{
			var child = new MyContentControl (50, 50);
			Grid grid = new Grid ();
			grid.Children.Add (child);
			grid.Measure (new Size (100, 100));
			Assert.AreEqual (new Size (50, 50), grid.DesiredSize, "#1");

			((FrameworkElement) child.Content).Height = 60;
			((FrameworkElement) child.Content).Width = 10;

			grid.Measure (new Size (100, 100));
			Assert.AreEqual (new Size (10, 60), grid.DesiredSize, "#2");
		}
Esempio n. 8
0
		public void StarRows3c ()
		{
			var canvas = new Canvas { Width = 120, Height = 120 };
			var poker = new MyContentControl ();
			MyGrid grid = new MyGrid ();
			grid.AddRows (Star, Star, Star);
			grid.AddColumns (Star, Star, Star);

			canvas.Children.Add (poker);
			poker.Content = grid;
			grid.AddChild (new MyContentControl (100, 100), 1, 1, 1, 1);

			CreateAsyncTest (canvas,
				() => { },
				() => {
					Assert.AreEqual (Infinity, poker.MeasureOverrideArg, "#1");
					Assert.AreEqual (new Size (100, 100), poker.MeasureOverrideResult, "#2");
					Assert.AreEqual (new Size (100, 100), poker.ArrangeOverrideArg, "#3");
					Assert.AreEqual (new Size (100, 100), poker.ArrangeOverrideResult, "#4");

					grid.CheckColWidths ("#5", 0, 100, 0);
					grid.CheckRowHeights ("#6", 0, 100, 0);

					grid.CheckMeasureArgs ("#7", Infinity);
					grid.CheckMeasureResult ("#8", new Size (100, 100));

					grid.CheckArrangeArgs ("#9", new Size (100, 100));
					grid.CheckArrangeResult ("#10", new Size (100, 100));
				}
			);
		}
Esempio n. 9
0
		public void ArrangeTest ()
		{
			MyGrid g = new MyGrid ();

			RowDefinition rdef;
			ColumnDefinition cdef;

			rdef = new RowDefinition ();
			rdef.Height = new GridLength (50);
			g.RowDefinitions.Add (rdef);

			cdef = new ColumnDefinition ();
			cdef.Width = new GridLength (100);
			g.ColumnDefinitions.Add (cdef);

			g.Margin = new Thickness (5);

			var r = new Border ();
			MyContentControl mc = new MyContentControl { Content = r };
			Grid.SetRow (mc, 0);
			Grid.SetColumn (mc, 0);

			g.Children.Add (mc);

			g.Measure (new Size (Double.PositiveInfinity, Double.PositiveInfinity));
			g.CheckMeasureArgs ("#MeasureOverrideArg", new Size (100, 50));
			g.Reset ();
			Assert.AreEqual (new Size (0,0), new Size (r.ActualWidth, r.ActualHeight), "r actual after measure");
			Assert.AreEqual (new Size (0,0), new Size (g.ActualWidth, g.ActualHeight), "g actual after measure");

			g.Arrange (new Rect (0,0,g.DesiredSize.Width,g.DesiredSize.Height));
			g.CheckRowHeights ("#RowHeights", 50);
			Assert.AreEqual (new Size (0,0), r.DesiredSize, "r desired 0");
			Assert.AreEqual (new Size (110,60), g.DesiredSize, "g desired 1");

			Assert.AreEqual (new Rect (0,0,100,50).ToString (), LayoutInformation.GetLayoutSlot (r).ToString(), "slot");
			Assert.AreEqual (new Size (100,50), new Size (r.ActualWidth, r.ActualHeight), "r actual after arrange");
			Assert.AreEqual (new Size (100,50), new Size (g.ActualWidth, g.ActualHeight), "g actual after arrange");
		}
Esempio n. 10
0
		public void ArrangeOverride_Constraints2 ()
		{
			MyContentControl top = new MyContentControl { Width = 25, Height = 25 };
			MyContentControl child = new MyContentControl ();
			Rectangle content = new Rectangle { Width = 50, Height = 50 };

			top.Content = child;
			child.Content = content;

			CreateAsyncTest (top, () => {
				// First check the natural results.
				Assert.AreEqual (new Size (25, 25), child.DesiredSize, "desired 1");
				Assert.AreEqual (new Size (25, 25), content.DesiredSize, "desired 2");

				Assert.AreEqual (new Size (25, 25), child.MeasureOverrideArg, "#1");
				Assert.AreEqual (new Size (25, 25), child.MeasureOverrideResult, "#2");
				Assert.AreEqual (new Size (25, 25), child.ArrangeOverrideArg, "#4");
				Assert.AreEqual (new Size (25, 25), child.ArrangeOverrideResult, "#5");
				Assert.AreEqual (new Size (25, 25), child.RenderSize, "#3");


				Assert.AreEqual (new Size (25, 25), new Size (child.ActualWidth, child.ActualHeight), "actual 1");
				Assert.AreEqual (new Size (50, 50), new Size (content.ActualWidth, content.ActualHeight), "actual 2");

				// Now give the child more size in Arrange than it requires.
				child.Arrange (new Rect (0, 0, 100, 100));
				Assert.AreEqual (new Size (25, 25), child.DesiredSize, "desired 3");
				Assert.AreEqual (new Size (25, 25), content.DesiredSize, "desired 4");
				Assert.AreEqual (new Size (100, 100), new Size (child.ActualWidth, child.ActualHeight), "actual 3");
				Assert.AreEqual (new Size (50, 50), new Size (content.ActualWidth, content.ActualHeight), "actual 4");

				Assert.AreEqual (new Size (100, 100), child.RenderSize, "#8");
				Assert.AreEqual (new Size (100, 100), child.ArrangeOverrideArg, "#9");
				Assert.AreEqual (new Size (100, 100), child.ArrangeOverrideResult, "#10");
				Assert.AreEqual (new Size (50, 50), content.RenderSize, "#11");

				// Now give the child less size
				child.Arrange (new Rect (0, 0, 10, 10));
				Assert.AreEqual (new Size (25, 25), child.DesiredSize, "desired 5");
				Assert.AreEqual (new Size (25, 25), content.DesiredSize, "desired 6");
				Assert.AreEqual (new Size (25, 25), new Size (child.ActualWidth, child.ActualHeight), "actual 5");
				Assert.AreEqual (new Size (50, 50), new Size (content.ActualWidth, content.ActualHeight), "actual 6");

				Assert.AreEqual (new Size (25, 25), child.RenderSize, "#13");
				Assert.AreEqual (new Size (25, 25), child.ArrangeOverrideArg, "#14");
				Assert.AreEqual (new Size (25, 25), child.ArrangeOverrideResult, "#15");
			});
		}
Esempio n. 11
0
		public void ComplexLayout1 ()
		{
			MyGrid g = new MyGrid ();

			RowDefinition rdef;
			ColumnDefinition cdef;

			// Add rows
			rdef = new RowDefinition ();
			rdef.Height = new GridLength (200);
			g.RowDefinitions.Add (rdef);

			rdef = new RowDefinition ();
			rdef.Height = new GridLength (200);
			g.RowDefinitions.Add (rdef);

			cdef = new ColumnDefinition ();
			cdef.Width = GridLength.Auto;
			g.ColumnDefinitions.Add (cdef);

			cdef = new ColumnDefinition ();
			cdef.Width = GridLength.Auto;
			g.ColumnDefinitions.Add (cdef);

			Canvas child1, child2, child3;
			MyContentControl mc;

			// child1
			child1 = new Canvas ();
			child1.Width = 200;
			child1.Height = 200;
			mc = new MyContentControl { Content = child1 };
			Grid.SetRow (mc, 0);
			Grid.SetColumn (mc, 0);
			Grid.SetColumnSpan (mc, 2);
			g.Children.Add (mc);

			// child2
			child2 = new Canvas ();
			child2.Width = 150;
			child2.Height = 200;
			mc = new MyContentControl { Content = child2 };
			Grid.SetRow (mc, 0);
			Grid.SetColumn (mc, 0);
			g.Children.Add (mc);

			// child3
			child3 = new Canvas ();
			child3.Width = 200;
			child3.Height = 200;
			mc = new MyContentControl { Content = child3 };
			Grid.SetRow (mc, 0);
			Grid.SetColumn (mc, 0);
			g.Children.Add (mc);

			g.Measure (new Size (Double.PositiveInfinity, Double.PositiveInfinity));
			g.CheckMeasureArgs ("#MeasureOverrideArg", new Size (inf, 200), new Size (inf, 200), new Size (inf, 200));
			g.Reset ();
			Assert.AreEqual (new Size (200, 400), g.DesiredSize, "DesiredSize");
		}
Esempio n. 12
0
		public void ArrangeChild_ColSpan2_2Columns_constSize_and_1Star_1Row_constSize ()
		{
			MyGrid g = new MyGrid ();
			g.AddRows (new GridLength (200));
			g.AddColumns (new GridLength (200), new GridLength (2, GridUnitType.Star));
			g.Margin = new Thickness (5);

			MyContentControl mc = new MyContentControl {
				Content = new Canvas { Width = 400, Height = 400 }
			};

			Grid.SetRow (mc, 0);
			Grid.SetColumn (mc, 0);
			Grid.SetColumnSpan (mc, 2);
			g.Children.Add (mc);

			TestPanel.Width = 500;
			TestPanel.Height = 500;
			CreateAsyncTest (g,
				() => {
					g.CheckMeasureArgs ("#MeasureOverrideArg", new Size (490, 200));
					g.CheckRowHeights ("#RowHeights", 200);
					g.CheckColWidths ("#ColWidths", 200, 290);

					TestPanel.Width = 100;
					TestPanel.Height = 100;
					g.Reset ();
				}, () => {
					g.CheckMeasureArgs ("#MeasureOverrideArg 2", new Size (200, 200));
					g.CheckRowHeights ("#RowHeights 2", 200);
					g.CheckColWidths ("#ColWidths 2", 200, 0);
				}
			);
		}
Esempio n. 13
0
		public void Child_ColSpan2_2Columns_constSize_and_1Star_1Row_constSize ()
		{
			MyGrid g = new MyGrid ();

			RowDefinition rdef;
			ColumnDefinition cdef;

			rdef = new RowDefinition ();
			rdef.Height = new GridLength (200);
			g.RowDefinitions.Add (rdef);

			cdef = new ColumnDefinition ();
			cdef.Width = new GridLength (200);
			g.ColumnDefinitions.Add (cdef);

			cdef = new ColumnDefinition ();
			cdef.Width = new GridLength (2, GridUnitType.Star);
			g.ColumnDefinitions.Add (cdef);

			g.Margin = new Thickness (5);

			Canvas c;
			MyContentControl mc;

			c = new Canvas ();
			c.Width = 400;
			c.Height = 400;
			mc = new MyContentControl { Content = c };
			Grid.SetRow (mc, 0);
			Grid.SetColumn (mc, 0);
			Grid.SetColumnSpan (mc, 2);
			g.Children.Add (mc);

			g.Measure (new Size (Double.PositiveInfinity, Double.PositiveInfinity));
			g.CheckMeasureArgs ("#MeasureOverrideArg", new Size (inf, 200));
			g.Reset ();
			Assert.AreEqual (new Size (400, 200), c.DesiredSize, "DesiredSize0");

			Assert.AreEqual (new Size (410, 210), g.DesiredSize, "DesiredSize1");

			g.Measure (new Size (100, 100));
			g.CheckMeasureArgs ("#MeasureOverrideArg 2", new Size (200, 200));
			g.Reset ();
			Assert.AreEqual (new Size (100, 100), g.DesiredSize, "DesiredSize2");
		}
Esempio n. 14
0
		public void RowspanAutoTest ()
		{
			// This test demonstrates the following rules:
			// 1) Elements with RowSpan/ColSpan == 1 distribute their height first
			// 2) The rest of the elements distribute height in LIFO order
			Grid grid = new Grid ();
			grid.AddRows (GridLength.Auto, GridLength.Auto, GridLength.Auto);
			grid.AddColumns (new GridLength (50));

			var child50 = new MyContentControl (50, 50);
			var child60 = new MyContentControl (50, 60);

			grid.AddChild (child50, 0, 0, 1, 1);
			grid.AddChild (child60, 0, 0, 1, 1);

			CreateAsyncTest (grid,
				() => {
					// Check the initial values
					grid.CheckRowHeights ("#1", 60, 0, 0);

					// Now make the smaller element use rowspan = 2
					Grid.SetRowSpan (child50, 2);
				}, () => {
					grid.CheckRowHeights ("#2", 60, 0, 0);

					// Then make the larger element us rowspan = 2
					Grid.SetRowSpan (child50, 1);
					Grid.SetRowSpan (child60, 2);
				}, () => {
					grid.CheckRowHeights ("#3", 55, 5, 0);

					// Swap the order in which they are added to the grid
					grid.Children.Clear ();
					grid.AddChild (child60, 0, 0, 2, 0);
					grid.AddChild (child50, 0, 0, 1, 0);
				}, () => {
					// Swapping the order has no effect here
					grid.CheckRowHeights ("#4", 55, 5, 0);

					// Then give both rowspan = 2
					Grid.SetRowSpan (child50, 2);
				}, () => {
					grid.CheckRowHeights ("#5", 30, 30, 0);

					// Finally give the larger element rowspan = 3
					Grid.SetRowSpan (child60, 3);
				}, () => {
					grid.CheckRowHeights ("#6", 28.333, 28.333, 3.333);

					// Swap the order in which the elements are added again
					grid.Children.Clear ();
					grid.AddChild (child50, 0, 0, 2, 0);
					grid.AddChild (child60, 0, 0, 3, 0);
				}, () => {
					grid.CheckRowHeights ("#7", 25, 25, 20);
				}
			);
		}
Esempio n. 15
0
		public void StarRows3d ()
		{
			var poker = new MyContentControl { Width = 120, Height = 120 };
			MyGrid grid = new MyGrid ();
			grid.AddRows (Star, Star, Star);
			grid.AddColumns (Star, Star, Star);

			poker.Content = grid;
			grid.AddChild (new MyContentControl (100, 100), 1, 1, 1, 1);

			CreateAsyncTest (poker,
				() => { },
				() => {
					Assert.AreEqual (new Size (120, 120), poker.MeasureOverrideArg, "#1");
					Assert.AreEqual (new Size (40, 40), poker.MeasureOverrideResult, "#2");
					Assert.AreEqual (new Size (40, 40), grid.DesiredSize, "#2b");
					Assert.AreEqual (new Size (120, 120), poker.DesiredSize, "#2c");
					Assert.AreEqual (new Size (120, 120), poker.ArrangeOverrideArg, "#3");
					Assert.AreEqual (new Size (120, 120), poker.ArrangeOverrideResult, "#4");

					grid.CheckColWidths ("#5", 0, 40, 0);
					grid.CheckRowHeights ("#6", 0, 40, 0);

					grid.CheckMeasureArgs ("#7", new Size (40, 40));
					grid.CheckMeasureResult ("#8", new Size (40, 40));

					grid.CheckArrangeArgs ("#9", new Size (40, 40));
					grid.CheckArrangeResult ("#10", new Size (40, 40));
				}
			);
		}
Esempio n. 16
0
		public void StarAutoIsNotInfinite ()
		{
			var child1 =new MyContentControl { };
			var child2 = new MyContentControl { };
			MyGrid grid = new MyGrid ();
			grid.AddRows (Auto, Auto, Auto, Star);
			grid.AddColumns (Auto, Star);

			grid.AddChild (child1, 0, 0, 1, 1);
			grid.AddChild (child2, 0, 0, 4, 2);

			grid.Measure (new Size (100, 100));
			Assert.AreEqual (Infinity, child1.MeasureOverrideArg, "#1");
			Assert.AreEqual (new Size (100, 100), child2.MeasureOverrideArg, "#2");
		}
Esempio n. 17
0
		public void ExpandStarsInStackPanel ()
		{
			MyGrid grid = CreateGridWithChildren ();
			MyContentControl c = new MyContentControl ();
			//c.Content = grid;
			var parent = new StackPanel ();
			parent.Children.Add (grid);

			TestPanel.Width = 75;
			TestPanel.Height = 75;

			CreateAsyncTest (parent,
				() => {
					grid.CheckRowHeights ("#1", 15, 15, 15);
					grid.CheckColWidths ("#2", 12, 25, 38);
					
					grid.HorizontalAlignment = HorizontalAlignment.Left;
					grid.VerticalAlignment = VerticalAlignment.Center;
					parent.InvalidateSubtree ();
				}, () => {
					grid.CheckRowHeights ("#3", 15, 15, 15);
					grid.CheckColWidths ("#4", 12, 15, 15);

					grid.Width = 50;
					grid.Height = 50;
					parent.InvalidateSubtree ();
				}, () => {
					grid.CheckRowHeights ("#5", 8, 17, 25);
					grid.CheckColWidths ("#6", 8, 17, 25);

					grid.ClearValue (Grid.HorizontalAlignmentProperty);
					grid.ClearValue (Grid.VerticalAlignmentProperty);
					parent.InvalidateSubtree ();
				}, () => {
					grid.CheckRowHeights ("#7", 8, 17, 25);
					grid.CheckColWidths ("#8", 8, 17, 25);
				}
			);
		}