SetRow() public static method

public static SetRow ( IDependencyObject element, int value ) : void
element IDependencyObject
value int
return void
示例#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);
                }
            }
        }
示例#2
0
        void PrepareChild(ContentPresenter child, ColumnBase column)
        {
            int columnCorrectingCoef     = BandedViewBehavior.GetIsLeftColumn(column) ? 0 : 1;
            int columnSpanCorrectingCoef = BandedViewBehavior.GetIsLeftColumn(column) ? 1 : 0;

            StdGrid.SetRow(child, BandedViewBehavior.GetRow(column));
            StdGrid.SetColumn(child, BandedViewBehavior.GetColumn(column) + columnCorrectingCoef);
            StdGrid.SetRowSpan(child, BandedViewBehavior.GetRowSpan(column));
            StdGrid.SetColumnSpan(child, BandedViewBehavior.GetColumnSpan(column) + columnSpanCorrectingCoef);
        }
示例#3
0
 private static void OnCellChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
 {
     if (e.NewValue == null)
     {
         return;
     }
     if (e.NewValue is string str)
     {
         var tmpArr = str.Split(_separators, StringSplitOptions.RemoveEmptyEntries);
         if (d is FrameworkElement fe)
         {
             if (tmpArr.Length == 2)
             {
                 if (int.TryParse(tmpArr[0], out var x) && int.TryParse(tmpArr[1], out var y))
                 {
                     OriginalGrid.SetColumn(fe, x);
                     OriginalGrid.SetRow(fe, y);
                 }
                 else
                 {
                     throw new ArgumentException("Can't parse values");
                 }
             }
             else if (tmpArr.Length == 4)
             {
                 if (int.TryParse(tmpArr[0], out var column) &&
                     int.TryParse(tmpArr[1], out var row) &&
                     int.TryParse(tmpArr[2], out var columnSpan) &&
                     int.TryParse(tmpArr[3], out var rowSpan))
                 {
                     OriginalGrid.SetColumn(fe, column);
                     OriginalGrid.SetRow(fe, row);
                     OriginalGrid.SetColumnSpan(fe, columnSpan);
                     OriginalGrid.SetRowSpan(fe, rowSpan);
                 }
                 else
                 {
                     throw new ArgumentException("Can't parse values");
                 }
             }
             else
             {
                 throw new ArgumentException("Incorrect argument count for Cell value");
             }
         }
     }
 }
        private void CreateRowConstraintControls()
        {
            if (this.RowConstraints != null && RowConstraintsTemplate != null)
            {
                foreach (var index in RowConstraints.Indices)
                {
                    var rowIndex           = index + 1;
                    var rowConstraintData  = RowConstraints[index];
                    var constraintsControl = (FrameworkElement)RowConstraintsTemplate.LoadContent();

                    constraintsControl.DataContext = rowConstraintData;
                    UIGrid.SetRow(constraintsControl, rowIndex);
                    UIGrid.SetColumn(constraintsControl, 0);

                    this.grid.Children.Add(constraintsControl);
                }
            }
        }
        private void CreateSquareControls()
        {
            if (this.Grid != null && SquareTemplate != null)
            {
                foreach (var position in Grid.AllPositions)
                {
                    var gridCol       = position.X + 1;
                    var gridRow       = position.Y + 1;
                    var squareData    = Grid[position];
                    var squareControl = (FrameworkElement)SquareTemplate.LoadContent();

                    squareControl.DataContext = squareData;
                    UIGrid.SetColumn(squareControl, gridCol);
                    UIGrid.SetRow(squareControl, gridRow);

                    this.grid.Children.Add(squareControl);
                }
            }
        }
