本文整理汇总了C#中System.Windows.Controls.ColumnDefinition.SetBinding方法的典型用法代码示例。如果您正苦于以下问题:C# ColumnDefinition.SetBinding方法的具体用法?C# ColumnDefinition.SetBinding怎么用?C# ColumnDefinition.SetBinding使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Controls.ColumnDefinition
的用法示例。
在下文中一共展示了ColumnDefinition.SetBinding方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: UpdateColumns
private void UpdateColumns()
{
this.Dispatcher.InvokeAsync(
() =>
{
this.ColumnDefinitions.Clear();
int i = 0;
foreach (FrameworkElement item in this.Children.Cast<FrameworkElement>())
{
EntityGroup entityGroup = (EntityGroup)item.DataContext;
ColumnDefinition columnDefinition = new ColumnDefinition()
{
DataContext = entityGroup
};
Grid.SetColumn(item, i);
if (entityGroup.IsVisible)
{
columnDefinition.SetBinding(ColumnDefinition.WidthProperty, "Width");
}
else
{
columnDefinition.Width = new GridLength(0);
}
this.ColumnDefinitions.Add(columnDefinition);
++i;
}
});
}
示例2: UpdateColumns
/// <summary>
/// Updates the specified columns.
/// </summary>
/// <param name="columns">The column index.</param>
private void UpdateColumns(int columns)
{
this.Columns = columns;
for (int i = 0; i < columns; i++)
{
var w = this.GetColumnWidth(i);
var cd1 = new System.Windows.Controls.ColumnDefinition { Width = w };
this.sheetGrid.ColumnDefinitions.Add(cd1);
// bind the width of the header column to the width of the sheet column
var cd2 = new System.Windows.Controls.ColumnDefinition();
this.columnGrid.ColumnDefinitions.Add(cd2);
var binding = new Binding("Width") { Source = cd1, Mode = BindingMode.TwoWay };
cd2.SetBinding(System.Windows.Controls.ColumnDefinition.WidthProperty, binding);
}
// Add one empty column covering the vertical scrollbar
this.columnGrid.ColumnDefinitions.Add(
new System.Windows.Controls.ColumnDefinition { Width = new GridLength(40) });
// set the context menu
this.columnGrid.ContextMenu = this.ColumnsContextMenu;
this.columnGrid.Children.Add(this.columnSelectionBackground);
for (int j = 0; j < columns; j++)
{
object header = this.GetColumnHeader(j);
var cellref = new CellRef(this.ItemsInRows ? -1 : j, this.ItemsInRows ? j : -1);
var pd = this.GetPropertyDefinition(cellref);
var border = new Border
{
BorderBrush = this.HeaderBorderBrush,
BorderThickness = new Thickness(0, 1, 1, 1),
Margin = new Thickness(0, 0, j < columns - 1 ? -1 : 0, 0)
};
Grid.SetColumn(border, j);
this.columnGrid.Children.Add(border);
var cell = header as FrameworkElement
?? new TextBlock
{
Text = header != null ? header.ToString() : "-",
VerticalAlignment = VerticalAlignment.Center,
HorizontalAlignment = this.ItemsInRows ? pd.HorizontalAlignment : HorizontalAlignment.Center,
Padding = new Thickness(4, 2, 4, 2)
};
if (this.ColumnHeadersSource != null && this.ItemsInRows)
{
cell.DataContext = this.ColumnHeadersSource;
cell.SetBinding(TextBlock.TextProperty, new Binding(string.Format("[{0}]", j)) { StringFormat = this.ColumnHeadersFormatString });
}
Grid.SetColumn(cell, j);
this.columnGrid.Children.Add(cell);
this.columnHeaderMap[j] = cell;
}
for (int j = 0; j < columns; j++)
{
if (this.CanResizeColumns)
{
var splitter = new GridSplitter
{
ResizeDirection = GridResizeDirection.Columns,
Background = Brushes.Transparent,
Width = 5,
RenderTransform = new TranslateTransform(3, 0),
Focusable = false,
VerticalAlignment = VerticalAlignment.Stretch,
HorizontalAlignment = HorizontalAlignment.Right
};
splitter.MouseDoubleClick += this.ColumnSplitterDoubleClick;
splitter.DragStarted += this.ColumnSplitterChangeStarted;
splitter.DragDelta += this.ColumnSplitterChangeDelta;
splitter.DragCompleted += this.ColumnSplitterChangeCompleted;
Grid.SetColumn(splitter, j);
this.columnGrid.Children.Add(splitter);
}
}
}
示例3: WriteGridColumns
private static void WriteGridColumns(DependencyObject d, ref DependencyPropertyChangedEventArgs e)
{
var grid = d as Grid;
if (grid == null) return;
grid.ColumnDefinitions.Clear();
int columnCount = 0;
if (!Int32.TryParse(e.NewValue.ToString(), out columnCount)) return;
var columnWidths = GetColumnWidth(grid).Split(',');
for (int i = 0; i < columnCount; i++)
{
var columnDefinition = new ColumnDefinition { MinWidth =140 };
grid.ColumnDefinitions.Add(columnDefinition);
if (columnWidths.Length <= i) continue;
columnDefinition.SetBinding(ColumnDefinition.WidthProperty,new Binding("TrackObject.Width")
{
Mode=BindingMode.TwoWay,
Converter=new GAP.Converters.GridLengthConverter()
});
}
}
示例4: RepopulateHeaders
private void RepopulateHeaders()
{
if (Columns == null)
{
Visibility = Visibility.Collapsed;
ForceParentRefresh();
return;
}
if (Visibility != Visibility.Visible)
{
Visibility = Visibility.Visible;
ForceParentRefresh();
}
var grid = new Grid
{
VerticalAlignment = VerticalAlignment.Stretch,
HorizontalAlignment = HorizontalAlignment.Left,
Width = 100000,
ClipToBounds = true
};
_headerContentGrids.Clear();
var columnCounter = -1;
var starColumnFound = false;
foreach (var column in Columns)
{
columnCounter++;
var gridColumn = new ColumnDefinition();
gridColumn.SetBinding(ColumnDefinition.WidthProperty, new Binding("Width") {Source = column, Mode = BindingMode.TwoWay});
var descriptor = DependencyPropertyDescriptor.FromProperty(ColumnDefinition.WidthProperty, typeof(ColumnDefinition));
if (descriptor != null)
{
var localColumn = column;
descriptor.AddValueChanged(gridColumn, (s2, e2) => { localColumn.ActualWidth = gridColumn.ActualWidth; });
grid.LayoutUpdated += (s3, e3) => { localColumn.ActualWidth = gridColumn.ActualWidth; };
grid.SizeChanged += (s4, e4) => { localColumn.ActualWidth = gridColumn.ActualWidth; };
SizeChanged += (s4, e4) => { localColumn.ActualWidth = gridColumn.ActualWidth; };
}
grid.ColumnDefinitions.Add(gridColumn);
if (column.Width.GridUnitType == GridUnitType.Star) starColumnFound = true;
var content = new HeaderContentControl {Column = column};
if (!string.IsNullOrEmpty(column.HeaderClickCommandBindingPath))
{
var binding = new Binding(column.HeaderClickCommandBindingPath);
content.SetBinding(HeaderContentControl.HeaderClickCommandProperty, binding);
}
var contentParent = new ContentControl {VerticalAlignment = VerticalAlignment.Stretch, HorizontalAlignment = HorizontalAlignment.Stretch};
if (column.HeaderEventCommands != null && column.HeaderEventCommands.Count > 0)
Ex.SetEventCommands(contentParent, column.HeaderEventCommands);
if (column.HeaderTemplate != null)
{
var realContent = column.HeaderTemplate.LoadContent();
var realContentElement = realContent as UIElement;
if (realContentElement != null)
contentParent.Content = realContentElement;
}
else
{
var contentGrid = new Grid {HorizontalAlignment = HorizontalAlignment.Stretch, VerticalAlignment = VerticalAlignment.Stretch};
_headerContentGrids.Add(contentGrid);
contentGrid.RowDefinitions.Add(new RowDefinition {Height = new GridLength(1d, GridUnitType.Star)});
contentGrid.RowDefinitions.Add(new RowDefinition {Height = new GridLength(1d, GridUnitType.Auto)});
if (column.ShowColumnHeaderText)
{
var textPlusGraphic = new TextPlusGraphic();
var headerText = new TextBlock();
textPlusGraphic.Children.Add(headerText);
if (column.Header != null)
headerText.Text = column.Header.ToString();
else
column.Header = " ";
var sort = new SortOrderIndicator();
if (!string.IsNullOrEmpty(column.SortOrderBindingPath))
sort.SetBinding(SortOrderIndicator.OrderProperty, new Binding(column.SortOrderBindingPath));
else
sort.Order = column.SortOrder;
textPlusGraphic.Children.Add(sort);
Grid.SetRow(textPlusGraphic, 1);
contentGrid.Children.Add(textPlusGraphic);
}
if (column.ShowColumnHeaderEditControl)
{
var headerTb = new TextBox();
if (!string.IsNullOrEmpty(column.ColumnHeaderEditControlBindingPath))
headerTb.SetBinding(TextBox.TextProperty, new Binding(column.ColumnHeaderEditControlBindingPath) {UpdateSourceTrigger = column.ColumnHeaderEditControlUpdateTrigger});
if (!string.IsNullOrEmpty(column.ColumnHeaderEditControlWatermarkText))
TextBoxEx.SetWatermarkText(headerTb, column.ColumnHeaderEditControlWatermarkText);
contentGrid.Children.Add(headerTb);
}
contentParent.Content = contentGrid;
}
content.Content = contentParent;
grid.Children.Add(content);
//.........这里部分代码省略.........
示例5: CreateDefinitions
private void CreateDefinitions( )
{
Debug.WriteLine($"{GameBoard.ActualHeight} x {GameBoard.ActualWidth}");
var rows = App.GameModel.Rows;
var columns = App.GameModel.Columns;
for(var i = 1; i <= rows; i++)
{
var heightBinding = new Binding("ActualHeight")
{
Converter = new SizeToGridLengthConverter(),
Source = GameBoard,
ConverterParameter = "Height"
};
var r = new RowDefinition();
r.SetBinding(RowDefinition.HeightProperty, heightBinding);
GameBoard.RowDefinitions.Add(r);
}
for(var i = 1; i <= columns; i++)
{
var widthBinding = new Binding("ActualWidth")
{
Converter = new SizeToGridLengthConverter(),
Source = GameBoard,
ConverterParameter = "Width"
};
var c = new ColumnDefinition();
c.SetBinding(ColumnDefinition.WidthProperty, widthBinding);
GameBoard.ColumnDefinitions.Add(c);
}
}
示例6: 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);
}
}
}