本文整理汇总了C#中System.Windows.FrameworkElement.UpdateLayout方法的典型用法代码示例。如果您正苦于以下问题:C# FrameworkElement.UpdateLayout方法的具体用法?C# FrameworkElement.UpdateLayout怎么用?C# FrameworkElement.UpdateLayout使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.FrameworkElement
的用法示例。
在下文中一共展示了FrameworkElement.UpdateLayout方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: UpdateAndMeasure
public Size UpdateAndMeasure(FrameworkElement element)
{
element.LayoutTransform = ChildRenderTransform;
element.UpdateLayout();
element.Measure(new Size(BodySize.Width, double.PositiveInfinity));
return element.DesiredSize;
}
示例2: CenterScrollViewer
public void CenterScrollViewer(FrameworkElement controlToCenter = null)
{
if (controlToCenter == null)
{
HorizontalOffset = lessonContainerComponent.ScrollableWidth/2.0;
VerticalOffset = lessonContainerComponent.ScrollableWidth/2.0;
return;
}
controlToCenter.UpdateLayout();
if (controlToCenter.ActualWidth < lessonContainerComponent.ViewportWidth)
{
// Horizontal center the content of the scrollviewer
HorizontalOffset = (lessonContainerComponent.ScrollableWidth - controlToCenter.Margin.Right)/2.0;
}
else
{
// Left center the content of the scrollviewer (with 25px left-margin)
HorizontalOffset = ((drawingAreaComponent.ActualWidth - controlToCenter.ActualWidth -
controlToCenter.Margin.Right)/2.0) - 25;
}
if (controlToCenter.ActualHeight < lessonContainerComponent.ViewportHeight)
{
// Vertical center the content of the scrollviewer
VerticalOffset = (lessonContainerComponent.ScrollableHeight - controlToCenter.Margin.Right)/2.0;
}
else
{
// Top center the content of the scrollviewer (with 25px top-margin)
VerticalOffset = ((drawingAreaComponent.ActualHeight - controlToCenter.ActualHeight -
controlToCenter.Margin.Right)/2.0) - 25;
}
}
示例3: RealizeFrameworkElement
public static void RealizeFrameworkElement(FrameworkElement fe) {
var size = new Size(double.MaxValue, double.MaxValue);
if (fe.Width > 0 && fe.Height > 0) size = new Size(fe.Width, fe.Height);
fe.Measure(size);
fe.Arrange(new Rect(new Point(), fe.DesiredSize));
fe.UpdateLayout();
}
示例4: ForceRenderIfElementIsInsideAHiddenListView
private static void ForceRenderIfElementIsInsideAHiddenListView(FrameworkElement element)
{
//need this condition to force rendering for items that are non visual that we've been swapping
//in and out of the hidden ListView.
if (element is ListViewItem)
{
if (element.ActualWidth == 0.0 || element.ActualHeight == 0.0)
{
element.UpdateLayout();
}
}
}
示例5: SaveImageSource
public static BitmapSource SaveImageSource(FrameworkElement obj, int width, int height)
{
// Save current canvas transform
obj.LayoutTransform = null;
obj.Width = width;
obj.Height = height;
obj.UpdateLayout();
obj.UpdateLayout();
// fix margin offset as well
Thickness margin = obj.Margin;
obj.Margin = new Thickness(0, 0,
margin.Right - margin.Left, margin.Bottom - margin.Top);
// Get the size of canvas
Size size = new Size(width, height);
// force control to Update
obj.Measure(size);
obj.Arrange(new Rect(size));
RenderTargetBitmap bmp = new RenderTargetBitmap(
width, height, 96, 96, PixelFormats.Pbgra32);
bmp.Render(obj);
//// return values as they were before
//obj.LayoutTransform = transform;
//obj.Margin = margin;
obj = null;
return bmp;
}
示例6: OpenParentRibbonGroupDropDownSync
public static void OpenParentRibbonGroupDropDownSync(FrameworkElement fe, bool templateApplied)
{
if (!templateApplied)
{
// Apply template if not yet applied.
fe.ApplyTemplate();
}
// Get the Parent RibbonGroup and open its dropdown if needed.
RibbonGroup ribbonGroup = TreeHelper.FindAncestor(fe, delegate(DependencyObject element) { return (element is RibbonGroup); }) as RibbonGroup;
if (ribbonGroup == null)
{
ribbonGroup = TreeHelper.FindLogicalAncestor<RibbonGroup>(fe);
}
if (ribbonGroup != null &&
ribbonGroup.IsCollapsed &&
!ribbonGroup.IsDropDownOpen)
{
ribbonGroup.IsDropDownOpen = true;
fe.UpdateLayout();
}
}
示例7: CopyFrameworkElementToStream
public static Stream CopyFrameworkElementToStream(FrameworkElement copyTarget,
double width, double height, BitmapEncoder enc,
Stream outStream, double? dpi)
{
if (copyTarget == null)
return outStream;
// Store the Frameworks current layout transform, as this will be restored later
Transform storedTransform = copyTarget.LayoutTransform;
// Set the layout transform to unity to get the nominal width and height
copyTarget.LayoutTransform = new ScaleTransform(1, 1);
copyTarget.UpdateLayout();
double baseHeight = copyTarget.ActualHeight;
double baseWidth = copyTarget.ActualWidth;
// Now scale the layout to fit the bitmap
copyTarget.LayoutTransform =
new ScaleTransform(baseWidth/width, baseHeight/height);
copyTarget.UpdateLayout();
// Render to a Bitmap Source, the DPI is changed for the
// render target as a way of scaling the FrameworkElement
var rtb = new RenderTargetBitmap(
(int) width,
(int) height,
96d*width/baseWidth,
96d*height/baseHeight,
PixelFormats.Default);
rtb.Render(copyTarget);
// Convert from a WinFX Bitmap Source to a Win32 Bitamp
if (dpi == null)
{
enc.Frames.Add(BitmapFrame.Create(rtb));
}
else
{
// Change the DPI
var brush = new ImageBrush(BitmapFrame.Create(rtb));
var rtbDpi = new RenderTargetBitmap(
(int) width, // PixelWidth
(int) height, // PixelHeight
(double) dpi, // DpiX
(double) dpi, // DpiY
PixelFormats.Default);
var drawVisual = new DrawingVisual();
using (DrawingContext dc = drawVisual.RenderOpen())
{
dc.DrawRectangle(brush, null,
new Rect(0, 0, rtbDpi.Width, rtbDpi.Height));
}
rtbDpi.Render(drawVisual);
enc.Frames.Add(BitmapFrame.Create(rtbDpi));
}
enc.Save(outStream);
// Restore the Framework Element to it's previous state
copyTarget.LayoutTransform = storedTransform;
copyTarget.UpdateLayout();
return outStream;
}
示例8: CopyFrameworkElementToStreamNew
/// <summary>
/// Note RenderTargetBitmap has a huge memory leak that was fixed in .NET 4.0
/// but only if you reference Winforms.
/// </summary>
/// <param name="copyTarget"></param>
/// <param name="width"></param>
/// <param name="height"></param>
/// <param name="enc"></param>
/// <param name="outStream"></param>
/// <param name="dpi"></param>
/// <returns></returns>
public static Stream CopyFrameworkElementToStreamNew(FrameworkElement copyTarget,
double width, double height, BitmapEncoder enc, Stream outStream, double dpi) {
// Store the Frameworks current layout transform, as this will be restored later
Transform storedLayoutTransform = copyTarget.LayoutTransform;
Transform storedRenderTransform = copyTarget.RenderTransform;
double scale = dpi / 96.0;
width *= scale;
height *= scale;
copyTarget.RenderTransform = new ScaleTransform(scale, scale);
// Set the layout transform to unity to get the nominal width and height
copyTarget.LayoutTransform = new ScaleTransform(1, 1);
copyTarget.UpdateLayout();
RenderTargetBitmap rtb;
copyTarget.LayoutTransform =
new ScaleTransform(1.0 / scale, 1.0 / scale);
copyTarget.UpdateLayout();
// Render to a Bitmap Source, note that the DPI is changed for the
// render target as a way of scaling the FrameworkElement
rtb = new RenderTargetBitmap(
(int)width,
(int)height,
dpi,
dpi,
PixelFormats.Default);
rtb.Render(copyTarget);
// Convert from a WinFX Bitmap Source to a Win32 Bitamp
enc.Frames.Add(BitmapFrame.Create(rtb));
enc.Save(outStream);
// Restore the Framework Element to it's previous state
copyTarget.LayoutTransform = storedLayoutTransform;
copyTarget.RenderTransform = storedRenderTransform;
copyTarget.UpdateLayout();
return outStream;
}
示例9: CopyFrameworkElementToStream
/// <summary>
/// Copies a framework element to a bitmap stored in a memory stream
/// </summary>
/// <param name="copyTarget"></param>
/// <param name="width"></param>
/// <param name="height"></param>
/// <param name="enc"></param>
/// <param name="str"></param>
/// <returns></returns>
public static void CopyFrameworkElementToStream(FrameworkElement copyTarget, double width, double height, BitmapEncoder enc, Stream str)
{
// Store the Frameworks current layout transform, as this will be restored later
Transform storedTransform = copyTarget.LayoutTransform;
// Set the layout transform to unity to get the nominal width and height
copyTarget.LayoutTransform = new ScaleTransform(1, 1);
copyTarget.UpdateLayout();
double baseHeight = copyTarget.ActualHeight;
double baseWidth = copyTarget.ActualWidth;
// Now scale the layout to fit the bitmap
copyTarget.LayoutTransform =
new ScaleTransform(baseWidth / width, baseHeight / height);
copyTarget.UpdateLayout();
// Render to a Bitmap Source, note that the DPI is changed for the
// render target as a way of scaling the FrameworkElement
RenderTargetBitmap rtb = new RenderTargetBitmap(
(int)width,
(int)height,
96d * width / baseWidth,
96d * height / baseHeight,
PixelFormats.Default);
rtb.Render(copyTarget);
// Convert from a WPF Bitmap Source to a Win32 Bitamp
enc.Frames.Add(BitmapFrame.Create(rtb));
enc.Save(str);
// Restore the Framework Element to it's previous state
copyTarget.LayoutTransform = storedTransform;
copyTarget.UpdateLayout();
}
示例10: AttachTreeControlToParent
private void AttachTreeControlToParent(FrameworkElement control, FrameworkElement parent)
{
if(parent != null)
{
Line line = new Line() { StrokeThickness = 2.5, Stroke = Brushes.Black, SnapsToDevicePixels = true };
line.SetValue(RenderOptions.EdgeModeProperty, EdgeMode.Aliased);
m_canvas_messageTree.Children.Add(line);
parent.LayoutUpdated += (x, y) =>
{
line.Y1 = Canvas.GetTop(parent) + parent.ActualHeight;
line.X1 = Canvas.GetLeft(parent) + (parent.ActualWidth / 2);
};
parent.UpdateLayout();
control.LayoutUpdated += (x, y) =>
{
line.Y2 = Canvas.GetTop(control);
line.X2 = Canvas.GetLeft(control) + (control.ActualWidth / 2);
};
control.UpdateLayout();
}
}
示例11: PrepareForExport
private static void PrepareForExport(FrameworkElement element)
{
if (element.ActualWidth == 0 && element.ActualHeight == 0)
{
double width = element.Width > 0 ? element.Width : 500;
double height = element.Height > 0 ? element.Height : 300;
element.Measure(Size.Empty);
element.Measure(new Size(width, height));
element.Arrange(new Rect(0, 0, width, height));
element.UpdateLayout();
}
}
示例12: SetBlackImage
static void SetBlackImage(FrameworkElement element)
{
if (element is Panel)
{
var shapes = ((Panel)element).Children.OfType<System.Windows.Shapes.Shape>();
var blackBrush = new SolidColorBrush(Colors.Black);
foreach (var shape in shapes)
{
shape.Fill = blackBrush;
}
element.UpdateLayout();
}
}
示例13: GenerateImage
public static BitmapImage GenerateImage(FrameworkElement pFE, int pWidth, int pHeight)
{;
pFE.Width = pWidth;
pFE.Height = pHeight;
System.Windows.Size theTargetSize = new System.Windows.Size(pWidth, pHeight);
pFE.Measure(new System.Windows.Size(double.PositiveInfinity, double.PositiveInfinity));
pFE.Arrange(new Rect(theTargetSize));
// to affect the changes in the UI, you must call this method at the end to apply the new changes
pFE.UpdateLayout();
pFE.InvalidateMeasure();
pFE.InvalidateArrange();
pFE.InvalidateVisual();
var imgEncoder = new PngBitmapEncoder();
imgEncoder.Interlace = PngInterlaceOption.Off;
RenderTargetBitmap bmpSource = new RenderTargetBitmap((int)pWidth, (int)pHeight, 96, 96, PixelFormats.Pbgra32);
bmpSource.Render(pFE);
imgEncoder.Frames.Add(BitmapFrame.Create(bmpSource));
BitmapImage result = new BitmapImage();
using (var stream = new MemoryStream())
{
imgEncoder.Save(stream);
stream.Seek(0, SeekOrigin.Begin);
result.BeginInit();
// According to MSDN, "The default OnDemand cache option retains access to the stream until the image is needed."
// Force the bitmap to load right now so we can dispose the stream.
result.CacheOption = BitmapCacheOption.OnLoad;
result.StreamSource = stream;
result.EndInit();
// result.Freeze();
}
return result;
}
示例14: BringIntoViewScrollingCell
private bool BringIntoViewScrollingCell( Cell cell, FrameworkElement container, RequestBringIntoViewEventArgs e )
{
Debug.Assert( cell != null );
Debug.Assert( container != null );
// The cell must be measured/arranged for the BringIntoView to correctly reacts
if( this.ForceScrollingCellToLayout( cell ) )
{
container.UpdateLayout();
}
var fixedWidth = this.GetFixedWidth();
var scrollingPanel = this.ScrollingCellsDecorator;
var scrollingArea = new Rect( scrollingPanel.TranslatePoint( FixedCellPanel.EmptyPoint, this ),
new Size( this.ParentScrollViewer.ViewportWidth - fixedWidth, scrollingPanel.ActualHeight ) );
var cellArea = new Rect( cell.TranslatePoint( FixedCellPanel.EmptyPoint, this ),
new Size( cell.ParentColumn.ActualWidth, cell.ActualHeight ) );
// The cell is larger than the scrolling area.
if( cellArea.Width > scrollingArea.Width )
{
var targetObject = e.TargetObject as UIElement;
var targetRect = e.TargetRect;
// Try to narrow the area within the cell that we clearly want to bring into view.
if( ( targetObject != null ) && ( targetObject != cell || !targetRect.IsEmpty ) )
{
Debug.Assert( targetObject.IsDescendantOf( cell ) );
if( targetRect.IsEmpty )
{
targetRect = new Rect( new Point( 0d, 0d ), targetObject.RenderSize );
}
if( targetRect.Width <= scrollingArea.Width )
{
var offset = targetObject.TranslatePoint( FixedCellPanel.EmptyPoint, cell );
var location = cellArea.Location;
location.Offset( offset.X, offset.Y );
cellArea.Location = location;
cellArea.Size = targetRect.Size;
}
}
}
if( ( cellArea.Left <= scrollingArea.Left ) && ( cellArea.Right >= scrollingArea.Right ) )
{
// Ensure to bring the container into view vertically.
container.BringIntoView();
}
else if( cellArea.Left < scrollingArea.Left )
{
// The ScrollViewer's extent width includes the fixed section. We must offset the target area or the cell
// will come into view under the fixed panel.
cellArea.X -= fixedWidth;
this.BringIntoView( cellArea );
}
else if( cellArea.Right > scrollingArea.Right )
{
this.BringIntoView( cellArea );
}
// The cell is fully visible.
else
{
// Ensure to bring the container into view vertically.
container.BringIntoView();
}
return true;
}
示例15: CallUpdateLayout
public void CallUpdateLayout(FrameworkElement el)
{
el.UpdateLayout();
}