示例#6
0
        /// <summary>
        ///     Place an <see cref="UIElement" /> onto the grid. Normally a <see cref="SigmaPanel" /> should be added
        ///     to the UI for a consistent look and feel of the UI.
        /// </summary>
        /// <param name="element">The <see cref="UIElement" /> that will be added.</param>
        /// <param name="row">The row in which the <see cref="UIElement" /> should be added.</param>
        /// <param name="column">The column in which the <see cref="UIElement" /> should be added.</param>
        /// <param name="rowSpan">How many rows the <see cref="UIElement" /> uses.</param>
        /// <param name="columnSpan">How many columns the <see cref="UIElement" /> uses.</param>
        /// <exception cref="ArgumentOutOfRangeException">
        ///     If rowSpan is smaller or equal to zero or if columnSpan
        ///     is smaller or equal to zero.
        /// </exception>
        /// <exception cref="IndexOutOfRangeException">If there is no space for the new <see cref="UIElement" />. </exception>
        public void AddElement(UIElement element, int row, int column, int rowSpan = 1, int columnSpan = 1)
        {
            if (rowSpan <= 0)
            {
                throw new ArgumentOutOfRangeException(nameof(rowSpan));
            }
            if (columnSpan <= 0)
            {
                throw new ArgumentOutOfRangeException(nameof(columnSpan));
            }

            EnsureGridCreated();

            if (row + rowSpan > GridSize.Rows)
            {
                throw new IndexOutOfRangeException("Element would be out of range! (Too few rows)");
            }
            if (column + columnSpan > GridSize.Columns)
            {
                throw new IndexOutOfRangeException("Element would be out of range! (Too few columns)");
            }

            Grid.Children.Add(element);
            WPFGrid.SetRow(element, row);
            WPFGrid.SetColumn(element, column);
            WPFGrid.SetRowSpan(element, rowSpan);
            WPFGrid.SetColumnSpan(element, columnSpan);

            //TODO: Ugly hack - otherwise it does not work if AddElement is called after Prepare
            if (WrappedContent.IsSelected)
            {
                WrappedContent.IsSelected = false;
                WrappedContent.IsSelected = true;
            }

            _log.Debug($"Added {element.GetType().Name} at {row}, {column}, with a span of {rowSpan}, {columnSpan}");
        }
        protected override FrameworkElement CreateChild(object item)
        {
            GridCellData cellData   = (GridCellData)item;
            ColumnBase   gridColumn = cellData.Column;
            AutoWidthCellContentPresenter presenter = new AutoWidthCellContentPresenter();
            int row        = BandedViewBehavior.GetRow(gridColumn);
            int column     = BandedViewBehavior.GetColumn(gridColumn) + 1;
            int rowSpan    = BandedViewBehavior.GetRowSpan(gridColumn);
            int columnSpan = BandedViewBehavior.GetColumnSpan(gridColumn);

            StdGrid.SetRow(presenter, row);
            StdGrid.SetColumn(presenter, column);
            StdGrid.SetRowSpan(presenter, rowSpan);
            StdGrid.SetColumnSpan(presenter, columnSpan);
            if (BandedViewBehavior.GetIsBand(gridColumn))
            {
                presenter.Visibility = Visibility.Collapsed;
            }
            else
            {
                presenter.Visibility = Visibility.Visible;
            }
            return(presenter);
        }
示例#8
0
        public override void SetupCustomUIElements(dynNodeView nodeUI)
        {
            //add a button to the inputGrid on the dynElement
            var selectButton = new dynNodeButton
            {
                HorizontalAlignment = HorizontalAlignment.Stretch,
                VerticalAlignment   = VerticalAlignment.Center
            };

            selectButton.Click += selectButton_Click;

            nodeUI.inputGrid.RowDefinitions.Add(new RowDefinition());
            nodeUI.inputGrid.Children.Add(selectButton);
            Grid.SetRow(selectButton, 0);

            selectButton.DataContext = this;

            var buttonEnabledBinding = new Binding("CanSelect")
            {
                Mode = BindingMode.TwoWay
            };

            selectButton.SetBinding(UIElement.IsEnabledProperty, buttonEnabledBinding);
        }
