當前位置: 首頁>>代碼示例>>C#>>正文


C# RowDefinition.SetBinding方法代碼示例

本文整理匯總了C#中System.Windows.Controls.RowDefinition.SetBinding方法的典型用法代碼示例。如果您正苦於以下問題:C# RowDefinition.SetBinding方法的具體用法?C# RowDefinition.SetBinding怎麽用?C# RowDefinition.SetBinding使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在System.Windows.Controls.RowDefinition的用法示例。


在下文中一共展示了RowDefinition.SetBinding方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: UpdateRows

        /// <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);
                }
            }
        }
開發者ID:Mitch-Connor,項目名稱:PropertyTools,代碼行數:93,代碼來源:DataGrid.cs

示例2: UpdateGrid

        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);
                }
            }
        }
開發者ID:Moeinmontazeripour,項目名稱:xamarin-forms-wpf,代碼行數:48,代碼來源:StackLayoutControl.xaml.cs


注:本文中的System.Windows.Controls.RowDefinition.SetBinding方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。