Esempio n. 1
0
        public void TemplateOrientation()
        {
            Grid         g        = GridSplitterTest.CreateGrid(2, 2, 100.0, 100.0);
            GridSplitter splitter = GridSplitterTest.CreateGridSplitterThroughCode(1, 1, 1, 1, 10.0, 10.0, VerticalAlignment.Stretch, HorizontalAlignment.Left, new SolidColorBrush(Colors.Green), true);

            g.Children.Add(splitter);

            this.CreateAsyncTest(g,
                                 () => splitter.DragValidator_DragStartedEvent(splitter, new DragStartedEventArgs(0.0, 0.0)),
                                 delegate
            {
                Assert.AreEqual(Visibility.Collapsed, splitter._resizeData.PreviewControl._elementHorizontalTemplateFrameworkElement.Visibility);
                Assert.AreEqual(Visibility.Visible, splitter._resizeData.PreviewControl._elementVerticalTemplateFrameworkElement.Visibility);
            },
                                 () => splitter.DragValidator_DragDeltaEvent(splitter, new DragDeltaEventArgs(5.0, 6.0)),
                                 () => splitter.DragValidator_DragCompletedEvent(splitter, new DragCompletedEventArgs(5.0, 6.0, false)),
                                 () => splitter.HorizontalAlignment = HorizontalAlignment.Stretch,
                                 () => splitter.VerticalAlignment   = VerticalAlignment.Top,
                                 () => splitter.DragValidator_DragStartedEvent(splitter, new DragStartedEventArgs(0.0, 0.0)),
                                 delegate
            {
                Assert.AreEqual(Visibility.Visible, splitter._resizeData.PreviewControl._elementHorizontalTemplateFrameworkElement.Visibility);
                Assert.AreEqual(Visibility.Collapsed, splitter._resizeData.PreviewControl._elementVerticalTemplateFrameworkElement.Visibility);
            });
        }
Esempio n. 2
0
        public void MouseStartResizeColumns()
        {
            Grid         g        = CreateGrid(2, 2, 100.0, 100.0);
            GridSplitter splitter = CreateGridSplitterThroughCode(1, 2, 5.0, HorizontalAlignment.Left, null, false);

            g.Children.Add(splitter);
            this.CreateAsyncTest(g,
                                 () => splitter.DragValidator_DragStartedEvent(splitter, new DragStartedEventArgs(0.0, 0.0)),
                                 delegate
            {
                Assert.IsNotNull(splitter._resizeData.Definition1.AsColumnDefinition, "Definition1 should be a column.");
                Assert.AreEqual(g.ColumnDefinitions[0], splitter._resizeData.Definition1.AsColumnDefinition, "Definition1 should be the first column.");
                Assert.AreEqual(0, splitter._resizeData.Definition1Index, "Definition1 should be the first column.");
                Assert.IsNotNull(splitter._resizeData.Definition2.AsColumnDefinition, "Definition2 should be a column.");
                Assert.AreEqual(g.ColumnDefinitions[1], splitter._resizeData.Definition2.AsColumnDefinition, "Definition1 should be the second column.");
                Assert.AreEqual(1, splitter._resizeData.Definition2Index, "Definition2 should be the second column.");
                Assert.AreEqual(g, splitter._resizeData.Grid, "Grid should be the parent grid.");
                Assert.AreEqual(0.0, splitter._resizeData.MaxChange, "MaxChange should be zero since ShowsPreview is false");
                Assert.AreEqual(0.0, splitter._resizeData.MinChange, "MinChange should be zero since ShowsPreivew is false.");
                Assert.AreEqual(new GridLength(1.0, GridUnitType.Star), splitter._resizeData.OriginalDefinition1Length, "OriginalDefinition1Length should be the original default width.");
                Assert.AreEqual(new GridLength(1.0, GridUnitType.Star), splitter._resizeData.OriginalDefinition2Length, "OriginalDefinition2Length should be the original default width.");
                Assert.IsNull(splitter._resizeData.PreviewControl, "No PreviewControl should be set.");
                Assert.AreEqual(GridSplitter.GridResizeBehavior.PreviousAndCurrent, splitter._resizeData.ResizeBehavior, "ResizeBehavior should be previous and current.");
                Assert.AreEqual(GridSplitter.GridResizeDirection.Columns, splitter._resizeData.ResizeDirection, "ResizeDirection should be Columns.");
                Assert.IsFalse(splitter._resizeData.ShowsPreview, "ShowsPreview should be false.");
                Assert.AreEqual(GridSplitter.SplitBehavior.Split, splitter._resizeData.SplitBehavior, "SplitBehavior should be Split since both definitions have * grid lengths.");
                Assert.AreEqual(1, splitter._resizeData.SplitterIndex, "Splitter should be in the second column.");
                Assert.AreEqual(5.0, splitter._resizeData.SplitterLength, "SplitterLength should be the width of the splitter.");
            });
        }
