public void WrapPanelLayoutTest() { WrapPanel panel = new WrapPanel(); panel.IsRootElement = true; FrameworkElement child1 = new FrameworkElement { Width = 200, Height = 100 }; FrameworkElement child2 = new FrameworkElement { Width = 200, Height = 100 }; FrameworkElement child3 = new FrameworkElement { Width = 200, Height = 60, Margin = new Thickness(0, 10) }; FrameworkElement child4 = new FrameworkElement { Width = 200, Height = 60, Margin = new Thickness(0, 10) }; FrameworkElement child5 = new FrameworkElement { Width = 200, Height = 60 }; panel.Children.Add(child1); panel.Children.Add(child2); panel.Children.Add(child3); panel.Children.Add(child4); panel.Children.Add(child5); panel.Measure(new Size(1000, 1000)); Assert.AreEqual(new Size(1000, 100), panel.DesiredSize); panel.Arrange(new Rect(1000, 100)); Assert.AreEqual(new Size(1000, 100), panel.RenderSize); Assert.AreEqual(new Point(0, 0), child1.VisualOffset); Assert.AreEqual(new Point(200, 0), child2.VisualOffset); Assert.AreEqual(new Point(400, 20), child3.VisualOffset); Assert.AreEqual(new Point(600, 20), child4.VisualOffset); Assert.AreEqual(new Point(800, 20), child5.VisualOffset); panel.Measure(new Size(500, 1000)); Assert.AreEqual(new Size(400, 240), panel.DesiredSize); panel.Arrange(new Rect(500, 240)); Assert.AreEqual(new Point(0, 0), child1.VisualOffset); Assert.AreEqual(new Point(200, 0), child2.VisualOffset); Assert.AreEqual(new Point(0, 110), child3.VisualOffset); Assert.AreEqual(new Point(200, 110), child4.VisualOffset); Assert.AreEqual(new Point(0, 180), child5.VisualOffset); }
protected override Size MeasureOverride(Size constraint) { double maxWrapPanelWidth = ThumbnailSize.Width * Columns; if (WrapPanel.MaxWidth != maxWrapPanelWidth) { WrapPanel.MaxWidth = maxWrapPanelWidth; WrapPanel.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity)); } Size size = base.MeasureOverride(constraint); double w = CalculateInRibbonThumbnailWidth(); if (WrapPanel.MaxWidth != w) { WrapPanel.MaxWidth = w; WrapPanel.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity)); size = base.MeasureOverride(constraint); } int visibleItems = (int)(size.Width / ThumbnailSize.Width); IsDropDownEnabled = visibleItems < Items.Count; return(size); }
public void WrapPanelLayoutParseTest() { string text = @" <WrapPanel xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation'> <FrameworkElement Width='200' Height='100'/> <FrameworkElement Width='200' Height='100'/> <FrameworkElement Width='200' Height='60' Margin='0,10'/> <FrameworkElement Width='200' Height='60' Margin='0,10'/> <FrameworkElement Width='200' Height='60'/> </WrapPanel>"; XamlElement rootElement = XamlParser.Parse(text); WrapPanel panel = XamlLoader.Load(rootElement) as WrapPanel; panel.IsRootElement = true; panel.Measure(new Size(1000, 1000)); Assert.AreEqual(new Size(1000, 100), panel.DesiredSize); panel.Arrange(new Rect(1000, 100)); Assert.AreEqual(new Size(1000, 100), panel.RenderSize); Assert.AreEqual(new Point(0, 0), panel.Children[0].VisualOffset); Assert.AreEqual(new Point(200, 0), panel.Children[1].VisualOffset); Assert.AreEqual(new Point(400, 20), panel.Children[2].VisualOffset); Assert.AreEqual(new Point(600, 20), panel.Children[3].VisualOffset); Assert.AreEqual(new Point(800, 20), panel.Children[4].VisualOffset); panel.Measure(new Size(500, 1000)); Assert.AreEqual(new Size(400, 240), panel.DesiredSize); panel.Arrange(new Rect(500, 240)); Assert.AreEqual(new Point(0, 0), panel.Children[0].VisualOffset); Assert.AreEqual(new Point(200, 0), panel.Children[1].VisualOffset); Assert.AreEqual(new Point(0, 110), panel.Children[2].VisualOffset); Assert.AreEqual(new Point(200, 110), panel.Children[3].VisualOffset); Assert.AreEqual(new Point(0, 180), panel.Children[4].VisualOffset); }
void ItemHeight_Trigger_InvalidateMeasure() { var target = new WrapPanel(); target.Measure(new Size(10, 10)); Assert.True(target.IsMeasureValid); target.ItemHeight = 1; Assert.False(target.IsMeasureValid); }
public void Lays_Out_Horizontally_On_A_Single_Line() { var target = new WrapPanel() { Width = 200, Children = new Controls { new Border { Height = 50, Width = 100 }, new Border { Height = 50, Width = 100 }, } }; target.Measure(Size.Infinity); target.Arrange(new Rect(target.DesiredSize)); Assert.Equal(new Size(200, 50), target.Bounds.Size); Assert.Equal(new Rect(0, 0, 100, 50), target.Children[0].Bounds); Assert.Equal(new Rect(100, 0, 100, 50), target.Children[1].Bounds); }
public void Applies_ItemWidth_And_ItemHeight_Properties() { var target = new WrapPanel() { Orientation = Orientation.Horizontal, Width = 50, ItemWidth = 20, ItemHeight = 15, Children = { new Border(), new Border(), } }; target.Measure(Size.Infinity); target.Arrange(new Rect(target.DesiredSize)); Assert.Equal(new Size(50, 15), target.Bounds.Size); Assert.Equal(new Rect(0, 0, 20, 15), target.Children[0].Bounds); Assert.Equal(new Rect(20, 0, 20, 15), target.Children[1].Bounds); }
public void Lays_Out_Horizontally_On_A_Single_Line() { var target = new WrapPanel() { Width = 200, Children = { new Border { Height = 50, Width = 100 }, new Border { Height = 50, Width = 100 }, } }; target.Measure(Size.Infinity); target.Arrange(new Rect(target.DesiredSize)); Assert.Equal(new Size(200, 50), target.Bounds.Size); Assert.Equal(new Rect(0, 0, 100, 50), target.Children[0].Bounds); Assert.Equal(new Rect(100, 0, 100, 50), target.Children[1].Bounds); }
public void Lays_Out_Horizontally_On_A_Single_Line() { var target = new WrapPanel() { Width = 200, Children = { new Border { Height = 50, Width = 100 }, new Border { Height = 50, Width = 100 }, } }; target.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity)); target.Arrange(new Rect(target.DesiredSize)); Assert.Equal(new Size(200, 50), new Size(target.ActualWidth, target.ActualHeight)); Assert.Equal(new Rect(0, 0, 100, 50), target.Children[0].BoundsRelativeTo(target)); Assert.Equal(new Rect(100, 0, 100, 50), target.Children[1].BoundsRelativeTo(target)); }
public void Lays_Out_Vertically_On_Separate_Lines() { var target = new WrapPanel() { Orientation = Orientation.Vertical, Height = 60, Children = { new Border { Height = 50, Width = 100 }, new Border { Height = 50, Width = 100 }, } }; target.Measure(Size.Infinity); target.Arrange(new Rect(target.DesiredSize)); Assert.Equal(new Size(200, 60), target.Bounds.Size); Assert.Equal(new Rect(0, 0, 100, 50), target.Children[0].Bounds); Assert.Equal(new Rect(100, 0, 100, 50), target.Children[1].Bounds); }
public void Lays_Out_Vertically_Children_On_A_Single_Line() { var target = new WrapPanel() { Orientation = Orientation.Vertical, Height = 120, Children = new Controls { new Border { Height = 50, Width = 100 }, new Border { Height = 50, Width = 100 }, } }; target.Measure(Size.Infinity); target.Arrange(new Rect(target.DesiredSize)); Assert.Equal(new Size(100, 120), target.Bounds.Size); Assert.Equal(new Rect(0, 0, 100, 50), target.Children[0].Bounds); Assert.Equal(new Rect(0, 50, 100, 50), target.Children[1].Bounds); }
public void Lays_Out_Vertically_On_Separate_Lines() { var target = new WrapPanel() { Orientation = Orientation.Vertical, Height = 60, Children = new Controls { new Border { Height = 50, Width = 100 }, new Border { Height = 50, Width = 100 }, } }; target.Measure(Size.Infinity); target.Arrange(new Rect(target.DesiredSize)); Assert.Equal(new Size(200, 60), target.Bounds.Size); Assert.Equal(new Rect(0, 0, 100, 50), target.Children[0].Bounds); Assert.Equal(new Rect(100, 0, 100, 50), target.Children[1].Bounds); }