示例#9
0
        private void GameInfo_Click_1(object sender, RoutedEventArgs e)
        {
            Window win = new Window();
            var Grid = new Grid();
            Grid.ColumnDefinitions.Add(new ColumnDefinition());
            Grid.ColumnDefinitions.Add(new ColumnDefinition());
            int row = 0;
            foreach (var stat in this.Game.lstStats)
            {
                Grid.RowDefinitions.Add(new RowDefinition());
                var label = new Label { Content = stat.Name, HorizontalAlignment = System.Windows.HorizontalAlignment.Right };
                Grid.Children.Add(label);
                Grid.SetRow(label, row);
                Grid.SetColumn(label, 0);

                var val = new Label { Content = stat.Value, HorizontalAlignment = System.Windows.HorizontalAlignment.Left };
                Grid.Children.Add(val);
                Grid.SetRow(val, row);
                Grid.SetColumn(val, 1);
                row++;
            }

            foreach (var stat in this.Game.lstInventory)
            {
                Grid.RowDefinitions.Add(new RowDefinition());
                var label = new Label { Content = stat.Name, HorizontalAlignment = System.Windows.HorizontalAlignment.Right };
                Grid.Children.Add(label);
                Grid.SetRow(label, row);
                Grid.SetColumn(label, 0);

                var val = new Label { Content = stat.Quantity, HorizontalAlignment = System.Windows.HorizontalAlignment.Left };
                Grid.Children.Add(val);
                Grid.SetRow(val, row);
                Grid.SetColumn(val, 1);
                row++;
            }
            win.Content = Grid;
            win.SizeToContent = System.Windows.SizeToContent.WidthAndHeight;
            win.ShowDialog();
        }
示例#10
0
        /// <summary>
        /// Add a dynPort element to this control.
        /// </summary>
        /// <param name="isInput">Is the port an input?</param>
        /// <param name="index">The index of the port in the port list.</param>
        public void AddPort(object el, PortType portType, string name, int index)
        {
            dynPort p = new dynPort(index);

            //create a text block for the name of the port
            TextBlock tb = new TextBlock();

            tb.VerticalAlignment = VerticalAlignment.Center;
            tb.FontSize          = 12;
            tb.FontWeight        = FontWeights.Normal;
            tb.Foreground        = new SolidColorBrush(Colors.Black);
            tb.Text = name;

            //set the z order to the back
            //Canvas.SetZIndex(p, 1);

            if (portType == PortType.INPUT)
            {
                tb.HorizontalAlignment = HorizontalAlignment.Left;

                p.PortType = PortType.INPUT;
                inPorts.Add(p);
                gridLeft.Children.Add(p);
                Grid.SetColumn(p, 0);
                Grid.SetRow(p, index);

                //portNamesLeft.Children.Add(tb);
                gridLeft.Children.Add(tb);
                Grid.SetColumn(tb, 1);
                Grid.SetRow(tb, index);
            }
            else if (portType == PortType.OUTPUT)
            {
                tb.HorizontalAlignment = HorizontalAlignment.Right;

                p.PortType = PortType.OUTPUT;
                outPorts.Add(p);
                gridRight.Children.Add(p);
                Grid.SetColumn(p, 1);
                Grid.SetRow(p, index);

                //portNamesRight.Children.Add(tb);
                gridRight.Children.Add(tb);
                Grid.SetColumn(tb, 0);
                Grid.SetRow(tb, index);
            }
            //else if (portType == PortType.STATE)
            //{
            //    tb.HorizontalAlignment = HorizontalAlignment.Center;

            //    p.PortType = PortType.STATE;
            //    statePorts.Add(p);
            //    gridBottom.Children.Add(p);
            //    Grid.SetColumn(p, index);
            //    Grid.SetRow(p, 0);

            //    portNamesBottom.Children.Add(tb);
            //    Grid.SetColumn(tb, index);
            //    Grid.SetRow(tb, 0);
            //}

            p.Owner = this;

            //register listeners on the port
            p.PortConnected    += new PortConnectedHandler(p_PortConnected);
            p.PortDisconnected += new PortConnectedHandler(p_PortDisconnected);
        }