Esempio n. 3
0
        public void ApplyPreviewStyle()
        {
            Grid         g        = GridSplitterTest.CreateGrid(2, 2, 100, 100);
            GridSplitter splitter = GridSplitterTest.CreateGridSplitterThroughCode(1, 1, 1, null, null, 10.0, null, HorizontalAlignment.Left, new SolidColorBrush(Colors.Cyan), true);

            splitter.PreviewStyle = XamlReader.Load(Resource.GridSplitter_PreviewStyle) as Style;
            g.Children.Add(splitter);

            TestPanel.Children.Add(g);

            // Wait until the splitter style got applied
            DateTime timeout = DateTime.Now.AddMilliseconds(StyleApplicationTimeout);

            EnqueueConditional(() => (splitter.Template != null) || (DateTime.Now > timeout));

            EnqueueCallback(() => splitter.DragValidator_DragStartedEvent(splitter, new DragStartedEventArgs(0.0, 0.0)));

            // Give time for the preview style to get applied (if required)
            timeout = DateTime.Now.AddMilliseconds(StyleApplicationTimeout);
            EnqueueConditional(() => (splitter._resizeData.PreviewControl.Template != null) || (DateTime.Now > timeout));

            EnqueueCallback(delegate
            {
                Assert.IsNotNull(splitter._resizeData.PreviewControl.Template, "The template should have been set if the style was applied.");
            });

            EnqueueCallback(() => TestPanel.Children.Remove(g));
            EnqueueTestComplete();
        }
Esempio n. 4
0
        public void GridSplitterTest()
        {
            Grid grid = new Grid();

            grid.Height = 100.0;
            grid.Width  = 100.0;
            grid.RowDefinitions.Add(new RowDefinition());
            grid.RowDefinitions.Add(new RowDefinition());
            grid.ColumnDefinitions.Add(new ColumnDefinition());
            grid.ColumnDefinitions.Add(new ColumnDefinition());

            GridSplitter splitter = new GridSplitter();

            splitter.SetValue(Grid.ColumnProperty, 1);
            splitter.SetValue(Grid.RowSpanProperty, 2);
            splitter.Width               = 5.0;
            splitter.ShowsPreview        = true;
            splitter.HorizontalAlignment = HorizontalAlignment.Left;

            grid.Children.Add(splitter);
            this.CreateAsyncTest(grid,
                                 () => splitter.DragValidator_DragStartedEvent(splitter, new DragStartedEventArgs(0.0, 0.0)),
                                 () => splitter.DragValidator_DragDeltaEvent(splitter, new DragDeltaEventArgs(5.0, 6.0)),
                                 () => splitter.DragValidator_DragCompletedEvent(splitter, new DragCompletedEventArgs(5.0, 6.0, false)),
                                 delegate
            {
                Assert.IsNull(splitter._resizeData, "The stored ResizeData instance should be gone since the resize operation is over.");
                Assert.AreEqual(55.0, grid.ColumnDefinitions[0].ActualWidth, "The first column should have had the new width committed.");
                Assert.AreEqual(45.0, grid.ColumnDefinitions[1].ActualWidth, "The second column should have had the new width committed.");
            });
        }
Esempio n. 5
0
        public void MouseCompleteResizeColumns()
        {
            Grid         g        = CreateGrid(2, 2, 100.0, 100.0);
            GridSplitter splitter = CreateGridSplitterThroughCode(1, 2, 5.0, HorizontalAlignment.Left, null, false);

            g.Children.Add(splitter);
            this.CreateAsyncTest(g,
                                 () => splitter.DragValidator_DragStartedEvent(splitter, new DragStartedEventArgs(0.0, 0.0)),
                                 () => splitter.DragValidator_DragDeltaEvent(splitter, new DragDeltaEventArgs(5.0, 6.0)),
                                 () => splitter.DragValidator_DragCompletedEvent(splitter, new DragCompletedEventArgs(5.0, 6.0, false)),
                                 delegate
            {
                Assert.IsNull(splitter._resizeData, "The stored ResizeData instance should be gone since the resize operation is over.");
                Assert.AreEqual(55.0, g.ColumnDefinitions[0].ActualWidth, "The first column should have had the new width committed.");
                Assert.AreEqual(45.0, g.ColumnDefinitions[1].ActualWidth, "The second column should have had the new width committed.");
            });
        }
