public void Not_Visible_Children_Are_Ignored() { var target = new UniformGrid() { Children = { new Border { Width = 50, Height = 70 }, new Border { Width = 30, Height = 50 }, new Border { Width = 80, Height = 90, IsVisible = false }, new Border { Width = 20, Height = 30 }, new Border { Width = 40, Height = 60 } } }; target.Measure(Size.Infinity); target.Arrange(new Rect(target.DesiredSize)); // 2 * 2 grid Assert.Equal(new Size(2 * 50, 2 * 70), target.Bounds.Size); }
public DrawButtonsOnBitmap() { Title = "Draw Buttons on Bitmap"; //заголовок UniformGrid unigrid = new UniformGrid(); // создание униформ-грида для хостинга кнопок unigrid.Columns = 4; //колонки униформ-грида for (int i = 0; i < 32; i++) // создание 32 объектов, каждый из кот. может содержать один объект любого типа (ToggleButton) { ToggleButton btn = new ToggleButton(); //создание ToggleButton btn.Width = 96; //параметры btn.Height = 24; btn.IsChecked = (i < 4 | i > 27) ^ (i % 4 == 0 | i % 4 == 3); //устанавивает находится ли ToggleButton во включ. состоянии unigrid.Children.Add(btn); //добавление кнопок в грид } unigrid.Measure(new Size(Double.PositiveInfinity, Double.PositiveInfinity)); //рекурсивное обновление структуры грида Size szGrid = unigrid.DesiredSize; // размеры униформ-грида. unigrid.Arrange(new Rect(new Point(0, 0), szGrid)); // организация грида. RenderTargetBitmap renderbitmap = new RenderTargetBitmap((int)Math.Ceiling(szGrid.Width), (int)Math.Ceiling(szGrid.Height), 96, 96, PixelFormats.Default); // создание RenderTargetBitmap (преобразует объект Visual в растровое изображение) renderbitmap.Render(unigrid); // преобразование грида в растровое изображение. Image img = new Image(); // создание нового объекта Image. img.Source = renderbitmap; //установка Source объекта Image в растрвое изображение Content = img; // содержимое окна - объект Image. }
public void Grid_Extends_For_Columns_And_First_Column_With_Auto_Rows() { var target = new UniformGrid() { Columns = 3, FirstColumn = 2, Children = { new Border { Width = 50, Height = 70 }, new Border { Width = 30, Height = 50 }, new Border { Width = 80, Height = 90 }, new Border { Width = 20, Height = 30 }, new Border { Width = 40, Height = 60 } } }; target.Measure(Size.Infinity); target.Arrange(new Rect(target.DesiredSize)); // 3 * 3 grid Assert.Equal(new Size(3 * 80, 3 * 90), target.Bounds.Size); }
public void Grid_Expands_Horizontally_For_Rows_With_Auto_Columns() { var target = new UniformGrid() { Rows = 2, Children = { new Border { Width = 50, Height = 70 }, new Border { Width = 30, Height = 50 }, new Border { Width = 80, Height = 90 }, new Border { Width = 20, Height = 30 }, new Border { Width = 40, Height = 60 } } }; target.Measure(Size.Infinity); target.Arrange(new Rect(target.DesiredSize)); // 3 * 2 grid Assert.Equal(new Size(3 * 80, 2 * 90), target.Bounds.Size); }
public void Grid_Size_Is_Limited_By_Rows_And_Columns() { var target = new UniformGrid() { Columns = 2, Rows = 2, Children = { new Border { Width = 50, Height = 70 }, new Border { Width = 30, Height = 50 }, new Border { Width = 80, Height = 90 }, new Border { Width = 20, Height = 30 }, new Border { Width = 40, Height = 60 } } }; target.Measure(Size.Infinity); target.Arrange(new Rect(target.DesiredSize)); // 2 * 2 grid Assert.Equal(new Size(2 * 80, 2 * 90), target.Bounds.Size); }
public void TestSurroudingAnchor() { var childSize1 = new Vector3(50, 150, 250); var childSize2 = new Vector3(100, 200, 300); var grid = new UniformGrid { Columns = 2, VerticalAlignment = VerticalAlignment.Center, HorizontalAlignment = HorizontalAlignment.Center}; var child1 = new UniformGrid { Size = childSize1 }; var child2 = new UniformGrid { Size = childSize2 }; child2.DependencyProperties.Set(ColumnPropertyKey, 1); grid.Children.Add(child1); grid.Children.Add(child2); grid.Measure(1000 * Vector3.One); grid.Arrange(1000 * Vector3.One, false); Assert.AreEqual(new Vector2(0, 100), grid.GetSurroudingAnchorDistances(Orientation.Horizontal, -1)); Assert.AreEqual(new Vector2(0, 100), grid.GetSurroudingAnchorDistances(Orientation.Horizontal, 0)); Assert.AreEqual(new Vector2(-50, 50), grid.GetSurroudingAnchorDistances(Orientation.Horizontal, 50)); Assert.AreEqual(new Vector2(-80, 20), grid.GetSurroudingAnchorDistances(Orientation.Horizontal, 80)); Assert.AreEqual(new Vector2(0, 100), grid.GetSurroudingAnchorDistances(Orientation.Horizontal, 100)); Assert.AreEqual(new Vector2(-10, 90), grid.GetSurroudingAnchorDistances(Orientation.Horizontal, 110)); Assert.AreEqual(new Vector2(-100, 0), grid.GetSurroudingAnchorDistances(Orientation.Horizontal, 200)); Assert.AreEqual(new Vector2(-100, 0), grid.GetSurroudingAnchorDistances(Orientation.Horizontal, 300)); Assert.AreEqual(new Vector2(0, 200), grid.GetSurroudingAnchorDistances(Orientation.Vertical, -1)); Assert.AreEqual(new Vector2(-100, 100), grid.GetSurroudingAnchorDistances(Orientation.Vertical, 100)); Assert.AreEqual(new Vector2(-200, 0), grid.GetSurroudingAnchorDistances(Orientation.Vertical, 500)); Assert.AreEqual(new Vector2(0, 300), grid.GetSurroudingAnchorDistances(Orientation.InDepth, -1)); Assert.AreEqual(new Vector2(-150, 150), grid.GetSurroudingAnchorDistances(Orientation.InDepth, 150)); Assert.AreEqual(new Vector2(-300, 0), grid.GetSurroudingAnchorDistances(Orientation.InDepth, 500)); }
public void UniformGridFirstColumnTest() { FrameworkElement child1 = new FrameworkElement(); UniformGrid uniformGrid = new UniformGrid { FirstColumn = 3 }; uniformGrid.Children.Add(child1); uniformGrid.Measure(Size.Infinity); uniformGrid.Arrange(new Rect(120, 120)); Assert.AreEqual(new Rect(60, 60, 60, 60), child1.VisualBounds); }
public DrawButtonsOnBitmap() { Title = "Draw Buttons on Bitmap"; // Create a UniformGrid for hosting buttons. UniformGrid unigrid = new UniformGrid(); unigrid.Columns = 4; // Create 32 ToggleButton objects on UniformGrid. for (int i = 0; i < 32; i++) { ToggleButton btn = new ToggleButton(); btn.Width = 96; btn.Height = 24; btn.IsChecked = (i < 4 | i > 27) ^ (i % 4 == 0 | i % 4 == 3); unigrid.Children.Add(btn); } // Size the UniformGrid. unigrid.Measure(new Size(Double.PositiveInfinity, Double.PositiveInfinity)); Size szGrid = unigrid.DesiredSize; // Arrange the UniformGrid. unigrid.Arrange(new Rect(new Point(0, 0), szGrid)); // Create the RenderTargetBitmap object. RenderTargetBitmap renderbitmap = new RenderTargetBitmap((int)Math.Ceiling(szGrid.Width), (int)Math.Ceiling(szGrid.Height), 96, 96, PixelFormats.Default); // Render the UniformGrid on the RenderTargetBitmap. renderbitmap.Render(unigrid); // Create an Image object and set its Source to the bitmap. Image img = new Image(); img.Source = renderbitmap; // Make the Image object the content of the window. Content = img; }
public void UniformGridDefaultLayoutTest() { FrameworkElement child1 = new FrameworkElement(); FrameworkElement child2 = new FrameworkElement(); FrameworkElement child3 = new FrameworkElement(); UniformGrid uniformGrid = new UniformGrid(); uniformGrid.Children.Add(child1); uniformGrid.Children.Add(child2); uniformGrid.Children.Add(child3); uniformGrid.Measure(Size.Infinity); uniformGrid.Arrange(new Rect(120, 120)); Assert.AreEqual(new Rect(0, 0, 60, 60), child1.VisualBounds); Assert.AreEqual(new Rect(60, 0, 60, 60), child2.VisualBounds); Assert.AreEqual(new Rect(0, 60, 60, 60), child3.VisualBounds); }
public void TestSurroudingAnchor() { var childSize1 = new Vector3(50, 150, 250); var childSize2 = new Vector3(100, 200, 300); var grid = new UniformGrid { Columns = 2, VerticalAlignment = VerticalAlignment.Center, HorizontalAlignment = HorizontalAlignment.Center }; var child1 = new UniformGrid { Size = childSize1 }; var child2 = new UniformGrid { Size = childSize2 }; child2.DependencyProperties.Set(ColumnPropertyKey, 1); grid.Children.Add(child1); grid.Children.Add(child2); grid.Measure(1000 * Vector3.One); grid.Arrange(1000 * Vector3.One, false); Assert.Equal(new Vector2(0, 100), grid.GetSurroudingAnchorDistances(Orientation.Horizontal, -1)); Assert.Equal(new Vector2(0, 100), grid.GetSurroudingAnchorDistances(Orientation.Horizontal, 0)); Assert.Equal(new Vector2(-50, 50), grid.GetSurroudingAnchorDistances(Orientation.Horizontal, 50)); Assert.Equal(new Vector2(-80, 20), grid.GetSurroudingAnchorDistances(Orientation.Horizontal, 80)); Assert.Equal(new Vector2(0, 100), grid.GetSurroudingAnchorDistances(Orientation.Horizontal, 100)); Assert.Equal(new Vector2(-10, 90), grid.GetSurroudingAnchorDistances(Orientation.Horizontal, 110)); Assert.Equal(new Vector2(-100, 0), grid.GetSurroudingAnchorDistances(Orientation.Horizontal, 200)); Assert.Equal(new Vector2(-100, 0), grid.GetSurroudingAnchorDistances(Orientation.Horizontal, 300)); Assert.Equal(new Vector2(0, 200), grid.GetSurroudingAnchorDistances(Orientation.Vertical, -1)); Assert.Equal(new Vector2(-100, 100), grid.GetSurroudingAnchorDistances(Orientation.Vertical, 100)); Assert.Equal(new Vector2(-200, 0), grid.GetSurroudingAnchorDistances(Orientation.Vertical, 500)); Assert.Equal(new Vector2(0, 300), grid.GetSurroudingAnchorDistances(Orientation.InDepth, -1)); Assert.Equal(new Vector2(-150, 150), grid.GetSurroudingAnchorDistances(Orientation.InDepth, 150)); Assert.Equal(new Vector2(-300, 0), grid.GetSurroudingAnchorDistances(Orientation.InDepth, 500)); }
public void Grid_Columns_Equals_Rows_For_Auto_Columns_And_Rows() { var target = new UniformGrid() { Children = { new Border { Width = 50, Height = 70 }, new Border { Width = 30, Height = 50 }, new Border { Width = 80, Height = 90 } } }; target.Measure(Size.Infinity); target.Arrange(new Rect(target.DesiredSize)); // 2 * 2 grid Assert.Equal(new Size(2 * 80, 2 * 90), target.Bounds.Size); }
/// <summary> /// /// </summary> /// <param name="finalSize"></param> /// <returns></returns> protected override Size ArrangeOverride(Size finalSize) { unigrid.Arrange(new Rect(new Point(0, 0), finalSize)); return(finalSize); }