本文整理汇总了C#中System.Windows.Controls.Grid.BeginInit方法的典型用法代码示例。如果您正苦于以下问题:C# Grid.BeginInit方法的具体用法?C# Grid.BeginInit怎么用?C# Grid.BeginInit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Controls.Grid
的用法示例。
在下文中一共展示了Grid.BeginInit方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetMappedLayerWeights
public ScrollViewer GetMappedLayerWeights()
{
WrapPanel panel = new WrapPanel();
panel.BeginInit();
panel.UseLayoutRounding = true;
panel.SnapsToDevicePixels = true;
panel.Orientation = Orientation.Horizontal;
panel.HorizontalAlignment = HorizontalAlignment.Stretch;
panel.VerticalAlignment = VerticalAlignment.Stretch;
for (int map = 0; map < MapCount; map++)
{
Grid grid = new Grid();
grid.SnapsToDevicePixels = true;
grid.UseLayoutRounding = true;
grid.Background = System.Windows.Media.Brushes.White;
grid.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;
grid.VerticalAlignment = System.Windows.VerticalAlignment.Top;
grid.Width = double.NaN;
grid.Height = double.NaN;
grid.Margin = new Thickness(4);
for (int col = 0; col < MapWidth; col++)
{
ColumnDefinition colDef = new ColumnDefinition();
colDef.Width = new GridLength(0, GridUnitType.Auto);
grid.ColumnDefinitions.Add(colDef);
}
for (int row = 0; row < MapHeight; row++)
{
RowDefinition rowDef = new RowDefinition();
rowDef.Height = new GridLength(0, GridUnitType.Auto);
grid.RowDefinitions.Add(rowDef);
}
double weightMin = Weights.Min(weight => weight.Value);
double weightMax = Weights.Max(weight => weight.Value);
double range = GetRangeFactor(weightMin, weightMax);
grid.BeginInit();
for (int y = 0; y < ReceptiveFieldWidth; y++)
{
for (int x = 0; x < ReceptiveFieldHeight; x++)
{
int index = x + (y * ReceptiveFieldWidth) + (map * ((ReceptiveFieldWidth * ReceptiveFieldHeight) + 1));
System.Windows.Shapes.Rectangle rectangle = new System.Windows.Shapes.Rectangle();
rectangle.BeginInit();
rectangle.SnapsToDevicePixels = true;
rectangle.UseLayoutRounding = true;
rectangle.HorizontalAlignment = HorizontalAlignment.Stretch;
ToolTip tip = new ToolTip();
tip.Content = Weights[index].Value.ToString("N17", CultureInfo.CurrentUICulture);
rectangle.ToolTip = tip;
rectangle.VerticalAlignment = VerticalAlignment.Stretch;
rectangle.Margin = new Thickness(0);
rectangle.Height = 8;
rectangle.Width = 8;
rectangle.Stretch = Stretch.Uniform;
rectangle.Fill = GetBrushFromRange(range, weightMin, weightMax, Weights[index].Value);
rectangle.EndInit();
Grid.SetColumn(rectangle, x);
Grid.SetRow(rectangle, y);
grid.Children.Add(rectangle);
tip = null;
rectangle = null;
}
};
grid.EndInit();
panel.Children.Add(grid);
}
panel.EndInit();
ScrollViewer scr = new ScrollViewer();
scr.BeginInit();
scr.SnapsToDevicePixels = true;
scr.UseLayoutRounding = true;
scr.VerticalScrollBarVisibility = ScrollBarVisibility.Visible;
scr.HorizontalScrollBarVisibility = ScrollBarVisibility.Disabled;
scr.HorizontalContentAlignment = HorizontalAlignment.Left;
scr.VerticalContentAlignment = VerticalAlignment.Top;
scr.VerticalAlignment = VerticalAlignment.Stretch;
scr.HorizontalAlignment = HorizontalAlignment.Stretch;
scr.Content = panel;
scr.Height = double.NaN;
scr.Width = double.NaN;
scr.EndInit();
return (scr);
}
示例2: GetMappedLayerOutputs
public ScrollViewer GetMappedLayerOutputs()
{
WrapPanel panel = new WrapPanel();
panel.BeginInit();
panel.UseLayoutRounding = true;
panel.SnapsToDevicePixels = true;
panel.Orientation = Orientation.Horizontal;
panel.HorizontalAlignment = HorizontalAlignment.Stretch;
panel.VerticalAlignment = VerticalAlignment.Stretch;
for (int map = 0; map < MapCount; ++map)
{
Grid grid = new Grid();
grid.SnapsToDevicePixels = true;
grid.UseLayoutRounding = true;
grid.Background = System.Windows.Media.Brushes.White;
grid.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;
grid.VerticalAlignment = System.Windows.VerticalAlignment.Top;
grid.Width = double.NaN;
grid.Height = double.NaN;
grid.Margin = new Thickness(4);
for (int col = 0; col < MapWidth; col++)
{
ColumnDefinition colDef = new ColumnDefinition();
colDef.Width = new GridLength(0, GridUnitType.Auto);
grid.ColumnDefinitions.Add(colDef);
}
for (int row = 0; row < MapHeight; row++)
{
RowDefinition rowDef = new RowDefinition();
rowDef.Height = new GridLength(0, GridUnitType.Auto);
grid.RowDefinitions.Add(rowDef);
}
grid.BeginInit();
for (int y = 0; y < MapHeight; y++)
{
for (int x = 0; x < MapWidth; x++)
{
int index = x + (y * MapWidth) + (map * MapWidth * MapHeight);
byte color = (byte)(255 - ((Neurons[index].Output + 1D) * 127D));
System.Windows.Media.SolidColorBrush brush = new System.Windows.Media.SolidColorBrush(System.Windows.Media.Color.FromRgb(color, color, color));
brush.Freeze();
System.Windows.Shapes.Rectangle rectangle = new System.Windows.Shapes.Rectangle();
rectangle.BeginInit();
rectangle.SnapsToDevicePixels = true;
rectangle.UseLayoutRounding = true;
rectangle.HorizontalAlignment = HorizontalAlignment.Stretch;
ToolTip tip = new ToolTip();
tip.Content = Neurons[index].Output.ToString("N17", CultureInfo.CurrentUICulture);
rectangle.ToolTip = tip;
rectangle.VerticalAlignment = VerticalAlignment.Stretch;
rectangle.Margin = new Thickness(0);
rectangle.Height = 8;
rectangle.Width = 8;
rectangle.Stretch = Stretch.Uniform;
rectangle.Fill = brush;
rectangle.EndInit();
Grid.SetColumn(rectangle, x);
Grid.SetRow(rectangle, y);
grid.Children.Add(rectangle);
brush = null;
tip = null;
rectangle = null;
}
}
grid.EndInit();
panel.Children.Add(grid);
}
panel.EndInit();
ScrollViewer scr = new ScrollViewer();
scr.BeginInit();
scr.SnapsToDevicePixels = true;
scr.UseLayoutRounding = true;
scr.VerticalScrollBarVisibility = ScrollBarVisibility.Visible;
scr.HorizontalScrollBarVisibility = ScrollBarVisibility.Disabled;
scr.HorizontalContentAlignment = HorizontalAlignment.Left;
scr.VerticalContentAlignment = VerticalAlignment.Top;
scr.VerticalAlignment = VerticalAlignment.Stretch;
scr.HorizontalAlignment = HorizontalAlignment.Stretch;
scr.Content = panel;
scr.Height = double.NaN;
scr.Width = double.NaN;
scr.EndInit();
return (scr);
}
示例3: GenerateRows
private void GenerateRows(int StartZeile, int EndZeile)
{
try
{
if (StartZeile == EndZeile) return;
if (oTable == null)
{
oTable = new Grid();
oTable.BeginInit();
}
oTable.SetValue(TextBlock.FontFamilyProperty, new FontFamily("Verdana"));
if (Configuration.FontSize < 4) configuration.FontSize = 8;
oTable.SetValue(TextBlock.FontSizeProperty, (double)Configuration.FontSize);
GenerateColumns();
for (int i = StartZeile; i <= EndZeile + 1; i++)
{
oTable.RowDefinitions.Add(new RowDefinition());
}
int ColBorders = 1;
int ColBorderLeft = 1;
int ColBorderRight = 0;
int ColBorderButtom = 1;
if (!HasRowLines)
ColBorderButtom = 0;
if (!HasColumnLines) ColBorders = 0;
int row = 1;
int col = -1;
GenerateHeaderRow(ColBorders);
for (int currow = StartZeile; currow < EndZeile; currow++)
{
DataRow item = oData.Rows[currow];
row++;
if (currow + 1 == EndZeile)
ColBorderButtom = 1;
int FirstCol = 1;
int colcount = 0; //nur ECHTE Spalten
col = -1;
for (int i = CurrentRange.From; i <= CurrentRange.Until; i++)
{
ColumnDefinition colDef = Columns[i];
col++;
ColBorderLeft = 1;
ColBorderRight = 0;
colcount++;
if (ColBorders == 0 && FirstCol != 1)
ColBorderLeft = 0;
if (colcount == (CurrentRange.Until - CurrentRange.From + 1))
ColBorderRight = 1;
string sValue = "";
sValue = item.Field<string>(colDef.Name);
if (sValue.Contains("\n"))
sValue = sValue.Split('\n')[0];
if (sValue.Contains("\r"))
sValue = sValue.Split('\r')[0];
GenerateCell(sValue, colDef, new Thickness(ColBorderLeft, 0, ColBorderRight, ColBorderButtom), row, col, null);
FirstCol = 0;
}
}
return;
}
catch (Exception ex)
{ }
}
示例4: GenerateFixedDocument
public void GenerateFixedDocument(bool InPrintMode)
{
PrintDocument = new FixedDocument();
int RowsOnPage = 100;
PageSupplemental oSupplemental = new PageSupplemental(Configuration);
PageDefinition def = definition;
//Verteilung auf mehreren Seiten?
GenerateRanges();
int RowsOnFirstPage = CalculateRowsOnPage(ref RowsOnPage, def);
UpdatePages();
int from = PageSelectionFrom;
int until = PageSelectionUntil;
if (AllPages | !InPrintMode)
{ from = 1; until = maxPages; }
ProgressContext.Init(Properties.Resources.prgSeiten, (until - from + 1));
PrintDocument.DocumentPaginator.PageSize = def.PageSize;
for (int i = from; i <= until; i++)
{
for (int x = 1; x <= ColRanges.Count; x++)
{
oTable = new Grid();
oTable.BeginInit();
ProgressContext.UpdateProgress(i - from + x);
if (ProgressContext.Canceled)
{
ProgressContext.Finish();
return;
}
offset = x - 1;
PageContent oPage = new PageContent();
FixedPage oFixed = CreatePage();
int RowsUntil = Math.Min((i - 1) * RowsOnPage + RowsOnFirstPage, oData.Rows.Count);
int RowsFrom = (i - 2) * RowsOnPage + RowsOnFirstPage;
if (RowsFrom < 0)
RowsFrom = 0;
GenerateRows(RowsFrom, RowsUntil);
oTable.Width = def.ContentSize.Width;
oTable.Margin = new Thickness(def.ContentOrigin.X, def.ContentOrigin.Y, 0, 0);
oTable.EndInit();
oFixed.Children.Add(oTable);
FrameworkElement oHeader = oSupplemental.PageHeader();
oHeader.Width = def.ContentSize.Width;
oHeader.Margin = new Thickness(def.HeaderRect.Left, def.HeaderRect.Top, 0, 0);
oFixed.Children.Add(oHeader);
string currentpage = Convert.ToString(((int)i));
if (ColRanges.Count > 1)
currentpage = currentpage.AddLetter(x);
FrameworkElement oFooter = oSupplemental.PageFooter(currentpage, Maximum);
oFooter.Margin = new Thickness(def.FooterRect.Left, def.FooterRect.Top, 0, 0);
oFooter.Width = def.ContentSize.Width;
oFixed.Children.Add(oFooter);
oFixed.Measure(def.PageSize);
oFixed.Arrange(new Rect(new Point(), def.PageSize));
oFixed.UpdateLayout();
((IAddChild)oPage).AddChild(oFixed);
PrintDocument.Pages.Add(oPage);
}
}
ticket.PageBorderless = PageBorderless.Borderless;
oTable = null;
ProgressContext.Finish();
NotifyPropertyChanged("PrintDocument");
NotifyPropertyChanged("Maximum");
NotifyPropertyChanged("PageSelectionFrom");
NotifyPropertyChanged("PageSelectionUntil");
}
示例5: ResizeRows
private void ResizeRows(Grid grid, double deltaX)
{
GridResizeBehavior effectiveGridResizeBehavior =
this.DetermineEffectiveResizeBehavior();
int row = Grid.GetRow(this);
int upperRow;
int lowerRow;
switch (effectiveGridResizeBehavior)
{
case GridResizeBehavior.PreviousAndCurrent:
upperRow = row - 1;
lowerRow = row;
break;
case GridResizeBehavior.PreviousAndNext:
upperRow = row - 1;
lowerRow = row + 1;
break;
default:
upperRow = row;
lowerRow = row + 1;
break;
}
if (lowerRow >= grid.RowDefinitions.Count)
{
return;
}
var upperRowDefinition = grid.RowDefinitions[upperRow];
var lowerRowDefinition = grid.RowDefinitions[lowerRow];
var upperRowGridUnitType = upperRowDefinition.Height.GridUnitType;
var lowerRowGridUnitType = lowerRowDefinition.Height.GridUnitType;
var upperRowActualHeight = upperRowDefinition.ActualHeight;
var lowerRowActualHeight = lowerRowDefinition.ActualHeight;
var upperRowMaxHeight = upperRowDefinition.MaxHeight;
var lowerRowMaxHeight = lowerRowDefinition.MaxHeight;
var upperRowMinHeight = upperRowDefinition.MinHeight;
var lowerRowMinHeight = lowerRowDefinition.MinHeight;
//deltaX = 200;
if (upperRowActualHeight + deltaX > upperRowMaxHeight)
{
deltaX = Math.Max(
0,
upperRowDefinition.MaxHeight - upperRowActualHeight);
}
if (upperRowActualHeight + deltaX < upperRowMinHeight)
{
deltaX = Math.Min(
0,
upperRowDefinition.MinHeight - upperRowActualHeight);
}
if (lowerRowActualHeight - deltaX > lowerRowMaxHeight)
{
deltaX = -Math.Max(
0,
lowerRowDefinition.MaxHeight - lowerRowActualHeight);
}
if (lowerRowActualHeight - deltaX < lowerRowMinHeight)
{
deltaX = -Math.Min(
0,
lowerRowDefinition.MinHeight - lowerRowActualHeight);
}
var newUpperRowActualHeight = upperRowActualHeight + deltaX;
var newLowerRowActualHeight = lowerRowActualHeight - deltaX;
grid.BeginInit();
double totalStarRowsHeight = 0;
double starRowsAvailableHeight = grid.ActualHeight;
if (upperRowGridUnitType ==
GridUnitType.Star ||
lowerRowGridUnitType ==
GridUnitType.Star)
{
foreach (var rowDefinition in grid.RowDefinitions)
{
if (rowDefinition.Height.GridUnitType ==
GridUnitType.Star)
{
totalStarRowsHeight +=
rowDefinition.Height.Value;
}
else
{
starRowsAvailableHeight -=
rowDefinition.ActualHeight;
}
}
}
if (upperRowGridUnitType == GridUnitType.Star)
//.........这里部分代码省略.........
示例6: ResizeColumns
private void ResizeColumns(Grid grid, double deltaX)
{
GridResizeBehavior effectiveGridResizeBehavior =
this.DetermineEffectiveResizeBehavior();
int column = Grid.GetColumn(this);
int leftColumn;
int rightColumn;
switch (effectiveGridResizeBehavior)
{
case GridResizeBehavior.PreviousAndCurrent:
leftColumn = column - 1;
rightColumn = column;
break;
case GridResizeBehavior.PreviousAndNext:
leftColumn = column - 1;
rightColumn = column + 1;
break;
default:
leftColumn = column;
rightColumn = column + 1;
break;
}
if (rightColumn >= grid.ColumnDefinitions.Count)
{
return;
}
var leftColumnDefinition = grid.ColumnDefinitions[leftColumn];
var rightColumnDefinition = grid.ColumnDefinitions[rightColumn];
var leftColumnGridUnitType = leftColumnDefinition.Width.GridUnitType;
var rightColumnGridUnitType = rightColumnDefinition.Width.GridUnitType;
var leftColumnActualWidth = leftColumnDefinition.ActualWidth;
var rightColumnActualWidth = rightColumnDefinition.ActualWidth;
var leftColumnMaxWidth = leftColumnDefinition.MaxWidth;
var rightColumnMaxWidth = rightColumnDefinition.MaxWidth;
var leftColumnMinWidth = leftColumnDefinition.MinWidth;
var rightColumnMinWidth = rightColumnDefinition.MinWidth;
//deltaX = 200;
if (leftColumnActualWidth + deltaX > leftColumnMaxWidth)
{
deltaX = Math.Max(
0,
leftColumnDefinition.MaxWidth - leftColumnActualWidth);
}
if (leftColumnActualWidth + deltaX < leftColumnMinWidth)
{
deltaX = Math.Min(
0,
leftColumnDefinition.MinWidth - leftColumnActualWidth);
}
if (rightColumnActualWidth - deltaX > rightColumnMaxWidth)
{
deltaX = -Math.Max(
0,
rightColumnDefinition.MaxWidth - rightColumnActualWidth);
}
if (rightColumnActualWidth - deltaX < rightColumnMinWidth)
{
deltaX = -Math.Min(
0,
rightColumnDefinition.MinWidth - rightColumnActualWidth);
}
var newLeftColumnActualWidth = leftColumnActualWidth + deltaX;
var newRightColumnActualWidth = rightColumnActualWidth - deltaX;
grid.BeginInit();
double totalStarColumnsWidth = 0;
double starColumnsAvailableWidth = grid.ActualWidth;
if (leftColumnGridUnitType ==
GridUnitType.Star ||
rightColumnGridUnitType ==
GridUnitType.Star)
{
foreach (var columnDefinition in grid.ColumnDefinitions)
{
if (columnDefinition.Width.GridUnitType ==
GridUnitType.Star)
{
totalStarColumnsWidth +=
columnDefinition.Width.Value;
}
else
{
starColumnsAvailableWidth -=
columnDefinition.ActualWidth;
}
}
}
if (leftColumnGridUnitType == GridUnitType.Star)
//.........这里部分代码省略.........