Esempio n. 6
0
        public void MouseResizeColumns()
        {
            Grid         g        = CreateGrid(2, 2, 100.0, 100.0);
            GridSplitter splitter = CreateGridSplitterThroughCode(1, 2, 5.0, HorizontalAlignment.Left, null, false);

            g.Children.Add(splitter);
            this.CreateAsyncTest(g,
                                 () => splitter.DragValidator_DragStartedEvent(splitter, new DragStartedEventArgs(0.0, 0.0)),
                                 () => splitter.DragValidator_DragDeltaEvent(splitter, new DragDeltaEventArgs(5.0, 6.0)),
                                 delegate
            {
                Assert.IsNotNull(splitter._resizeData.Definition1.AsColumnDefinition, "Definition1 should be a column.");
                Assert.AreEqual(55.0, splitter._resizeData.Definition1.AsColumnDefinition.ActualWidth, "Definition1 should have increased by the drag delta amount.");
                Assert.IsNotNull(splitter._resizeData.Definition2.AsColumnDefinition, "Definition2 should be a column.");
                Assert.AreEqual(45.0, splitter._resizeData.Definition2.AsColumnDefinition.ActualWidth, "Definition2 should have decreased by the drag delta amount.");
            });
        }
Esempio n. 7
0
        public void VariableNumbersOfColumnsAndRows()
        {
            // Check the cases where a vertical GridSplitter is used in a Grid with 0,1, and n columns
            // and when a horizontal GridSplitter is used in a Grid with 0,1, and n rows.
            bool         result;
            Grid         g        = CreateGrid(2, 0, 100.0, 100.0);
            GridSplitter splitter = CreateGridSplitterThroughCode(1, 0, null, null, null, null, VerticalAlignment.Top, HorizontalAlignment.Stretch, null, true);

            g.Children.Add(splitter);
            this.CreateAsyncTest(g,
                                 delegate
            {
                result = GridSplitter.DoubleUtil.AreClose(g.RowDefinitions[0].ActualHeight, 50.0);
                Assert.IsTrue(result, "ActualHeight should be same as the desired height.");
            },
                                 () => splitter.DragValidator_DragStartedEvent(splitter, new DragStartedEventArgs(0.0, 0.0)),
                                 () => splitter.DragValidator_DragDeltaEvent(splitter, new DragDeltaEventArgs(0.0, 10.0)),
                                 () => splitter.DragValidator_DragCompletedEvent(splitter, new DragCompletedEventArgs(0.0, 0.0, false)),
                                 delegate
            {
                result = GridSplitter.DoubleUtil.AreClose(g.RowDefinitions[0].ActualHeight, 60.0);
                Assert.IsTrue(result, "ActualHeight should be same as the desired height.");
            },
                                 () => g.ColumnDefinitions.Add(new ColumnDefinition()),
                                 () => splitter.DragValidator_DragStartedEvent(splitter, new DragStartedEventArgs(0.0, 0.0)),
                                 () => splitter.DragValidator_DragDeltaEvent(splitter, new DragDeltaEventArgs(0.0, -15.0)),
                                 () => splitter.DragValidator_DragCompletedEvent(splitter, new DragCompletedEventArgs(0.0, 0.0, false)),
                                 delegate
            {
                result = GridSplitter.DoubleUtil.AreClose(g.RowDefinitions[0].ActualHeight, 45.0);
                Assert.IsTrue(result, "ActualHeight should be same as the desired height.");
            },
                                 () => g.ColumnDefinitions.Add(new ColumnDefinition()),
                                 () => splitter.DragValidator_DragStartedEvent(splitter, new DragStartedEventArgs(0.0, 0.0)),
                                 () => splitter.DragValidator_DragDeltaEvent(splitter, new DragDeltaEventArgs(0.0, 25.0)),
                                 () => splitter.DragValidator_DragCompletedEvent(splitter, new DragCompletedEventArgs(0.0, 0.0, false)),
                                 delegate
            {
                result = GridSplitter.DoubleUtil.AreClose(g.RowDefinitions[0].ActualHeight, 70.0);
                Assert.IsTrue(result, "ActualHeight should be same as the desired height.");
            },
                                 () => g.RowDefinitions.Clear(),
                                 () => splitter.VerticalAlignment   = VerticalAlignment.Stretch,
                                 () => splitter.HorizontalAlignment = HorizontalAlignment.Left,
                                 () => splitter.SetValue(Grid.RowProperty, 0),
                                 () => splitter.SetValue(Grid.ColumnProperty, 1),
                                 delegate
            {
                result = GridSplitter.DoubleUtil.AreClose(g.ColumnDefinitions[0].ActualWidth, 50.0);
                Assert.IsTrue(result, "ActualWidth should be same as the desired width.");
            },
                                 () => splitter.DragValidator_DragStartedEvent(splitter, new DragStartedEventArgs(0.0, 0.0)),
                                 () => splitter.DragValidator_DragDeltaEvent(splitter, new DragDeltaEventArgs(10.0, 0.0)),
                                 () => splitter.DragValidator_DragCompletedEvent(splitter, new DragCompletedEventArgs(0.0, 0.0, false)),
                                 delegate
            {
                result = GridSplitter.DoubleUtil.AreClose(g.ColumnDefinitions[0].ActualWidth, 60.0);
                Assert.IsTrue(result, "ActualWidth should be same as the desired width.");
            },
                                 () => g.RowDefinitions.Add(new RowDefinition()),
                                 () => splitter.DragValidator_DragStartedEvent(splitter, new DragStartedEventArgs(0.0, 0.0)),
                                 () => splitter.DragValidator_DragDeltaEvent(splitter, new DragDeltaEventArgs(-15.0, 0.0)),
                                 () => splitter.DragValidator_DragCompletedEvent(splitter, new DragCompletedEventArgs(0.0, 0.0, false)),
                                 delegate
            {
                result = GridSplitter.DoubleUtil.AreClose(g.ColumnDefinitions[0].ActualWidth, 45.0);
                Assert.IsTrue(result, "ActualWidth should be same as the desired width.");
            },
                                 () => g.RowDefinitions.Add(new RowDefinition()),
                                 () => splitter.DragValidator_DragStartedEvent(splitter, new DragStartedEventArgs(0.0, 0.0)),
                                 () => splitter.DragValidator_DragDeltaEvent(splitter, new DragDeltaEventArgs(25.0, 0.0)),
                                 () => splitter.DragValidator_DragCompletedEvent(splitter, new DragCompletedEventArgs(0.0, 0.0, false)),
                                 delegate
            {
                result = GridSplitter.DoubleUtil.AreClose(g.ColumnDefinitions[0].ActualWidth, 70.0);
                Assert.IsTrue(result, "ActualWidth should be same as the desired width.");
            });
        }
