예제 #1
0
        public void Calculates_Colspan_Correctly()
        {
            var target = new Grid
            {
                ColumnDefinitions = new ColumnDefinitions
                {
                    new ColumnDefinition(GridLength.Auto),
                    new ColumnDefinition(new GridLength(4, GridUnitType.Pixel)),
                    new ColumnDefinition(GridLength.Auto),
                },
                RowDefinitions = new RowDefinitions
                {
                    new RowDefinition(GridLength.Auto),
                    new RowDefinition(GridLength.Auto),
                },
                Children = new Controls
                {
                    new Border
                    {
                        Width = 100,
                        Height = 25,
                        [Grid.ColumnSpanProperty] = 3,
                    },
                    new Border
                    {
                        Width = 150,
                        Height = 25,
                        [Grid.RowProperty] = 1,
                    },
                    new Border
                    {
                        Width = 50,
                        Height = 25,
                        [Grid.RowProperty] = 1,
                        [Grid.ColumnProperty] = 2,
                    }
                },
            };

            target.Measure(Size.Infinity);

            // Issue #25 only appears after a second measure
            target.InvalidateMeasure();
            target.Measure(Size.Infinity);

            target.Arrange(new Rect(target.DesiredSize));

            Assert.Equal(new Size(204, 50), target.Bounds.Size);
            Assert.Equal(150d, target.ColumnDefinitions[0].ActualWidth);
            Assert.Equal(4d, target.ColumnDefinitions[1].ActualWidth);
            Assert.Equal(50d, target.ColumnDefinitions[2].ActualWidth);
            Assert.Equal(new Rect(52, 0, 100, 25), target.Children[0].Bounds);
            Assert.Equal(new Rect(0, 25, 150, 25), target.Children[1].Bounds);
            Assert.Equal(new Rect(154, 25, 50, 25), target.Children[2].Bounds);
        }
예제 #2
0
        private Control Template(ScrollViewer control)
        {
            var result = new Grid
            {
                ColumnDefinitions = new ColumnDefinitions
                {
                    new ColumnDefinition(1, GridUnitType.Star),
                    new ColumnDefinition(GridLength.Auto),
                },
                RowDefinitions = new RowDefinitions
                {
                    new RowDefinition(1, GridUnitType.Star),
                    new RowDefinition(GridLength.Auto),
                },
                Children = new Controls
                {
                    new ScrollContentPresenter
                    {
                        Name = "contentPresenter",
                        [~ScrollContentPresenter.ContentProperty] = control[~ScrollViewer.ContentProperty],
                        [~~ScrollContentPresenter.ExtentProperty] = control[~~ScrollViewer.ExtentProperty],
                        [~~ScrollContentPresenter.OffsetProperty] = control[~~ScrollViewer.OffsetProperty],
                        [~~ScrollContentPresenter.ViewportProperty] = control[~~ScrollViewer.ViewportProperty],
                        [~ScrollContentPresenter.CanScrollHorizontallyProperty] = control[~ScrollViewer.CanScrollHorizontallyProperty],
                    },
                    new ScrollBar
                    {
                        Name = "horizontalScrollBar",
                        Orientation = Orientation.Horizontal,
                        [~ScrollBar.MaximumProperty] = control[~ScrollViewer.HorizontalScrollBarMaximumProperty],
                        [~~ScrollBar.ValueProperty] = control[~~ScrollViewer.HorizontalScrollBarValueProperty],
                        [~ScrollBar.ViewportSizeProperty] = control[~ScrollViewer.HorizontalScrollBarViewportSizeProperty],
                        [~ScrollBar.VisibilityProperty] = control[~ScrollViewer.HorizontalScrollBarVisibilityProperty],
                        [Grid.RowProperty] = 1,
                    },
                    new ScrollBar
                    {
                        Name = "verticalScrollBar",
                        Orientation = Orientation.Vertical,
                        [~ScrollBar.MaximumProperty] = control[~ScrollViewer.VerticalScrollBarMaximumProperty],
                        [~~ScrollBar.ValueProperty] = control[~~ScrollViewer.VerticalScrollBarValueProperty],
                        [~ScrollBar.ViewportSizeProperty] = control[~ScrollViewer.VerticalScrollBarViewportSizeProperty],
                        [~ScrollBar.VisibilityProperty] = control[~ScrollViewer.VerticalScrollBarVisibilityProperty],
                        [Grid.ColumnProperty] = 1,
                    },
                },
            };

            return result;
        }
예제 #3
0
        private void InitializeComponent()
        {
            TreeView tree;

            Content = new Grid
            {
                ColumnDefinitions = new ColumnDefinitions
                {
                    new ColumnDefinition(1, GridUnitType.Star),
                    new ColumnDefinition(4, GridUnitType.Pixel),
                    new ColumnDefinition(3, GridUnitType.Star),
                },
                Children = new Controls
                {
                    (tree = new TreeView
                    {
                        DataTemplates = new DataTemplates
                        {
                            new FuncTreeDataTemplate<VisualTreeNode>(GetHeader, x => x.Children),
                        },
                        [!ItemsControl.ItemsProperty] = this.WhenAnyValue(x => x.ViewModel.Nodes),
                    }),
                    new GridSplitter
                    {
                        Width = 4,
                        Orientation = Orientation.Vertical,
                        [Grid.ColumnProperty] = 1,
                    },
                    new ContentControl
                    {
                        [!ContentProperty] = this.WhenAnyValue(x => x.ViewModel.Details),
                        [Grid.ColumnProperty] = 2,
                    }
                }
            };

            tree.GetObservable(TreeView.SelectedItemProperty)
                .OfType<VisualTreeNode>()
                .Subscribe(x => ViewModel.SelectedNode = x);
        }
