本文整理汇总了C#中System.Windows.UIElement.Arrange方法的典型用法代码示例。如果您正苦于以下问题:C# UIElement.Arrange方法的具体用法?C# UIElement.Arrange怎么用?C# UIElement.Arrange使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.UIElement
的用法示例。
在下文中一共展示了UIElement.Arrange方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Arrange
/// <summary>
/// Arranges the adorner element on the specified adorner panel.
/// </summary>
public override void Arrange(AdornerPanel panel, UIElement adorner, Size adornedElementSize)
{
Point p = new Point(0, 0);
if (shape is Line)
{
var s = shape as Line;
double x, y;
if (alignment == PlacementAlignment.BottomRight)
{
x = s.X2;
y = s.Y2;
}
else
{
x = s.X1;
y = s.Y1;
}
p = new Point(x, y);
} else if (shape is Polygon) {
var pg = shape as Polygon;
p = pg.Points[Index];
} else if (shape is Polyline) {
var pg = shape as Polyline;
p = pg.Points[Index];
}
var transform = shape.RenderedGeometry.Transform;
p = transform.Transform(p);
adorner.Arrange(new Rect(p.X - 3.5, p.Y - 3.5, 7, 7));
}
示例2: CreateCursor
public static Cursor CreateCursor(UIElement element, int xHotSpot,
int yHotSpot)
{
element.Measure(new Size(double.PositiveInfinity,
double.PositiveInfinity));
element.Arrange(new Rect(0, 0, element.DesiredSize.Width,
element.DesiredSize.Height));
RenderTargetBitmap rtb =
new RenderTargetBitmap((int)element.DesiredSize.Width,
(int)element.DesiredSize.Height, 96, 96, PixelFormats.Pbgra32);
rtb.Render(element);
PngBitmapEncoder encoder = new PngBitmapEncoder();
encoder.Frames.Add(BitmapFrame.Create(rtb));
MemoryStream ms = new MemoryStream();
encoder.Save(ms);
System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(ms);
ms.Close();
ms.Dispose();
Cursor cur = InternalCreateCursor(bmp, xHotSpot, yHotSpot);
bmp.Dispose();
return cur;
}
示例3: CreateElementScreenshot
private static BitmapSource CreateElementScreenshot(UIElement uiElement)
{
bool measureValid = uiElement.IsMeasureValid;
if (!measureValid)
{
double width = 300;
double height = 300;
FrameworkElement frElement = uiElement as FrameworkElement;
if (frElement != null)
{
if (!Double.IsNaN(frElement.Width))
width = frElement.Width;
if (!Double.IsNaN(frElement.Height))
height = frElement.Height;
}
Size size = new Size(width, height);
uiElement.Measure(size);
uiElement.Arrange(new Rect(size));
}
RenderTargetBitmap bmp = new RenderTargetBitmap(
(int)uiElement.RenderSize.Width, (int)uiElement.RenderSize.Height,
96, 96, PixelFormats.Default);
// this is waiting for dispatcher to perform measure, arrange and render passes
uiElement.Dispatcher.Invoke(((Action)(() => { })), DispatcherPriority.Background);
bmp.Render(uiElement);
return bmp;
}
示例4: ToImageSource
public static ImageSource ToImageSource(UIElement element, System.Windows.Size size)
{
element.Measure(size);
element.Arrange(new Rect(size));
var bmp = new RenderTargetBitmap((int)size.Width, (int)size.Height, 96, 96, PixelFormats.Pbgra32);
bmp.Render(element);
return bmp;
}
示例5: ToBitmapStream
public static MemoryStream ToBitmapStream(UIElement uiElement, double width, double height)
{
var renderTargetBitmap = new RenderTargetBitmap((int)width, (int)height, 96, 96, new PixelFormat());
uiElement.Arrange(new Rect(0, 0, width, height));
renderTargetBitmap.Render(uiElement);
var bitmap = new PngBitmapEncoder();
bitmap.Frames.Add(BitmapFrame.Create(renderTargetBitmap));
var bitmapStream = new MemoryStream();
bitmap.Save(bitmapStream);
return bitmapStream;
}
示例6: SaveElement
public static bool SaveElement(UIElement element, Tile tile)
{
try
{
var side = (tile == Tile.Small) ? 159 : 336;
element.Measure(new Size(side, side));
element.Arrange(new Rect(0, 0, side, side));
var bmp = new WriteableBitmap(side, side);
bmp.Render(element, null);
bmp.Invalidate();
var name = tile.ToString() + Guid.NewGuid() + ".png";
using (var isf = IsolatedStorageFile.GetUserStoreForApplication())
{
if (!isf.DirectoryExists("/CustomLiveTiles"))
{
isf.CreateDirectory("/CustomLiveTiles");
}
using (var myFileStream = isf.CreateFile("shared/shellcontent/" + name))
{
// Encode WriteableBitmap object to a PNG stream.
bmp.WritePng(myFileStream);
}
var filesTodelete =
from f in isf.GetFileNames("shared/shellcontent/" + tile + "*").AsQueryable()
where !f.EndsWith(name)
select f;
foreach (var file in filesTodelete)
{
isf.DeleteFile("shared/shellcontent/" + file);
}
}
SaveTilePart("isostore:/Shared/ShellContent/" + name, tile);
}
catch (Exception)
{
Thread.Sleep(1000);
if (tile == Tile.Small)
{
SaveTilePart(GetDefaultSmallTile(), tile);
}
else
{
SaveTilePart((tile == Tile.Front) ? GetDefaultFrontTile() : GetDefaultBackTile(), tile);
}
return false;
}
return true;
}
示例7: GenerateBitmapSource
public static BitmapSource GenerateBitmapSource(UIElement element, double renderWidth, double renderHeight, bool performLayout)
{
if (performLayout)
{
element.Measure(new Size(renderWidth, renderHeight));
element.Arrange(new Rect(new Size(renderWidth, renderHeight)));
}
var bmp = new RenderTargetBitmap((int)renderWidth, (int)renderHeight, 96, 96, PixelFormats.Pbgra32);
var dv = new DrawingVisual();
using (DrawingContext dc = dv.RenderOpen())
{
dc.DrawRectangle(new VisualBrush(element), null, new Rect(0, 0, renderWidth, renderHeight));
}
bmp.Render(dv);
return bmp;
}
示例8: RenderControlToBitmap
private static void RenderControlToBitmap(UIElement control, [NotNull] string path, int scale = 1,
double maxWidth = double.PositiveInfinity, double maxheight = double.PositiveInfinity)
{
var availableSize = new Size(maxWidth, maxheight);
control.Measure(availableSize);
var desiredSize = control.DesiredSize;
control.Arrange(new Rect(desiredSize));
var dpi = scale * 96;
var bmp = new RenderTargetBitmap((int)desiredSize.Width * scale, (int)desiredSize.Height * scale, dpi, dpi, PixelFormats.Pbgra32);
bmp.Render(control);
var encoder = new PngBitmapEncoder();
encoder.Frames.Add(BitmapFrame.Create(bmp));
var dir = Path.GetDirectoryName(path);
if (dir == null)
throw new InvalidPathException(path);
Directory.CreateDirectory(dir);
using (Stream stm = File.Create(path))
encoder.Save(stm);
}
示例9: ToImage
private async Task ToImage(UIElement element, double width, double height)
{
element.Measure(new Size(width, height));
element.Arrange(new Rect { Height = height, Width = width });
element.UpdateLayout();
var bitmap = new WriteableBitmap((int)width, (int)height);
bitmap.Render(element, null);
bitmap.Invalidate();
await SaveTheImage(bitmap, WideTileUrl);
}
示例10: ToImage
private async Task ToImage(UIElement element)
{
element.Measure(new Size(480, 800));
element.Arrange(new Rect{ Height = 800, Width = 480});
element.UpdateLayout();
var bitmap = new WriteableBitmap(480, 800);
bitmap.Render(element, null);
bitmap.Invalidate();
await SaveTheImage(bitmap);
}
示例11: Arrange
public override void Arrange(AdornerPanel panel, UIElement adorner, Size adornedElementSize)
{
adorner.Arrange(new Rect(adornedElementSize));
}
示例12: ArrangeDecoratorChild
public static Size ArrangeDecoratorChild (UIElement child, Size constraint, double borderThickness)
{
if (child != null) {
double actualBorderThickness = Utility.GetActualDecoratorBorderThickness (borderThickness, constraint.Width, constraint.Height);
child.Arrange (GetArrangeRectToPassToDecoratorChild (constraint, actualBorderThickness));
}
return constraint;
}
示例13: DoLayout
/// <summary>
/// We initiate the layout on the tree rooted at the Visual to which VisualBrush points.
/// </summary>
private void DoLayout(UIElement element)
{
Debug.Assert(element != null);
DependencyObject parent = VisualTreeHelper.GetParent(element);
if (!(element.IsRootElement)
&& (parent == null || parent is Visual3D))
{
//
// PropagateResumeLayout sets the LayoutSuspended flag to false if it were true.
//
UIElement.PropagateResumeLayout(null, element);
element.Measure(new Size(Double.PositiveInfinity, Double.PositiveInfinity));
element.Arrange(new Rect(element.DesiredSize));
}
}
示例14: CreateCursor
public static Cursor CreateCursor(UIElement element, int xHotSpot, int yHotSpot,bool isTransparent)
{
try
{
element.Measure(new Size(double.PositiveInfinity,
double.PositiveInfinity));
element.Arrange(new Rect(0, 0, element.DesiredSize.Width,
element.DesiredSize.Height));
RenderTargetBitmap rtb =
new RenderTargetBitmap((int)element.DesiredSize.Width,
(int)element.DesiredSize.Height, 96, 96,
PixelFormats.Pbgra32);
rtb.Render(element);
PngBitmapEncoder encoder = new PngBitmapEncoder();
encoder.Frames.Add(BitmapFrame.Create(rtb));
MemoryStream ms = new MemoryStream();
encoder.Save(ms);
System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(ms);
if (isTransparent)
{
System.Drawing.Color backColor = bmp.GetPixel(1, 1);
bmp.MakeTransparent(backColor);
}
Cursor cur = InternalCreateCursor(bmp, xHotSpot, yHotSpot);
ms.Close();
ms.Dispose();
//VictorDEBUG
bmp.Dispose();
return cur;
}
catch
{
}
return null;
}
示例15: Arrange
public override void Arrange(AdornerPanel panel, UIElement adorner, Size adornedElementSize)
{
adorner.Arrange(new Rect(p.X, p.Y, adornedElementSize.Width, adornedElementSize.Height));
}