Esempio n. 8
0
        public void GridSplitterTest()
        {
            Grid grid = new Grid();
            grid.Height = 100.0;
            grid.Width = 100.0;
            grid.RowDefinitions.Add(new RowDefinition());
            grid.RowDefinitions.Add(new RowDefinition());
            grid.ColumnDefinitions.Add(new ColumnDefinition());
            grid.ColumnDefinitions.Add(new ColumnDefinition());

            GridSplitter splitter = new GridSplitter();
            splitter.SetValue(Grid.ColumnProperty, 1);
            splitter.SetValue(Grid.RowSpanProperty, 2);
            splitter.Width = 5.0;
            splitter.ShowsPreview = true;
            splitter.HorizontalAlignment = HorizontalAlignment.Left;

            grid.Children.Add(splitter);
            this.CreateAsyncTest(grid,
                () => splitter.DragValidator_DragStartedEvent(splitter, new DragStartedEventArgs(0.0, 0.0)),
                () => splitter.DragValidator_DragDeltaEvent(splitter, new DragDeltaEventArgs(5.0, 6.0)),
                () => splitter.DragValidator_DragCompletedEvent(splitter, new DragCompletedEventArgs(5.0, 6.0, false)),
                delegate
                {
                    Assert.IsNull(splitter._resizeData, "The stored ResizeData instance should be gone since the resize operation is over.");
                    Assert.AreEqual(55.0, grid.ColumnDefinitions[0].ActualWidth, "The first column should have had the new width committed.");
                    Assert.AreEqual(45.0, grid.ColumnDefinitions[1].ActualWidth, "The second column should have had the new width committed.");
                });
        }