예제 #4
0
파일: Grid.cs 프로젝트: KvanTTT/Perspex
            public GridWalker(Grid grid, Segment[,] rowMatrix, Segment[,] colMatrix)
            {
                int rowMatrixDim = rowMatrix.GetLength(0);
                int colMatrixDim = colMatrix.GetLength(0);

                foreach (Control child in grid.Children)
                {
                    bool starCol = false;
                    bool starRow = false;
                    bool autoCol = false;
                    bool autoRow = false;

                    int col = Math.Min(GetColumn(child), colMatrixDim - 1);
                    int row = Math.Min(GetRow(child), rowMatrixDim - 1);
                    int colspan = Math.Min(GetColumnSpan(child), colMatrixDim - 1);
                    int rowspan = Math.Min(GetRowSpan(child), rowMatrixDim - 1);

                    for (int r = row; r < row + rowspan; r++)
                    {
                        starRow |= rowMatrix[r, r].Type == GridUnitType.Star;
                        autoRow |= rowMatrix[r, r].Type == GridUnitType.Auto;
                    }

                    for (int c = col; c < col + colspan; c++)
                    {
                        starCol |= colMatrix[c, c].Type == GridUnitType.Star;
                        autoCol |= colMatrix[c, c].Type == GridUnitType.Auto;
                    }

                    HasAutoAuto |= autoRow && autoCol && !starRow && !starCol;
                    HasStarAuto |= starRow && autoCol;
                    HasAutoStar |= autoRow && starCol;
                }
            }
예제 #5
0
 protected override void OnAttachedToVisualTree(VisualTreeAttachmentEventArgs e)
 {
     base.OnAttachedToVisualTree(e);
     _grid = this.GetVisualParent<Grid>();
     
     if (Orientation == Orientation.Vertical)
     {
         Cursor = new Cursor(StandardCursorType.SizeWestEast);
         var col = GetValue(Grid.ColumnProperty);
         _definitions = _grid.ColumnDefinitions.Cast<DefinitionBase>().ToList();
         _prevDefinition = _definitions[col - 1];
         _nextDefinition = _definitions[col + 1];
     }
     else
     {
         Cursor = new Cursor(StandardCursorType.SizeNorthSouth);
         var row = GetValue(Grid.RowProperty);
         _definitions = _grid.RowDefinitions.Cast<DefinitionBase>().ToList();
         _prevDefinition = _definitions[row - 1];
         _nextDefinition = _definitions[row + 1];
     }
 }
예제 #6
0
 protected override void OnVisualParentChanged(Visual oldParent)
 {
     this.grid = this.GetVisualParent<Grid>();
 }
예제 #7
0
 protected override void OnAttachedToVisualTree(IRenderRoot root)
 {
     base.OnAttachedToVisualTree(root);
     _grid = this.GetVisualParent<Grid>();
 }
예제 #8
0
        private void InitializeComponent()
        {
            DataTemplates.Add(new ViewLocator<ReactiveObject>());

            Child = new Grid
            {
                RowDefinitions = new RowDefinitions("*,Auto"),
                Children = new Controls.Controls
                {
                    new TabControl
                    {
                        Items = new[]
                        {
                            new TabItem
                            {
                                Header = "Logical Tree",
                                [!ContentControl.ContentProperty] = _viewModel.WhenAnyValue(x => x.LogicalTree),
                            },
                            new TabItem
                            {
                                Header = "Visual Tree",
                                [!ContentControl.ContentProperty] = _viewModel.WhenAnyValue(x => x.VisualTree),
                            }
                        },
                    },
                    new StackPanel
                    {
                        Orientation = Orientation.Horizontal,
                        Gap = 4,
                        [Grid.RowProperty] = 1,
                        Children = new Controls.Controls
                        {
                            new TextBlock
                            {
                                Text = "Focused: "
                            },
                            new TextBlock
                            {
                                [!TextBlock.TextProperty] = _viewModel
                                    .WhenAnyValue(x => x.FocusedControl)
                                    .Select(x => x?.GetType().Name ?? "(null)")
                            },
                            new TextBlock
                            {
                                Text = "Pointer Over: "
                            },
                            new TextBlock
                            {
                                [!TextBlock.TextProperty] = _viewModel
                                    .WhenAnyValue(x => x.PointerOverElement)
                                    .Select(x => x?.GetType().Name ?? "(null)")
                            }
                        }
                    }
                }
            };
        }
예제 #9
0
 protected override void OnAttachedToVisualTree(VisualTreeAttachmentEventArgs e)
 {
     base.OnAttachedToVisualTree(e);
     _grid = this.GetVisualParent<Grid>();
 }