当前位置: 首页>>代码示例>>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;未经允许,请勿转载。