public void When_Horizontal_And_Fixed_Width_Item_And_Measured_Height_is_Valid() { var SUT = new StackPanel() { Name = "test", Orientation = Orientation.Horizontal }; var c1 = SUT.AddChild( new View { Name = "Child01", DesiredSizeSelector = s => { s.Height.Should().Be(20.0d); return(new Windows.Foundation.Size(8, 10)); }, Height = 10 } ); SUT.Measure(new Windows.Foundation.Size(20, 20)); var measuredSize = SUT.DesiredSize; Assert.AreEqual(new Windows.Foundation.Size(8, 10), measuredSize, "measuredSize"); Assert.AreEqual(new Windows.Foundation.Size(8, 10), c1.DesiredSize); SUT.Arrange(new Windows.Foundation.Rect(0, 0, 20, 20)); Assert.AreEqual(new Windows.Foundation.Rect(0, 5, 8, 10), c1.Arranged); Assert.AreEqual(1, SUT.GetChildren().Count()); }
public void When_Vertical_And_SimpleLayout_With_Spacing() { var SUT = new StackPanel { Name = "test", Orientation = Orientation.Vertical, Spacing = 5 }; var c1 = SUT.AddChild( child: new View { Name = "Child01", RequestedDesiredSize = new Size(width: 10, height: 8) } ); var c2 = SUT.AddChild( child: new View { Name = "Child02", RequestedDesiredSize = new Size(width: 10, height: 7) } ); SUT.Measure(availableSize: new Size(width: 20, height: 20)); Assert.AreEqual(expected: new Size(width: 10, height: 20), actual: SUT.DesiredSize, message: "measuredSize"); SUT.Arrange(finalRect: new Rect(x: 0, y: 0, width: 20, height: 20)); Assert.AreEqual(expected: new Rect(x: 0, y: 0, width: 20, height: 8), actual: c1.Arranged); Assert.AreEqual(expected: new Rect(x: 0, y: 13, width: 20, height: 7), actual: c2.Arranged); Assert.AreEqual(expected: 2, actual: SUT.GetChildren().Count()); }
public void When_Vertical_And_Fixed_Height_And_Width_Item_With_Margin() { var SUT = new StackPanel { Name = "test", Orientation = Orientation.Vertical }; var c1 = SUT.AddChild( child: new View { Name = "Child02", DesiredSizeSelector = s => { s.Width.Should().Be(expected: 30.0d); s.Height.Should().Be(expected: double.PositiveInfinity); return(new Size(width: 10, height: 10)); }, Height = 10, Margin = new Thickness(uniformLength: 10) } ); SUT.Measure(availableSize: new Size(width: 30, height: 30)); SUT.DesiredSize.Should().Be(new Size(10, 10)); c1.DesiredSize.Should().Be(new Size(10, 10)); SUT.Arrange(finalRect: new Rect(x: 0, y: 0, width: 30, height: 30)); SUT.Arranged.Should().Be((Rect)"0,0,30,30"); c1.Arranged.Should().Be((Rect)"10,10,10,0"); // size is 10x0 because of margins (w= 30-(10+10), h=10-(10+10)) SUT.GetChildren().Should().HaveCount(1); }
public void When_Horizontal_And_Fixed_Height_Item() { var SUT = new StackPanel() { Name = "test", Orientation = Orientation.Horizontal }; var c1 = SUT.AddChild( new View { Name = "Child01", RequestedDesiredSize = new Windows.Foundation.Size(8, 10), Height = 10 } ); SUT.Measure(new Windows.Foundation.Size(20, 20)); var measuredSize = SUT.DesiredSize; Assert.AreEqual(new Windows.Foundation.Size(8, 10), measuredSize, "measuredSize"); Assert.AreEqual(new Windows.Foundation.Size(8, 10), c1.DesiredSize); SUT.Arrange(new Windows.Foundation.Rect(0, 0, 20, 20)); Assert.AreEqual(new Windows.Foundation.Rect(0, 5, 8, 10), c1.Arranged); Assert.AreEqual(1, SUT.GetChildren().Count()); }
public void When_Vertical_And_Fixed_Height_And_Width_Item_With_Margin() { var SUT = new StackPanel() { Name = "test", Orientation = Orientation.Vertical }; var c1 = SUT.AddChild( new View { Name = "Child02", DesiredSizeSelector = s => { s.Width.Should().Be(30.0d); s.Height.Should().Be(double.PositiveInfinity); return(new Windows.Foundation.Size(10, 10)); }, Height = 10, Margin = new Thickness(10) } ); SUT.Measure(new Windows.Foundation.Size(30, 30)); var measuredSize = SUT.DesiredSize; Assert.AreEqual(new Windows.Foundation.Size(30, 30), measuredSize, "measuredSize"); Assert.AreEqual(new Windows.Foundation.Size(30, 30), c1.DesiredSize); SUT.Arrange(new Windows.Foundation.Rect(0, 0, 30, 30)); Assert.AreEqual(new Windows.Foundation.Rect(10, 10, 10, 10), c1.Arranged); Assert.AreEqual(1, SUT.GetChildren().Count()); }
public void When_Vertical_And_Fixed_MaxWidth_Oversized() { var SUT = new StackPanel() { Name = "test", Orientation = Orientation.Vertical }; var c1 = SUT.AddChild( new View { Name = "Child01", RequestedDesiredSize = new Windows.Foundation.Size(10, 8), MaxWidth = 20 } ); SUT.Measure(new Windows.Foundation.Size(25, 20)); var measuredSize = SUT.DesiredSize; Assert.AreEqual(new Windows.Foundation.Size(10, 8), measuredSize, "measuredSize"); Assert.AreEqual(new Windows.Foundation.Size(25, float.PositiveInfinity), c1.AvailableMeasureSize, "AvailableMeasureSize"); Assert.AreEqual(new Windows.Foundation.Size(10, 8), c1.DesiredSize); SUT.Arrange(new Windows.Foundation.Rect(0, 0, 30, 20)); Assert.AreEqual(new Windows.Foundation.Rect(5, 0, 20, 8), c1.Arranged); Assert.AreEqual(1, SUT.GetChildren().Count()); }
public void When_Vertical_And_Fixed_MaxWidth_Oversized() { var SUT = new StackPanel { Name = "test", Orientation = Orientation.Vertical }; var c1 = SUT.AddChild( child: new View { Name = "Child01", RequestedDesiredSize = new Size(width: 10, height: 8), MaxWidth = 20 } ); SUT.Measure(availableSize: new Size(width: 25, height: 20)); var measuredSize = SUT.DesiredSize; Assert.AreEqual(expected: new Size(width: 10, height: 8), actual: measuredSize, message: "measuredSize"); Assert.AreEqual(expected: new Size(width: 25, height: float.PositiveInfinity), actual: c1.AvailableMeasureSize, message: "AvailableMeasureSize"); Assert.AreEqual(expected: new Size(width: 10, height: 8), actual: c1.DesiredSize); SUT.Arrange(finalRect: new Rect(x: 0, y: 0, width: 30, height: 20)); Assert.AreEqual(expected: new Rect(x: 5, y: 0, width: 20, height: 8), actual: c1.Arranged); Assert.AreEqual(expected: 1, actual: SUT.GetChildren().Count()); }
public void When_Horizontal_And_Fixed_Width_Item_And_Measured_Height_is_Valid() { var SUT = new StackPanel { Name = "test", Orientation = Orientation.Horizontal }; var c1 = SUT.AddChild( child: new View { Name = "Child01", DesiredSizeSelector = s => { s.Height.Should().Be(expected: 20.0d); return(new Size(width: 8, height: 10)); }, Height = 10 } ); SUT.Measure(availableSize: new Size(width: 20, height: 20)); var measuredSize = SUT.DesiredSize; Assert.AreEqual(expected: new Size(width: 8, height: 10), actual: measuredSize, message: "measuredSize"); Assert.AreEqual(expected: new Size(width: 8, height: 10), actual: c1.DesiredSize); SUT.Arrange(finalRect: new Rect(x: 0, y: 0, width: 20, height: 20)); Assert.AreEqual(expected: new Rect(x: 0, y: 5, width: 8, height: 10), actual: c1.Arranged); Assert.AreEqual(expected: 1, actual: SUT.GetChildren().Count()); }
public void When_Vertical_And_SimpleLayout_With_Spacing() { var SUT = new StackPanel() { Name = "test", Orientation = Orientation.Vertical, Spacing = 5 }; var c1 = SUT.AddChild( new View { Name = "Child01", RequestedDesiredSize = new Windows.Foundation.Size(10, 8) } ); var c2 = SUT.AddChild( new View { Name = "Child02", RequestedDesiredSize = new Windows.Foundation.Size(10, 7) } ); SUT.Measure(new Windows.Foundation.Size(20, 20)); Assert.AreEqual(new Windows.Foundation.Size(10, 20), SUT.DesiredSize, "measuredSize"); Assert.AreEqual(new Windows.Foundation.Size(10, 8), c1.RequestedDesiredSize); Assert.AreEqual(new Windows.Foundation.Size(10, 7), c2.RequestedDesiredSize); SUT.Arrange(new Windows.Foundation.Rect(0, 0, 20, 20)); Assert.AreEqual(new Windows.Foundation.Rect(0, 0, 20, 8), c1.Arranged); Assert.AreEqual(new Windows.Foundation.Rect(0, 13, 20, 7), c2.Arranged); Assert.AreEqual(2, SUT.GetChildren().Count()); }
public void When_Horizontal_And_SimpleLayout() { var SUT = new StackPanel() { Name = "test", Orientation = Orientation.Horizontal }; var c1 = SUT.AddChild( new View { Name = "Child01", RequestedDesiredSize = new Windows.Foundation.Size(5, 8) } ); var c2 = SUT.AddChild( new View { Name = "Child02", RequestedDesiredSize = new Windows.Foundation.Size(12, 7) } ); SUT.Measure(new Windows.Foundation.Size(20, 20)); var measuredSize = SUT.DesiredSize; Assert.AreEqual(new Windows.Foundation.Size(17, 8), measuredSize, "measuredSize"); Assert.AreEqual(new Windows.Foundation.Size(5, 8), c1.RequestedDesiredSize); Assert.AreEqual(new Windows.Foundation.Size(12, 7), c2.RequestedDesiredSize); SUT.Arrange(new Windows.Foundation.Rect(0, 0, 20, 20)); Assert.AreEqual(new Windows.Foundation.Rect(0, 0, 5, 20), c1.Arranged); Assert.AreEqual(new Windows.Foundation.Rect(5, 0, 12, 20), c2.Arranged); Assert.AreEqual(2, SUT.GetChildren().Count()); }
public static void InitializeEvents(this StackPanel pObjStackPanel) { foreach (FrameworkElement lObjElement in pObjStackPanel.GetChildren().Where(x => x.GetType() == typeof(TextBox) || x.GetType() == typeof(CheckBox) || x.GetType() == typeof(ToggleButton) || x.GetType() == typeof(PasswordBox) || x.GetType() == typeof(Button))) { lObjElement.KeyDown += new KeyEventHandler(Element_KeyDown); } //foreach (TextBox lObjTextBox in pObjGrid.GetChildren().OfType<TextBox>()) //{ // lObjTextBox.KeyDown += new KeyEventHandler(Element_KeyDown); //} //foreach (CheckBox lObjCheckBox in pObjGrid.GetChildren().OfType<CheckBox>()) //{ // lObjCheckBox.KeyDown += new KeyEventHandler(Element_KeyDown); //} //foreach (ToggleButton lObjToggleButton in pObjGrid.GetChildren().OfType<ToggleButton>()) //{ // lObjToggleButton.KeyDown += new KeyEventHandler(Element_KeyDown); //} //foreach (PasswordBox lObjPasswordBox in pObjGrid.GetChildren().OfType<PasswordBox>()) //{ // lObjPasswordBox.KeyDown += new KeyEventHandler(Element_KeyDown); //} foreach (Grid lObjGrid in pObjStackPanel.GetChildren().OfType <Grid>()) { lObjGrid.InitializeEvents(); } foreach (StackPanel lObjStackPanel in pObjStackPanel.GetChildren().OfType <StackPanel>()) { lObjStackPanel.InitializeEvents(); } }
public static void DisableControl(this StackPanel pObjStackPanel) { foreach (TextBox lObjTextBox in pObjStackPanel.GetChildren().OfType <TextBox>()) { lObjTextBox.IsEnabled = false; } foreach (PasswordBox lObjPasswordBox in pObjStackPanel.GetChildren().OfType <PasswordBox>()) { lObjPasswordBox.IsEnabled = false; } foreach (CheckBox lObjCheckBox in pObjStackPanel.GetChildren().OfType <CheckBox>()) { lObjCheckBox.IsEnabled = false; } foreach (Button lObjButton in pObjStackPanel.GetChildren().OfType <Button>()) { lObjButton.IsEnabled = false; } foreach (Grid lObjGrid in pObjStackPanel.GetChildren().OfType <Grid>()) { lObjGrid.DisableControl(); } foreach (StackPanel lObjStackPanel in pObjStackPanel.GetChildren().OfType <StackPanel>()) { lObjStackPanel.DisableControl(); } }
public static bool Valid(this StackPanel pObjStackPanel) { bool lBolResult = true; foreach (TextBox lObjTextBox in pObjStackPanel.GetChildren().OfType <TextBox>()) { if (!lObjTextBox.ValidRequired()) { lBolResult = false; } } foreach (ComboBox lObjComboBox in pObjStackPanel.GetChildren().OfType <ComboBox>()) { if (!lObjComboBox.ValidRequired()) { lBolResult = false; } } foreach (PasswordBox lObjPasswordBox in pObjStackPanel.GetChildren().OfType <PasswordBox>()) { if (!lObjPasswordBox.ValidRequired()) { lBolResult = false; } } foreach (Grid lObjGrid in pObjStackPanel.GetChildren().OfType <Grid>()) { lObjGrid.Valid(); } foreach (StackPanel lObjStackPanel in pObjStackPanel.GetChildren().OfType <StackPanel>()) { lObjStackPanel.Valid(); } return(lBolResult); }
public static void ClearControl(this StackPanel pObjStackPanel) { foreach (TextBox lObjTextBox in pObjStackPanel.GetChildren().OfType <TextBox>()) { lObjTextBox.ClearControl(); } foreach (PasswordBox lObjPasswordBox in pObjStackPanel.GetChildren().OfType <PasswordBox>()) { lObjPasswordBox.ClearControl(); } foreach (Grid lObjGrid in pObjStackPanel.GetChildren().OfType <Grid>()) { lObjGrid.ClearControl(); } foreach (StackPanel lObjStackPanel in pObjStackPanel.GetChildren().OfType <StackPanel>()) { lObjStackPanel.ClearControl(); } }
public void When_Vertical_And_Fixed_Height_Item_With_Margin() { var SUT = new StackPanel() { Name = "test", Orientation = Orientation.Vertical }; var c1 = SUT.AddChild( new View { Name = "Child01", RequestedDesiredSize = new Windows.Foundation.Size(10, 10), } ); var c2 = SUT.AddChild( new View { Name = "Child02", DesiredSizeSelector = s => { Assert.AreEqual(new Windows.Foundation.Size(20, 10), s); return(new Windows.Foundation.Size(10, 10)); }, Height = 10, Margin = new Thickness(10) } ); SUT.Measure(new Windows.Foundation.Size(40, float.PositiveInfinity)); var measuredSize = SUT.DesiredSize; Assert.AreEqual(new Windows.Foundation.Size(30, 40), measuredSize, "measuredSize"); Assert.AreEqual(new Windows.Foundation.Size(10, 10), c1.DesiredSize); Assert.AreEqual(new Windows.Foundation.Size(30, 30), c2.DesiredSize); SUT.Arrange(new Windows.Foundation.Rect(0, 0, 30, 40)); Assert.AreEqual(new Windows.Foundation.Rect(0, 0, 30, 10), c1.Arranged); Assert.AreEqual(new Windows.Foundation.Rect(10, 20, 10, 10), c2.Arranged); Assert.AreEqual(2, SUT.GetChildren().Count()); }
public void When_Vertical_And_Fixed_Height_Item_With_Margin() { var SUT = new StackPanel { Name = "test", Orientation = Orientation.Vertical }; var c1 = SUT.AddChild( child: new View { Name = "Child01", RequestedDesiredSize = new Size(width: 10, height: 10), } ); var c2 = SUT.AddChild( child: new View { Name = "Child02", Height = 10, Margin = new Thickness(uniformLength: 10) } ); SUT.Measure(availableSize: new Size(width: 40, height: float.PositiveInfinity)); using (new AssertionScope("Desired Sizes")) { SUT.DesiredSize.Should().Be(new Size(20, 40)); c1.DesiredSize.Should().Be(new Size(10, 10)); c2.DesiredSize.Should().Be(new Size(20, 30)); } SUT.Arrange(finalRect: new Rect(x: 0, y: 0, width: 30, height: 40)); using (new AssertionScope("Arranged Sizes")) { SUT.Arranged.Should().Be((Rect)"0,0,30,40"); c1.Arranged.Should().Be((Rect)"0,0,30,10"); c2.Arranged.Should().Be((Rect)"10,20,10,10"); SUT.GetChildren().Should().HaveCount(2); } }
public void When_Horizontal_And_Three_With_Spacing() { var SUT = new StackPanel() { Name = "test", Orientation = Orientation.Horizontal, Spacing = 5 }; var c1 = SUT.AddChild( new View { Name = "Child01", RequestedDesiredSize = new Windows.Foundation.Size(5, 8) } ); var c2 = SUT.AddChild( new View { Name = "Child02", RequestedDesiredSize = new Windows.Foundation.Size(12, 7) } ); var c3 = SUT.AddChild( new View { Name = "Child02", RequestedDesiredSize = new Windows.Foundation.Size(12, 5) } ); SUT.Measure(new Windows.Foundation.Size(20, 20)); var measuredSize = SUT.DesiredSize; Assert.AreEqual(new Windows.Foundation.Size(39, 8), measuredSize, "measuredSize"); Assert.AreEqual(new Windows.Foundation.Size(5, 8), c1.RequestedDesiredSize); Assert.AreEqual(new Windows.Foundation.Size(12, 7), c2.RequestedDesiredSize); Assert.AreEqual(new Windows.Foundation.Size(12, 5), c3.RequestedDesiredSize); SUT.Arrange(new Windows.Foundation.Rect(0, 0, 20, 20)); Assert.AreEqual(new Windows.Foundation.Rect(0, 0, 5, 20), c1.Arranged); Assert.AreEqual(new Windows.Foundation.Rect(10, 0, 12, 20), c2.Arranged); Assert.AreEqual(new Windows.Foundation.Rect(27, 0, 12, 20), c3.Arranged); Assert.AreEqual(3, SUT.GetChildren().Count()); }
public void When_Horizontal_And_ArrangeIsBiggerThanMeasure() { var SUT = new StackPanel { Name = "test", Orientation = Orientation.Horizontal }; var c1 = SUT.AddChild( child: new View { Name = "Child01", RequestedDesiredSize = new Size(width: 10, height: 10) } ); SUT.Measure(availableSize: new Size(width: 20, height: 20)); var measuredSize = SUT.DesiredSize; Assert.AreEqual(expected: new Size(width: 10, height: 10), actual: measuredSize, message: "measuredSize"); SUT.Arrange(finalRect: new Rect(x: 0, y: 0, width: 20, height: 20)); Assert.AreEqual(expected: new Rect(x: 0, y: 0, width: 10, height: 20), actual: c1.Arranged); Assert.AreEqual(expected: 1, actual: SUT.GetChildren().Count()); }
public void When_Horizontal_And_Three_With_Spacing() { var SUT = new StackPanel { Name = "test", Orientation = Orientation.Horizontal, Spacing = 5 }; var c1 = SUT .AddChild( child: new View { Name = "Child01", RequestedDesiredSize = new Size(width: 5, height: 8) } ); var c2 = SUT .AddChild( child: new View { Name = "Child02", RequestedDesiredSize = new Size(width: 12, height: 7) } ); var c3 = SUT .AddChild( child: new View { Name = "Child02", RequestedDesiredSize = new Size(width: 12, height: 5) } ); SUT.Measure(availableSize: new Size(width: 20, height: 20)); SUT.DesiredSize.Should().Be(new Size(20, 8)); SUT.UnclippedDesiredSize.Should().Be(new Size(39, 8)); SUT.Arrange(finalRect: new Rect(x: 0, y: 0, width: 20, height: 20)); Assert.AreEqual(expected: new Rect(x: 0, y: 0, width: 5, height: 20), actual: c1.Arranged); Assert.AreEqual(expected: new Rect(x: 10, y: 0, width: 12, height: 20), actual: c2.Arranged); Assert.AreEqual(expected: new Rect(x: 27, y: 0, width: 12, height: 20), actual: c3.Arranged); Assert.AreEqual(expected: 3, actual: SUT.GetChildren().Count()); }
public void When_Vertical_And_ArrangeIsBiggerThanMeasure() { var SUT = new StackPanel() { Name = "test", Orientation = Orientation.Vertical }; var c1 = SUT.AddChild( new View { Name = "Child01", RequestedDesiredSize = new Windows.Foundation.Size(10, 10) } ); SUT.Measure(new Windows.Foundation.Size(20, 20)); var measuredSize = SUT.DesiredSize; Assert.AreEqual(new Windows.Foundation.Size(10, 10), measuredSize, "measuredSize"); SUT.Arrange(new Windows.Foundation.Rect(0, 0, 20, 20)); Assert.AreEqual(new Windows.Foundation.Rect(0, 0, 20, 10), c1.Arranged); Assert.AreEqual(1, SUT.GetChildren().Count()); }