本文整理汇总了C#中UIElement.Measure方法的典型用法代码示例。如果您正苦于以下问题:C# UIElement.Measure方法的具体用法?C# UIElement.Measure怎么用?C# UIElement.Measure使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UIElement
的用法示例。
在下文中一共展示了UIElement.Measure方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetImage
public static RenderTargetBitmap GetImage(UIElement fe, Brush background = null, Size sz = default(Size), int dpi = 144)
{
if (sz.Width < alib.Math.math.ε || sz.Height < alib.Math.math.ε)
{
fe.Measure(util.infinite_size);
sz = fe.DesiredSize; //VisualTreeHelper.GetContentBounds(fe).Size; //
}
DrawingVisual dv = new DrawingVisual();
RenderOptions.SetEdgeMode(dv, EdgeMode.Aliased);
using (DrawingContext ctx = dv.RenderOpen())
{
Rect r = new Rect(0, 0, sz.Width, sz.Height);
if (background != null)
ctx.DrawRectangle(background, null, r);
VisualBrush br = new VisualBrush(fe);
br.AutoLayoutContent = true;
ctx.DrawRectangle(br, null, r);
}
Double f = dpi / 96.0;
RenderTargetBitmap bitmap = new RenderTargetBitmap(
(int)(sz.Width * f) + 1,
(int)(sz.Height * f) + 1,
dpi,
dpi,
PixelFormats.Pbgra32);
bitmap.Render(dv);
return bitmap;
}
示例2: GetElementPixelSize
public Size GetElementPixelSize(UIElement element)
{
Matrix transformToDevice;
var source = PresentationSource.FromVisual(element);
if (source != null)
transformToDevice = source.CompositionTarget.TransformToDevice;
else
using (var src = new HwndSource(new HwndSourceParameters()))
transformToDevice = src.CompositionTarget.TransformToDevice;
if (element.DesiredSize == new Size())
element.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
return (Size)transformToDevice.Transform((Vector)element.DesiredSize);
}
示例3: PopupRoot
public PopupRoot(Point location, UIElement child)
{
this.PresentationSource = PlatformInterface.Instance.CreatePopupPresentationSource();
this.PresentationSource.RootVisual = this;
this.Child = child;
Size clientSize = new Size(double.PositiveInfinity, double.PositiveInfinity);
child.Measure(clientSize);
child.Arrange(new Rect(child.DesiredSize));
this.PresentationSource.BoundingRect = new Rect(location, child.RenderSize);
this.PresentationSource.Show();
child.InvalidateVisual();
}
示例4: OptimizeSize
/// <summary>
/// Optimizes the size of a panel.
/// </summary>
/// <param name="panel">The panel to optimize.</param>
/// <param name="minWidth">The minimum width.</param>
/// <param name="maxWidth">The maximum width.</param>
/// <returns>The desired size.</returns>
private static double OptimizeSize(UIElement panel, double minWidth, double maxWidth)
{
double width;
// optimize size
for (width = minWidth; width < maxWidth; width += 50)
{
panel.Measure(new Size(width, width + 1));
if (panel.DesiredSize.Height <= width)
{
break;
}
}
panel.Arrange(new Rect(0, 0, width, width));
return width;
}
示例5: PopulateConnectionPoints
void PopulateConnectionPoints(UIElement view)
{
view.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
List<ConnectionPoint> connectionPoints = new List<ConnectionPoint>();
if (view is InitialNode)
{
connectionPoints.Add(CreateConnectionPoint(view, 0.5, 1.0, EdgeLocation.Bottom, ConnectionPointType.Outgoing));
connectionPoints.Add(CreateConnectionPoint(view, 0, 0.5, EdgeLocation.Left, ConnectionPointType.Outgoing));
connectionPoints.Add(CreateConnectionPoint(view, 1.0, 0.5, EdgeLocation.Right, ConnectionPointType.Outgoing));
}
else if (view is StateDesigner)
{
ConnectionPointType connectionPointType = ConnectionPointType.Default;
double connectionPointNum = 3;
double connectionPointRatio = 0.25;
if (((StateDesigner)view).IsFinalState())
{
connectionPointType = ConnectionPointType.Incoming;
}
for (int ii = 1; ii <= connectionPointNum; ii++)
{
connectionPoints.Add(CreateConnectionPoint(view, 1, ii * connectionPointRatio, EdgeLocation.Right, connectionPointType));
connectionPoints.Add(CreateConnectionPoint(view, 0, ii * connectionPointRatio, EdgeLocation.Left, connectionPointType));
}
if (!((StateDesigner)view).IsFinalState())
{
connectionPointNum = 5;
connectionPointRatio = 0.167;
}
for (int ii = 1; ii <= connectionPointNum; ii++)
{
connectionPoints.Add(CreateConnectionPoint(view, ii * connectionPointRatio, 0, EdgeLocation.Top, connectionPointType));
connectionPoints.Add(CreateConnectionPoint(view, ii * connectionPointRatio, 1, EdgeLocation.Bottom, connectionPointType));
}
}
StateContainerEditor.SetConnectionPoints(view, connectionPoints);
}
示例6: MeasureChild
/// <summary>
/// Method which measures a given child based on its column width
///
/// For auto kind columns it may actually end up measuring twice
/// once with positive infinity to determine its actual desired width
/// and then again with the available space constraints
/// </summary>
private static void MeasureChild(UIElement child, Size constraint)
{
IProvideDataGridColumn cell = child as IProvideDataGridColumn;
bool isColumnHeader = (child is DataGridColumnHeader);
Size childMeasureConstraint = new Size(double.PositiveInfinity, constraint.Height);
double desiredWidth = 0.0;
bool remeasure = false;
// Allow the column to affect the constraint.
if (cell != null)
{
// For auto kind columns measure with infinity to find the actual desired width of the cell.
DataGridColumn column = cell.Column;
DataGridLength width = column.Width;
if (width.IsAuto ||
(width.IsSizeToHeader && isColumnHeader) ||
(width.IsSizeToCells && !isColumnHeader))
{
child.Measure(childMeasureConstraint);
desiredWidth = child.DesiredSize.Width;
remeasure = true;
}
childMeasureConstraint.Width = column.GetConstraintWidth(isColumnHeader);
}
if (DoubleUtil.AreClose(desiredWidth, 0.0))
{
child.Measure(childMeasureConstraint);
}
Size childDesiredSize = child.DesiredSize;
if (cell != null)
{
DataGridColumn column = cell.Column;
// Allow the column to process the desired size
column.UpdateDesiredWidthForAutoColumn(
isColumnHeader,
DoubleUtil.AreClose(desiredWidth, 0.0) ? childDesiredSize.Width : desiredWidth);
// For auto kind columns measure again with display value if
// the desired width is greater than display value.
DataGridLength width = column.Width;
if (remeasure &&
!DoubleUtil.IsNaN(width.DisplayValue) &&
DoubleUtil.GreaterThan(desiredWidth, width.DisplayValue))
{
childMeasureConstraint.Width = width.DisplayValue;
child.Measure(childMeasureConstraint);
}
}
}
示例7: RenderBitmap
private System.Drawing.Bitmap RenderBitmap(UIElement element)
{
Size size = element.RenderSize;
//RenderTargetBitmap rtb = new RenderTargetBitmap((int)size.Width, (int)size.Height, 96, 96, PixelFormats.Pbgra32);
RenderTargetBitmap rtb = new RenderTargetBitmap(640, 480, 96, 96, PixelFormats.Pbgra32);
rtb.Render(element);
element.Measure(size);
element.Arrange(new Rect(size));
System.Drawing.Bitmap image;
using (var stream = new MemoryStream())
{
var encoder = new JpegBitmapEncoder();
encoder.Frames.Add(BitmapFrame.Create(rtb));
encoder.Save(stream);
image = new System.Drawing.Bitmap(stream);
}
return image;
}
示例8: TestMeasureInvalidation
public static void TestMeasureInvalidation(UIElement element, Action changeProperty)
{
element.Measure(Vector3.Zero);
changeProperty();
Assert.IsFalse(element.IsMeasureValid);
}
示例9: saveToPng
/// <summary>
/// Save an UIElement to a png file
/// </summary>
/// <param name="source">Element to save</param>
/// <param name="filename">png filename</param>
public void saveToPng(UIElement source, String filename)
{
source.Measure(new System.Windows.Size(320.0, 240.0));
source.Arrange(new System.Windows.Rect(0.0, 0.0, 320.0, 240.0));
RenderTargetBitmap rtbImage = new RenderTargetBitmap(320,
240,
96,
96,
PixelFormats.Pbgra32);
rtbImage.Render(source);
PngBitmapEncoder png = new PngBitmapEncoder();
png.Frames.Add(BitmapFrame.Create(rtbImage));
using (Stream stm = File.Create(filename))
{
png.Save(stm);
}
}
示例10: saveToJpg
public static void saveToJpg(UIElement source, string filename, String link, bool include_exif, int quality=100)
{
RenderOptions.SetEdgeMode(source, EdgeMode.Aliased);
RenderOptions.SetBitmapScalingMode(source, BitmapScalingMode.HighQuality);
source.SnapsToDevicePixels = true;
source.Measure(source.RenderSize);//new System.Windows.Size(source.RenderSize.Width, source.RenderSize.Height));
source.Arrange(new Rect(source.RenderSize));//new System.Windows.Rect(0.0, 0.0, 320.0, 240.0));
//RenderOptions.SetBitmapScalingMode(source, BitmapScalingMode.Linear);
RenderTargetBitmap rtbImage = new RenderTargetBitmap(CMSConfig.imagewidth,
CMSConfig.imageheight,
96,
96,
PixelFormats.Default);
rtbImage.Render(source);
JpegBitmapEncoder encoder = new JpegBitmapEncoder();
/* String v = "http://radiodns1.ebu.ch/";
BitmapMetadata m = new BitmapMetadata("jpg");
//m.Comment = v; 37510
m.SetQuery("/app1/ifd/exif:{uint=270}", v);*/
//BitmapFrame outputFrame = BitmapFrame.Create(rtbImage, rtbImage, m, null);
int width = rtbImage.PixelWidth;
int height = rtbImage.PixelHeight;
int stride = width * ((rtbImage.Format.BitsPerPixel + 7) / 8);
byte[] bits = new byte[height * stride];
MemoryStream mem = new MemoryStream();
BitmapEncoder bitmapenc = new BmpBitmapEncoder();
bitmapenc.Frames.Add(BitmapFrame.Create(rtbImage));
bitmapenc.Save(mem);
Bitmap bmp1 = new Bitmap(mem);
ImageCodecInfo jgpEncoder = GetEncoder(ImageFormat.Jpeg);
// Create an Encoder object based on the GUID
// for the Quality parameter category.
System.Drawing.Imaging.Encoder myEncoder =
System.Drawing.Imaging.Encoder.Compression;
System.Drawing.Imaging.Encoder myEncoder2 =
System.Drawing.Imaging.Encoder.Quality;
// Create an EncoderParameters object.
// An EncoderParameters object has an array of EncoderParameter
// objects. In this case, there is only one
// EncoderParameter object in the array.
EncoderParameters myEncoderParameters = new EncoderParameters(2);
EncoderParameter myEncoderParameter = new EncoderParameter(myEncoder, 0L);
EncoderParameter myEncoderParameter2 = new EncoderParameter(myEncoder2, quality);
myEncoderParameters.Param[0] = myEncoderParameter;
myEncoderParameters.Param[1] = myEncoderParameter2;
bmp1.Save(filename, jgpEncoder, myEncoderParameters);
/*
BitmapFrame outputFrame = BitmapFrame.Create(rtbImage);
encoder.QualityLevel = quality;
encoder.Frames.Add(outputFrame);
*/
/*
try
{
using (FileStream file = File.OpenWrite(filename))
{
encoder.Save(file);
file.Close();
}
}
catch(Exception e)
{
Console.WriteLine("Error writting files\n"+e.Message);
}*/
}
示例11: InsertDisplayedElement
private void InsertDisplayedElement(int slot, UIElement element, bool wasNewlyAdded, bool updateSlotInformation)
{
// We can only support creating new rows that are adjacent to the currently visible rows
// since they need to be added to the visual tree for us to Measure them.
Debug.Assert(this.DisplayData.FirstScrollingSlot == -1 || slot >= GetPreviousVisibleSlot(this.DisplayData.FirstScrollingSlot) && slot <= GetNextVisibleSlot(this.DisplayData.LastScrollingSlot));
Debug.Assert(element != null);
if (this._rowsPresenter != null)
{
DataGridRowGroupHeader groupHeader = null;
DataGridRow row = element as DataGridRow;
if (row != null)
{
LoadRowVisualsForDisplay(row);
if (IsRowRecyclable(row))
{
if (!row.IsRecycled)
{
Debug.Assert(!this._rowsPresenter.Children.Contains(element));
_rowsPresenter.Children.Add(row);
}
}
else
{
element.Clip = null;
Debug.Assert(row.Index == RowIndexFromSlot(slot));
}
}
else
{
groupHeader = element as DataGridRowGroupHeader;
Debug.Assert(groupHeader != null); // Nothig other and Rows and RowGroups now
if (groupHeader != null)
{
groupHeader.TotalIndent = (groupHeader.Level == 0) ? 0 : this.RowGroupSublevelIndents[groupHeader.Level - 1];
if (!groupHeader.IsRecycled)
{
_rowsPresenter.Children.Add(element);
}
groupHeader.LoadVisualsForDisplay();
Style lastStyle = _rowGroupHeaderStyles.Count > 0 ? _rowGroupHeaderStyles[_rowGroupHeaderStyles.Count - 1] : null;
EnsureElementStyle(groupHeader, groupHeader.Style, groupHeader.Level < _rowGroupHeaderStyles.Count ? _rowGroupHeaderStyles[groupHeader.Level] : lastStyle);
}
}
// Measure the element and update AvailableRowRoom
element.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
this.AvailableSlotElementRoom -= element.DesiredSize.Height;
if (groupHeader != null)
{
_rowGroupHeightsByLevel[groupHeader.Level] = groupHeader.DesiredSize.Height;
}
if (row != null && this.RowHeightEstimate == DataGrid.DATAGRID_defaultRowHeight && double.IsNaN(row.Height))
{
this.RowHeightEstimate = element.DesiredSize.Height;
}
}
if (wasNewlyAdded)
{
this.DisplayData.CorrectSlotsAfterInsertion(slot, element, false /*isCollapsed*/);
}
else
{
this.DisplayData.LoadScrollingSlot(slot, element, updateSlotInformation);
}
}
示例12: OptimizeSize
private static int OptimizeSize(UIElement panel, int maxWidth)
{
int width;
// optimize size
for (width = 16; width < maxWidth; width = width * 2)
{
panel.Measure(new Size(width, width + 1));
if (panel.DesiredSize.Height <= width)
{
break;
}
}
panel.Arrange(new Rect(0, 0, width, width));
return width;
}
示例13: MeasureChild
/// <summary>
/// Measure child objects such as template parts which are not updated automaticaly on first pass.
/// </summary>
/// <param name="child">Child UIElement</param>
protected void MeasureChild(UIElement child)
{
if (child == null) return;
child.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
}
示例14: AddChild
/// <summary>
/// Adds a child to the HeaderPanel
/// </summary>
/// <param name="child">Child to be added</param>
public async void AddChild(UIElement child)
{
if (child == null)
return;
await Dispatcher.InvokeAsync(() =>
{
child.Opacity = 0;
// Get the Desired size of the child
child.Measure(new Size(Double.PositiveInfinity, Double.PositiveInfinity));
// Check if the child needs to be added at the end or inserted in between
if ((Children.Count == 0) || (Children[Children.Count - 1] == _headerCollection.Last()))
{
child.RenderTransform = CreateTransform(child);
Children.Add(child);
_headerCollection.Add(child);
_addFadeInSb.Begin((FrameworkElement)child);
}
else
{
var lastChild = Children[Children.Count - 1];
Children.Add(child);
var index = _headerCollection.IndexOf(lastChild) + 1;
// Insert the new child after the last child in the header collection
if (index >= 1)
{
var newLocationX = ((TranslateTransform)(((TransformGroup)_headerCollection[index].RenderTransform).Children[0])).X;
_headerCollection.Insert(index, child);
child.RenderTransform = CreateTransform(new Point(newLocationX, 0.0));
InsertChild(child, index + 1);
}
}
// Subscribe to the HeaderItemSelected event and set Active property to false
var headerItem = child as IPivotHeader;
if (headerItem != null)
{
headerItem.HeaderItemSelected += OnHeaderItemSelected;
}
});
}
示例15: saveToJpg
public void saveToJpg(UIElement source, string filename, String link, bool include_exif, int quality=100)
{
source.Measure(new System.Windows.Size(320.0, 240.0));
source.Arrange(new System.Windows.Rect(0.0, 0.0, 320.0, 240.0));
RenderTargetBitmap rtbImage = new RenderTargetBitmap(320,
240,
96,
96,
PixelFormats.Pbgra32);
rtbImage.Render(source);
JpegBitmapEncoder encoder = new JpegBitmapEncoder();
/* String v = "http://radiodns1.ebu.ch/";
BitmapMetadata m = new BitmapMetadata("jpg");
//m.Comment = v; 37510
m.SetQuery("/app1/ifd/exif:{uint=270}", v);*/
//BitmapFrame outputFrame = BitmapFrame.Create(rtbImage, rtbImage, m, null);
BitmapFrame outputFrame = BitmapFrame.Create(rtbImage);
//outputFrame.Metadata.set
encoder.Frames.Add(outputFrame);
encoder.QualityLevel = quality;
try
{
using (FileStream file = File.OpenWrite(filename))
{
encoder.Save(file);
}
}
catch(Exception e)
{
Console.WriteLine("Error writting files\n"+e.Message);
}
}