Exemplo n.º 1
0
        void UpdateGrid()
        {
            if (_grid == null)
            {
                return;
            }

            _grid.ColumnDefinitions.Clear();
            _grid.RowDefinitions.Clear();

            if (_converter == null)
            {
                _converter = new LayoutOptionsToLengthConverter();
            }

            if (_orientation == Orientation.Vertical)
            {
                for (int i = 0; i < ItemsControl.Items.Count; i++)
                {
                    var element = _grid.Children.OfType <UIElement>().Skip(i).First();
                    WPFGrid.SetRow(element, i);
                    WPFGrid.SetColumn(element, 0);

                    var row = new WPFRowDefinition {
                        Height = new WPFGridLength(0, WPFGridUnitType.Auto)
                    };
                    _grid.RowDefinitions.Add(row);
                    var binding = new System.Windows.Data.Binding(View.VerticalOptionsProperty.PropertyName)
                    {
                        Source    = ItemsSource.Skip(i).FirstOrDefault(),
                        Converter = _converter
                    };
                    row.SetBinding(WPFRowDefinition.HeightProperty, binding);
                }
            }
            else
            {
                for (int i = 0; i < ItemsControl.Items.Count; i++)
                {
                    var element = _grid.Children.OfType <UIElement>().Skip(i).First();
                    WPFGrid.SetRow(element, 0);
                    WPFGrid.SetColumn(element, i);

                    var col = new WPFColumnDefinition {
                        Width = new WPFGridLength(0, WPFGridUnitType.Auto)
                    };
                    _grid.ColumnDefinitions.Add(col);
                    var binding = new System.Windows.Data.Binding(View.HorizontalOptionsProperty.PropertyName)
                    {
                        Source    = ItemsSource.Skip(i).FirstOrDefault(),
                        Converter = _converter
                    };
                    col.SetBinding(WPFColumnDefinition.WidthProperty, binding);
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Updates the rows.
        /// </summary>
        /// <param name="rows">The number rows.</param>
        private void UpdateRows(int rows)
        {
            this.rowGrid.Children.Add(this.rowSelectionBackground);

            for (var i = 0; i < rows; i++)
            {
                var sheetDefinition = new System.Windows.Controls.RowDefinition { Height = this.GetRowHeight(i) };
                this.sheetGrid.RowDefinitions.Add(sheetDefinition);

                var rowDefinition = new System.Windows.Controls.RowDefinition();
                rowDefinition.SetBinding(System.Windows.Controls.RowDefinition.HeightProperty, new Binding { Source = sheetDefinition, Path = new PropertyPath("Height"), Mode = BindingMode.TwoWay });
                this.rowGrid.RowDefinitions.Add(rowDefinition);
            }

            for (var i = 0; i < rows; i++)
            {
                var header = this.GetRowHeader(i);

                var border = new Border
                {
                    BorderBrush = this.HeaderBorderBrush,
                    BorderThickness = new Thickness(1, 0, 1, 1),
                    Margin = new Thickness(0, 0, 0, -1)
                };

                Grid.SetRow(border, i);
                this.rowGrid.Children.Add(border);

                var cell = header as FrameworkElement
                           ??
                           new TextBlock
                           {
                               Text = header?.ToString() ?? "-",
                               VerticalAlignment = VerticalAlignment.Center,
                               HorizontalAlignment = System.Windows.HorizontalAlignment.Center,
                               Padding = new Thickness(4, 2, 4, 2)
                           };

                if (this.ItemHeaderPropertyPath != null && this.ItemsInRows)
                {
                    cell.DataContext = this.Operator.GetItem(this, new CellRef(i, -1));
                    cell.SetBinding(TextBlock.TextProperty, new Binding(this.ItemHeaderPropertyPath));
                }

                if (this.RowHeadersSource != null && this.ItemsInRows)
                {
                    cell.DataContext = this.RowHeadersSource;
                    cell.SetBinding(
                        TextBlock.TextProperty,
                        new Binding($"[{i}]") { StringFormat = this.RowHeadersFormatString });
                }

                Grid.SetRow(cell, i);
                this.rowGrid.Children.Add(cell);
                this.rowHeaderMap[i] = cell;
            }

            // Add "Insert" row header
            this.AddInserterRow(rows);

            // set the context menu
            this.rowGrid.ContextMenu = this.RowsContextMenu;

            // to cover a possible scrollbar
            this.rowGrid.RowDefinitions.Add(new System.Windows.Controls.RowDefinition { Height = new GridLength(20) });

            for (var j = 0; j < rows; j++)
            {
                if (this.CanResizeRows)
                {
                    var splitter = new GridSplitter
                    {
                        ResizeDirection = GridResizeDirection.Rows,
                        Background = Brushes.Transparent,
                        Height = 5,
                        RenderTransform = new TranslateTransform(0, 3),
                        Focusable = false,
                        VerticalAlignment = VerticalAlignment.Bottom,
                        HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch
                    };
                    splitter.MouseDoubleClick += this.RowSplitterDoubleClick;
                    splitter.DragStarted += this.RowSplitterChangeStarted;
                    splitter.DragDelta += this.RowSplitterChangeDelta;
                    splitter.DragCompleted += this.RowSplitterChangeCompleted;
                    Grid.SetRow(splitter, j);
                    this.rowGrid.Children.Add(splitter);
                }
            }
        }
        void UpdateGrid()
        {
            if (_grid == null)
                return;

            _grid.ColumnDefinitions.Clear();
            _grid.RowDefinitions.Clear();

            if (_converter == null)
                _converter = new LayoutOptionsToLengthConverter();

            if (_orientation == Orientation.Vertical)
            {
                for (int i = 0; i < ItemsControl.Items.Count; i++)
                {
                    var element = _grid.Children.OfType<UIElement>().Skip(i).First();
                    WPFGrid.SetRow(element, i);
                    WPFGrid.SetColumn(element, 0);

                    var row = new WPFRowDefinition { Height = new WPFGridLength(0, WPFGridUnitType.Auto) };
                    _grid.RowDefinitions.Add(row);
                    var binding = new System.Windows.Data.Binding(View.VerticalOptionsProperty.PropertyName)
                    {
                        Source = ItemsSource.Skip(i).FirstOrDefault(),
                        Converter = _converter
                    };
                    row.SetBinding(WPFRowDefinition.HeightProperty, binding);
                }
            }
            else
            {
                for (int i = 0; i < ItemsControl.Items.Count; i++)
                {
                    var element = _grid.Children.OfType<UIElement>().Skip(i).First();
                    WPFGrid.SetRow(element, 0);
                    WPFGrid.SetColumn(element, i);

                    var col = new WPFColumnDefinition { Width = new WPFGridLength(0, WPFGridUnitType.Auto) };
                    _grid.ColumnDefinitions.Add(col);
                    var binding = new System.Windows.Data.Binding(View.HorizontalOptionsProperty.PropertyName)
                    {
                        Source = ItemsSource.Skip(i).FirstOrDefault(),
                        Converter = _converter
                    };
                    col.SetBinding(WPFColumnDefinition.WidthProperty, binding);
                }
            }
        }