本文整理汇总了C#中System.Windows.UIElement.Measure方法的典型用法代码示例。如果您正苦于以下问题:C# UIElement.Measure方法的具体用法?C# UIElement.Measure怎么用?C# UIElement.Measure使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.UIElement
的用法示例。
在下文中一共展示了UIElement.Measure方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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;
}
示例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: 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;
}
示例4: 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;
}
示例5: 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;
}
示例6: 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);
}
示例7: GetElementPixelSize
public System.Windows.Size GetElementPixelSize(UIElement element)
{
Matrix transformToDevice;
var source = PresentationSource.FromVisual(element);
if (source != null)
{
transformToDevice = source.CompositionTarget.TransformToDevice;
}
else
{
using (var newSource = new HwndSource(new HwndSourceParameters()))
{
transformToDevice = newSource.CompositionTarget.TransformToDevice;
}
}
if (element.DesiredSize == new System.Windows.Size())
{
element.Measure(new System.Windows.Size(double.PositiveInfinity, double.PositiveInfinity));
}
return (System.Windows.Size)transformToDevice.Transform((Vector)element.DesiredSize);
}
示例8: 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);
}
示例9: 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);
}
示例10: 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));
}
}
示例11: 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;
}
示例12: MeasureDecoratorChild
public static Size MeasureDecoratorChild (UIElement child, Size constraint, double borderThickness)
{
if (child == null)
return Size.Empty;
child.Measure (GetMeasureSizeToPassToDecoratorChild (constraint, borderThickness));
return GetDesiredDecoratorSize (child.DesiredSize, borderThickness);
}