本文整理汇总了C#中System.Windows.Controls.Grid.Measure方法的典型用法代码示例。如果您正苦于以下问题:C# Grid.Measure方法的具体用法?C# Grid.Measure怎么用?C# Grid.Measure使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Controls.Grid
的用法示例。
在下文中一共展示了Grid.Measure方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ExportToString
/// <summary>
/// Export the specified plot model to an xaml string.
/// </summary>
/// <param name="model">The model.</param>
/// <param name="width">The width.</param>
/// <param name="height">The height.</param>
/// <param name="background">The background.</param>
/// <returns>A xaml string.</returns>
public static string ExportToString(PlotModel model, double width, double height, OxyColor background = null)
{
var g = new Grid();
if (background != null)
{
g.Background = background.ToBrush();
}
var c = new Canvas();
g.Children.Add(c);
var size = new Size(width, height);
g.Measure(size);
g.Arrange(new Rect(0, 0, width, height));
g.UpdateLayout();
var rc = new ShapesRenderContext(c) { UseStreamGeometry = false };
model.Update();
model.Render(rc, width, height);
var sb = new StringBuilder();
using (var sw = new StringWriter(sb))
{
var xw = XmlWriter.Create(sw, new XmlWriterSettings { Indent = true });
XamlWriter.Save(c, xw);
}
return sb.ToString();
}
示例2: create
void create()
{
Grid grid = new Grid();
grid.HorizontalAlignment = HorizontalAlignment.Center;
grid.VerticalAlignment = VerticalAlignment.Center;
grid.Background = null;
Rating ratingControl = new Rating();
ratingControl.HorizontalAlignment = HorizontalAlignment.Left;
ratingControl.VerticalAlignment = VerticalAlignment.Top;
ratingControl.ItemCount = 5;
ratingControl.Foreground = new SolidColorBrush(Colors.Red);
ratingControl.Background = null;
ratingControl.IsReadOnly = true;
ratingControl.SelectionMode = RatingSelectionMode.Continuous;
double scale = 0.6;
ratingControl.LayoutTransform = new ScaleTransform(scale, scale);
grid.Children.Add(ratingControl);
int i = 0;
double nrStars = 0;
do
{
ratingControl.Value = nrStars;
grid.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
grid.Arrange(new Rect(new Size(double.MaxValue, double.MaxValue)));
Rect size = VisualTreeHelper.GetDescendantBounds(ratingControl);
//grid.Arrange(new Rect(new Size(size.Width, size.Height)));
RenderTargetBitmap bitmap = new RenderTargetBitmap((int)(size.Width * scale), (int)(size.Height * scale),
96, 96, PixelFormats.Default);
Window dummy = new Window();
dummy.Content = grid;
dummy.SizeToContent = SizeToContent.WidthAndHeight;
dummy.Show();
bitmap.Render(ratingControl);
RatingBitmap.Add(bitmap);
nrStars += 1.0 / 5;
BitmapEncoder encoder = new PngBitmapEncoder();
encoder.Frames.Add(BitmapFrame.Create(bitmap, null, null, null));
FileStream outputFile = new FileStream("d:\\" + i + "stars.png", FileMode.Create);
encoder.Save(outputFile);
i++;
} while (nrStars <= 1);
}
示例3: Button_Click
private void Button_Click(object sender, RoutedEventArgs e)
{
var icon = (sender as Button).DataContext as IconWrapper;
var grid = new Grid {Height = 36, Width = 36, Background = Brushes.White};
var visual = new Rectangle {Fill = icon.Icon};
grid.Children.Add(visual);
var renderBitmap = new RenderTargetBitmap(36, 36, 96d, 96d, PixelFormats.Pbgra32);
var size = new Size(36, 36);
grid.Measure(size);
grid.Arrange(new Rect(size));
// Update the layout for the surface. This should flush out any layout queues that hold a reference.
renderBitmap.Render(grid);
Clipboard.SetImage(renderBitmap);
}
示例4: OnMouseMove
private void OnMouseMove(object sender, MouseEventArgs e)
{
var popup = GetPopupTipWindow();
if (popup.IsOpen)
popup.Hide();
Point screenPoint = e.GetPosition(plotter.CentralGrid);
Point viewportPoint = screenPoint.ScreenToData(plotter.Transform);
var tooltip = GetTooltipForPoint(viewportPoint);
if (tooltip == null) return;
popup.VerticalOffset = screenPoint.Y + 20;
popup.HorizontalOffset = screenPoint.X;
popup.ShowDelayed(TimeSpan.FromSeconds(0));
Grid grid = new Grid();
Rectangle rect = new Rectangle
{
Stroke = Brushes.Black,
Fill = SystemColors.InfoBrush
};
StackPanel panel = new StackPanel();
panel.Orientation = Orientation.Vertical;
panel.Children.Add(tooltip);
panel.Margin = new Thickness(4, 2, 4, 2);
var textBlock = new TextBlock();
textBlock.Text = String.Format("Location: {0:F2}, {1:F2}", viewportPoint.X, viewportPoint.Y);
textBlock.Foreground = SystemColors.GrayTextBrush;
panel.Children.Add(textBlock);
grid.Children.Add(rect);
grid.Children.Add(panel);
grid.Measure(SizeHelper.CreateInfiniteSize());
popup.Child = grid;
}
示例5: RenderAndSave
public void RenderAndSave(ImageRendererArguments args, out string fileName)
{
var mainContainer = new Grid();
mainContainer.Children.Add(args.UiContainer);
mainContainer.Measure(new Size(args.Width, args.Height));
mainContainer.Arrange(new Rect(0, 0, args.Width, args.Height));
mainContainer.UpdateLayout();
var encoder = new PngBitmapEncoder();
var render = RenderBitmap(mainContainer, args.Dpi);
var workingDirectory = @"c:\temp";
fileName = Path.Combine(workingDirectory, $"dwg_{Guid.NewGuid()}.png");
render.Render(mainContainer);
encoder.Frames.Add(BitmapFrame.Create(render));
using (var s = File.Open(fileName, FileMode.Create))
{
encoder.Save(s);
}
}
示例6: ComplexLayout2
public void ComplexLayout2 ()
{
Grid g = new Grid ();
RowDefinition rdef;
ColumnDefinition cdef;
rdef = new RowDefinition ();
rdef.Height = new GridLength (200);
g.RowDefinitions.Add (rdef);
cdef = new ColumnDefinition ();
cdef.Width = new GridLength (200);
g.ColumnDefinitions.Add (cdef);
g.Margin = new Thickness (5);
LayoutPoker c = new LayoutPoker ();
Grid.SetRow (c, 0);
Grid.SetColumn (c, 0);
g.Children.Add (c);
c.Measure (new Size (Double.PositiveInfinity, Double.PositiveInfinity));
// first test with the child sized larger than the row/column definitions
c.Width = 400;
c.Height = 400;
g.Measure (new Size (Double.PositiveInfinity, Double.PositiveInfinity));
Assert.AreEqual (400, c.Width);
Assert.AreEqual (400, c.Height);
Assert.AreEqual (new Size (200, 200), c.DesiredSize, "c DesiredSize0");
Assert.AreEqual (new Size (400, 400), c.MeasureArg, "c MeasureArg0");
Assert.AreEqual (new Size (210, 210), g.DesiredSize, "grid DesiredSize0");
g.Measure (new Size (100, 100));
Assert.AreEqual (new Size (100, 100), g.DesiredSize, "grid DesiredSize1");
Assert.AreEqual (new Size (400, 400), c.MeasureArg, "c MeasureArg");
Assert.AreEqual (new Size (200, 200), c.DesiredSize, "c DesiredSize1");
// now test with the child sized smaller than the row/column definitions
c.Width = 100;
c.Height = 100;
g.Measure (new Size (Double.PositiveInfinity, Double.PositiveInfinity));
Assert.AreEqual (new Size (100, 100), c.MeasureArg, "c MeasureArg2");
Assert.AreEqual (new Size (210, 210), g.DesiredSize, "grid DesiredSize2");
}
示例7: ChildlessMargin_RowDefinition_Height_starSize_constSize_multiRow
public void ChildlessMargin_RowDefinition_Height_starSize_constSize_multiRow ()
{
Grid g = new Grid ();
RowDefinition def;
def = new RowDefinition ();
def.Height = new GridLength (2, GridUnitType.Star);
g.RowDefinitions.Add (def);
def = new RowDefinition ();
def.Height = new GridLength(200);
g.RowDefinitions.Add (def);
g.Margin = new Thickness (5);
g.Measure (new Size (Double.PositiveInfinity, Double.PositiveInfinity));
Assert.AreEqual (new Size (10, 210), g.DesiredSize, "DesiredSize");
g.Measure (new Size (100, 100));
Assert.AreEqual (new Size (10, 100), g.DesiredSize, "DesiredSize");
}
示例8: ChildlessMargin_RowDefinition_Height_autoSize_singleRow
public void ChildlessMargin_RowDefinition_Height_autoSize_singleRow ()
{
Grid g = new Grid ();
RowDefinition def;
def = new RowDefinition ();
def.Height = GridLength.Auto;
g.RowDefinitions.Add (def);
g.Margin = new Thickness (5);
g.Measure (new Size (Double.PositiveInfinity, Double.PositiveInfinity));
Assert.AreEqual (new Size (10, 10), g.DesiredSize, "DesiredSize");
g.Measure (new Size (100, 100));
Assert.AreEqual (new Size (10, 10), g.DesiredSize, "DesiredSize");
}
示例9: ChildlessMargin_ColumnDefinition_Width_starSize_constSize_multiColumn
public void ChildlessMargin_ColumnDefinition_Width_starSize_constSize_multiColumn ()
{
Grid g = new Grid ();
ColumnDefinition def;
def = new ColumnDefinition ();
def.Width = new GridLength (2, GridUnitType.Star);
g.ColumnDefinitions.Add (def);
def = new ColumnDefinition ();
def.Width = new GridLength(200);
g.ColumnDefinitions.Add (def);
g.Margin = new Thickness (5);
g.Measure (new Size (Double.PositiveInfinity, Double.PositiveInfinity));
Assert.AreEqual (new Size (210, 10), g.DesiredSize, "DesiredSize");
g.Measure (new Size (100, 100));
Assert.AreEqual (new Size (100, 10), g.DesiredSize, "DesiredSize");
}
示例10: ChildlessMargin_ColumnDefinition_Width_autoSize_singleColumn
public void ChildlessMargin_ColumnDefinition_Width_autoSize_singleColumn ()
{
Grid g = new Grid ();
ColumnDefinition def;
def = new ColumnDefinition ();
def.Width = GridLength.Auto;
g.ColumnDefinitions.Add (def);
g.Margin = new Thickness (5);
g.Measure (new Size (Double.PositiveInfinity, Double.PositiveInfinity));
Assert.AreEqual (new Size (10, 10), g.DesiredSize, "DesiredSize");
g.Measure (new Size (100, 100));
Assert.AreEqual (new Size (10, 10), g.DesiredSize, "DesiredSize");
}
示例11: ArrangeTest_TwoChildren
public void ArrangeTest_TwoChildren ()
{
Grid g = new Grid ();
RowDefinition rdef;
ColumnDefinition cdef;
rdef = new RowDefinition ();
rdef.Height = new GridLength (50);
g.RowDefinitions.Add (rdef);
cdef = new ColumnDefinition ();
cdef.Width = new GridLength (100);
g.ColumnDefinitions.Add (cdef);
cdef = new ColumnDefinition ();
cdef.Width = new GridLength (20);
g.ColumnDefinitions.Add (cdef);
g.Margin = new Thickness (5);
var ra = new Border ();
var rb = new Border ();
Grid.SetRow (ra, 0);
Grid.SetColumn (ra, 0);
Grid.SetRow (rb, 0);
Grid.SetColumn (rb, 1);
g.Children.Add (ra);
g.Children.Add (rb);
g.Measure (new Size (Double.PositiveInfinity, Double.PositiveInfinity));
Assert.AreEqual (new Size (0,0), ra.DesiredSize, "ra actual after measure");
Assert.AreEqual (new Size (0,0), rb.DesiredSize, "rb actual after measure");
Assert.AreEqual (new Size (130,60), g.DesiredSize, "g desired 1");
g.Arrange (new Rect (0,0,g.DesiredSize.Width,g.DesiredSize.Height));
Assert.AreEqual (new Size (0,0), ra.DesiredSize, "ra desired 0");
Assert.AreEqual (new Size (130,60), g.DesiredSize, "g desired 1");
Assert.AreEqual (new Rect (0,0,100,50).ToString (), LayoutInformation.GetLayoutSlot (ra).ToString(), "slot");
Assert.AreEqual (new Size (100,50), new Size (ra.ActualWidth, ra.ActualHeight), "ra actual after arrange");
Assert.AreEqual (new Size (20,50), new Size (rb.ActualWidth, rb.ActualHeight), "rb actual after arrange");
Assert.AreEqual (new Size (120,50), new Size (g.ActualWidth, g.ActualHeight), "g actual after arrange");
}
示例12: ConstructPage
/// <summary>
/// This method constructs the document page (visual) to print
/// </summary>
private DocumentPage ConstructPage(Grid content, int pageNumber)
{
if (content == null)
return null;
//Build the page inc header and footer
Grid pageGrid = new Grid();
//Header row
AddGridRow(pageGrid, GridLength.Auto);
//Content row
AddGridRow(pageGrid, new GridLength(1.0d, GridUnitType.Star));
//Footer row
AddGridRow(pageGrid, GridLength.Auto);
ContentControl pageHeader = new ContentControl();
pageHeader.Content = this.CreateDocumentHeader();
pageGrid.Children.Add(pageHeader);
if (content != null)
{
content.SetValue(Grid.RowProperty, 1);
pageGrid.Children.Add(content);
}
ContentControl pageFooter = new ContentControl();
pageFooter.Content = CreateDocumentFooter(pageNumber + 1);
pageFooter.SetValue(Grid.RowProperty, 2);
pageGrid.Children.Add(pageFooter);
double width = this.PageSize.Width - (this.PageMargin.Left + this.PageMargin.Right);
double height = this.PageSize.Height - (this.PageMargin.Top + this.PageMargin.Bottom);
pageGrid.Measure(new Size(width, height));
pageGrid.Arrange(new Rect(this.PageMargin.Left, this.PageMargin.Top, width, height));
//return new DocumentPage(pageGrid);
return new DocumentPage(pageGrid, PageSize, new Rect(content.DesiredSize), new Rect(content.DesiredSize));
}
示例13: ExpandStars_NoRowsOrCols
public void ExpandStars_NoRowsOrCols ()
{
// If the rows/cols are autogenerated, we still expand them
Grid grid = new Grid ();
grid.Children.Add (new Rectangle { Width = 50, Height = 50 });
grid.Measure (new Size (200, 200));
grid.Arrange (new Rect (0, 0, 200, 200));
Assert.AreEqual (200, grid.ActualWidth, "#1");
Assert.AreEqual (200, grid.ActualHeight, "#2");
}
示例14: AutoRow_StarCol
public void AutoRow_StarCol()
{
var g = new Grid();
var child = ContentControlWithChild ();
g.RowDefinitions.Add(new RowDefinition { Height = Star });
g.RowDefinitions.Add(new RowDefinition { Height = Star, MaxHeight = 20 });
g.AddChild(child, 0, 0, 1, 1);
g.Measure(new Size(100, 100));
Assert.AreEqual(new Size(100, 80), child.MeasureOverrideArg, "#1");
}
示例15: ExpandStars_NoRowsOrCols2
public void ExpandStars_NoRowsOrCols2 ()
{
// We don't expand autogenerated rows/cols if we don't have Alignment.Stretch
Grid grid = new Grid { VerticalAlignment = VerticalAlignment.Center, HorizontalAlignment = HorizontalAlignment.Center };
grid.Children.Add (new Rectangle { Width = 50, Height = 50 });
grid.Measure (new Size (200, 200));
grid.Arrange (new Rect (0, 0, 200, 200));
Assert.AreEqual (50, grid.ActualWidth, "#1");
Assert.AreEqual (50, grid.ActualHeight, "#2");
}