本文整理汇总了C#中System.Windows.Controls.Grid.Arrange方法的典型用法代码示例。如果您正苦于以下问题:C# Grid.Arrange方法的具体用法?C# Grid.Arrange怎么用?C# Grid.Arrange使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Controls.Grid
的用法示例。
在下文中一共展示了Grid.Arrange方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateTileBackground
public static string CreateTileBackground(this Project project)
{
Grid grid = new Grid();
Rectangle rect = new Rectangle();
rect.Width = 173;
rect.Height = 173;
rect.Fill = new SolidColorBrush(project.Color.ToColor());
TextBlock text = new TextBlock();
text.Text = "TASK";
text.Foreground = new SolidColorBrush(Colors.White);
text.FontSize = 32;
grid.Children.Add(rect);
grid.Children.Add(text);
grid.Arrange(new Rect(0d, 0d, 173d, 173d));
WriteableBitmap wbmp = new WriteableBitmap(grid, null);
string tiledirectory = "tiles";
string fullPath = tiledirectory + @"/" + project.Name + ".jpg";
using (var store = IsolatedStorageFile.GetUserStoreForApplication())
{
if (!store.DirectoryExists(tiledirectory))
{
store.CreateDirectory(tiledirectory);
}
using (var stream = store.OpenFile(fullPath, System.IO.FileMode.OpenOrCreate))
{
wbmp.SaveJpeg(stream, 173, 173, 0, 100);
}
}
return "isostore:/" + fullPath;
}
开发者ID:WindowsPhone-8-TrainingKit,项目名称:HOL-BackgroundTransferService,代码行数:35,代码来源:ShellTileHelpersUI.cs
示例2: RenderBrush
/// <summary>
/// Renders the brush.
/// </summary>
/// <param name="path">
/// The path.
/// </param>
/// <param name="brush">
/// The brush.
/// </param>
/// <param name="w">
/// The w.
/// </param>
/// <param name="h">
/// The h.
/// </param>
public static void RenderBrush(string path, Brush brush, int w, int h)
{
var ib = brush as ImageBrush;
if (ib != null)
{
var bi = ib.ImageSource as BitmapImage;
if (bi != null)
{
w = bi.PixelWidth;
h = bi.PixelHeight;
}
}
var bmp = new RenderTargetBitmap(w, h, 96, 96, PixelFormats.Pbgra32);
var rect = new Grid
{
Background = brush,
Width = 1,
Height = 1,
LayoutTransform = new ScaleTransform(w, h)
};
rect.Arrange(new Rect(0, 0, w, h));
bmp.Render(rect);
var encoder = new PngBitmapEncoder();
encoder.Frames.Add(BitmapFrame.Create(bmp));
using (Stream stm = File.Create(path))
{
encoder.Save(stm);
}
}
示例3: 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();
}
示例4: 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);
}
示例5: 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);
}
示例6: 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);
}
}
示例7: ExecuteThread
public string ExecuteThread(FileItem item,string infile, string dest, ValuePairEnumerator configData)
{
try
{
var conf = new OverlayTransformViewModel(configData);
using (var fileStream = new MemoryStream(File.ReadAllBytes(infile)))
{
BitmapDecoder bmpDec = BitmapDecoder.Create(fileStream,
BitmapCreateOptions.PreservePixelFormat,
BitmapCacheOption.OnLoad);
WriteableBitmap writeableBitmap = BitmapFactory.ConvertToPbgra32Format(bmpDec.Frames[0]);
writeableBitmap.Freeze();
Grid grid = new Grid
{
Width = writeableBitmap.PixelWidth,
Height = writeableBitmap.PixelHeight,
ClipToBounds = true,
SnapsToDevicePixels = true
};
grid.UpdateLayout();
var size = new Size(writeableBitmap.PixelWidth, writeableBitmap.PixelWidth);
grid.Measure(size);
grid.Arrange(new Rect(size));
Image overlay = new Image();
Image image = new Image { Width = writeableBitmap.PixelWidth, Height = writeableBitmap.PixelHeight };
image.BeginInit();
image.Source = writeableBitmap;
image.EndInit();
image.Stretch = Stretch.Fill;
grid.Children.Add(image);
grid.UpdateLayout();
string text = "";
if (!string.IsNullOrEmpty(conf.Text))
{
Regex regPattern = new Regex(@"\[(.*?)\]", RegexOptions.Singleline);
MatchCollection matchX = regPattern.Matches(conf.Text);
text = matchX.Cast<Match>()
.Aggregate(conf.Text,
(current1, match) =>
item.FileNameTemplates.Where(
template =>
String.Compare(template.Name, match.Value,
StringComparison.InvariantCultureIgnoreCase) == 0).Aggregate(current1,
(current, template) => current.Replace(match.Value, template.Value)));
}
TextBlock textBlock = new TextBlock
{
Text = text,
Foreground = (SolidColorBrush) new BrushConverter().ConvertFromString(conf.FontColor),
FontFamily = (FontFamily) new FontFamilyConverter().ConvertFromString(conf.Font),
FontSize = conf.FontSize,
Opacity = conf.Transparency/100.00
};
if (conf.A11)
{
textBlock.HorizontalAlignment = HorizontalAlignment.Left;
textBlock.VerticalAlignment = VerticalAlignment.Top;
}
if (conf.A12)
{
textBlock.HorizontalAlignment = HorizontalAlignment.Center;
textBlock.VerticalAlignment = VerticalAlignment.Top;
}
if (conf.A13)
{
textBlock.HorizontalAlignment = HorizontalAlignment.Right;
textBlock.VerticalAlignment = VerticalAlignment.Top;
}
if (conf.A21)
{
textBlock.HorizontalAlignment = HorizontalAlignment.Left;
textBlock.VerticalAlignment = VerticalAlignment.Center;
}
if (conf.A22)
{
textBlock.HorizontalAlignment = HorizontalAlignment.Center;
textBlock.VerticalAlignment = VerticalAlignment.Center;
}
if (conf.A23)
{
textBlock.HorizontalAlignment = HorizontalAlignment.Right;
textBlock.VerticalAlignment = VerticalAlignment.Center;
}
if (conf.A31)
{
textBlock.HorizontalAlignment = HorizontalAlignment.Left;
textBlock.VerticalAlignment = VerticalAlignment.Bottom;
}
if (conf.A32)
{
textBlock.HorizontalAlignment = HorizontalAlignment.Center;
textBlock.VerticalAlignment = VerticalAlignment.Bottom;
}
if (conf.A33)
{
textBlock.HorizontalAlignment = HorizontalAlignment.Right;
//.........这里部分代码省略.........
示例8: PrintOnClick
void PrintOnClick(object sender, RoutedEventArgs args)
{
PrintDialog dlg = new PrintDialog();
if ((bool)dlg.ShowDialog().GetValueOrDefault())
{
// Create Grid panel.
Grid grid = new Grid();
// Define five auto-sized rows and columns.
for (int i = 0; i < 5; i++)
{
ColumnDefinition coldef = new ColumnDefinition();
coldef.Width = GridLength.Auto;
grid.ColumnDefinitions.Add(coldef);
RowDefinition rowdef = new RowDefinition();
rowdef.Height = GridLength.Auto;
grid.RowDefinitions.Add(rowdef);
}
// Give the Grid a gradient brush.
grid.Background =
new LinearGradientBrush(Colors.Gray, Colors.White,
new Point(0, 0), new Point(1, 1));
// Every program needs a bit of randomness.
Random rand = new Random();
// Fill the Grid with 25 buttons.
for (int i = 0; i < 25; i++)
{
Button btn = new Button();
btn.FontSize = 12 + rand.Next(8);
btn.Content = "Button No. " + (i + 1);
btn.HorizontalAlignment = HorizontalAlignment.Center;
btn.VerticalAlignment = VerticalAlignment.Center;
btn.Margin = new Thickness(6);
grid.Children.Add(btn);
Grid.SetRow(btn, i % 5);
Grid.SetColumn(btn, i / 5);
}
// Size the Grid.
grid.Measure(new Size(Double.PositiveInfinity,
Double.PositiveInfinity));
Size sizeGrid = grid.DesiredSize;
// Determine point for centering Grid on page.
Point ptGrid =
new Point((dlg.PrintableAreaWidth - sizeGrid.Width) / 2,
(dlg.PrintableAreaHeight - sizeGrid.Height) / 2);
// Layout pass.
grid.Arrange(new Rect(ptGrid, sizeGrid));
// Now print it.
dlg.PrintVisual(grid, Title);
}
}
示例9: MakeCollage
private void MakeCollage(IEnumerable<string> imageFilenames, string outputFilename) {
var collage = new Grid();
foreach (var filename in imageFilenames) {
collage.Children.Add(new Image {
Source = LoadBitmapImage(filename),
HorizontalAlignment = HorizontalAlignment.Center,
VerticalAlignment = VerticalAlignment.Center,
});
}
collage.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
collage.Arrange(new Rect(0d, 0d, collage.DesiredSize.Width, collage.DesiredSize.Height));
var bitmap = new RenderTargetBitmap((int)collage.DesiredSize.Width, (int)collage.DesiredSize.Height,
96, 96, PixelFormats.Default);
bitmap.Render(collage);
bitmap.SaveAsPng(outputFilename);
}
示例10: NegativeMargin
public void NegativeMargin ()
{
var grid = new Grid ();
var poker = new LayoutPoker {
Margin = new Thickness (-1, -1, -1, -1),
MeasureOverrideResult = new Size (80, 80),
ArrangeOverrideResult = new Size (80, 80)
};
grid.Children.Add (poker);
grid.Measure (infinity);
grid.Arrange (new Rect (0, 0, 50, 50));
Assert.AreEqual (new Size (78, 78), grid.DesiredSize, "#1");
Assert.AreEqual (new Size (78, 78), poker.DesiredSize, "#2");
Assert.AreEqual (new Size (78, 78), new Size (grid.ActualWidth, grid.ActualHeight), "#3");
Assert.AreEqual (new Size (80, 80), new Size (poker.ActualWidth, poker.ActualHeight), "#4");
Assert.AreEqual (new Size (78, 78), grid.RenderSize, "#5");
Assert.AreEqual (new Size (80, 80), poker.RenderSize, "#6");
RectangleGeometry geom = LayoutInformation.GetLayoutClip (grid) as RectangleGeometry;
Assert.IsNotNull (geom, "#7");
Assert.AreEqual (new Rect (0, 0, 50, 50), geom.Rect, "#8");
Assert.IsNull (LayoutInformation.GetLayoutClip (poker), "#9");
Assert.AreEqual (new Rect (0, 0, 50, 50), LayoutInformation.GetLayoutSlot (grid), "#10");
Assert.AreEqual (new Rect (0, 0, 78, 78), LayoutInformation.GetLayoutSlot (poker), "#11");
}
示例11: btnMoveRight_Loaded
private void btnMoveRight_Loaded(object sender, RoutedEventArgs e)
{
//take screenshot
Grid grd = new Grid();
grd.Background = (ImageBrush)this.FindResource("HeaderBrush");
int height = 100;
grd.Height = height;
grd.Width = tabsGrid.ActualWidth;
tabsGrid.Children.Add(grd);
grd.Measure(new Size(tabsGrid.ActualWidth, height));
Size size = grd.DesiredSize;
grd.Arrange(new Rect(new Point(0, 0), size));
byte[] img = TextureUtil.TakeScreenShot(tabsGrid, (int)tabsGrid.ActualWidth, (int)tabsGrid.ActualHeight);
//crop image
Point p = btnMoveRight.TranslatePoint(new Point(0, 0), mainGrid);
img = TextureUtil.CropImageFile(img, 80, height - 2, (int)p.X, 0);
//create brush
BitmapImage bmImage = new BitmapImage();
bmImage.BeginInit();
bmImage.StreamSource = new MemoryStream(img);
bmImage.CreateOptions = BitmapCreateOptions.None;
bmImage.CacheOption = BitmapCacheOption.Default;
bmImage.EndInit();
btnMoveRight.Background = new ImageBrush(bmImage);
tabsGrid.Children.Remove(grd);
}
示例12: CreateEmptyBackground
private string CreateEmptyBackground(Grid grid)
{
TextBlock block = grid.Children[1] as TextBlock;
block.Text = "For more?";
block.FontSize = 23.0;
(grid.Children[0] as TextBlock).Text = string.Empty;
(grid.Children[2] as TextBlock).Text = "Turn on Live Tile!";
(grid.Children[3] as TextBlock).Text = string.Empty;
grid.Arrange(new Rect(0.0, 0.0, 173.0, 173.0));
TileInfoUpdatingAgent.SavePicture(grid, "Shared/ShellContent/tiles", "Shared/ShellContent/tiles/LiveTile.png");
return "isostore:/Shared/ShellContent/tiles/LiveTile.png";
}
示例13: CreateBackground
public string CreateBackground(Grid grid)
{
if (grid != null)
{
TextBlock block = grid.Children[0] as TextBlock;
string[] strArray = LocalizedStrings.GetLanguageInfoByKey("FormatterForExpenseInShellTile").Split(new char[] { ',' });
block.Text = System.DateTime.Today.ToString(strArray[0]) + strArray[1];
TextBlock block2 = grid.Children[1] as TextBlock;
block2.Text = this.TodaySummary.TotalExpenseAmountInfo;
TextBlock block3 = grid.Children[2] as TextBlock;
block3.Text = LocalizedStrings.GetCombinedText(AppResources.CurrentWeek, AppResources.Expense, false).ToLowerInvariant();
(grid.Children[3] as TextBlock).Text = this.ThisWeekSummary.TotalExpenseAmountInfo;
grid.Arrange(new Rect(0.0, 0.0, 173.0, 173.0));
TileInfoUpdatingAgent.SavePicture(grid, "Shared/ShellContent/tiles", "Shared/ShellContent/tiles/LiveTile.png");
}
return "isostore:/Shared/ShellContent/tiles/LiveTile.png";
}
示例14: 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");
}
示例15: 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));
}