Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

UIElement.RenderSize Property

Gets (or sets, but see Remarks) the final render size of this element.

Namespace:  System.Windows
Assembly:  PresentationCore (in PresentationCore.dll)
XMLNS for XAML: http://schemas.microsoft.com/winfx/2006/xaml/presentation, http://schemas.microsoft.com/netfx/2007/xaml/presentation
public Size RenderSize { get; set; }

Property Value

Type: System.Windows.Size
The rendered size for this element.
Important noteImportant

Do not attempt to set this property, either in XAML or in code, if using the WPF framework-level layout system. Nearly all typical application scenarios will use this layout system. The layout system will not respect sizes set in the RenderSize property directly. The RenderSize property is declared writable only to enable certain WPF core-level bridging cases that deliberately circumvent the typical layout protocols, such as support for the Adorner class.

This property can be used for checking the applicable render size within layout system overrides such as OnRender or GetLayoutClip.

A more common scenario is handling the SizeChanged event with the class handler override or the OnRenderSizeChanged event.

The following example shows how a custom adorner uses the RenderSize value in order to create and size the rectangle graphic that defines the adorner, as part of its OnRender implementation.

protected override void OnRender(DrawingContext drawingContext)
{
  // Get a rectangle that represents the desired size of the rendered element 
  // after the rendering pass.  This will be used to draw at the corners of the  
  // adorned element.
  Rect adornedElementRect = new Rect(this.AdornedElement.RenderSize);

  // Some arbitrary drawing implements.
  SolidColorBrush renderBrush = new SolidColorBrush(Colors.Green);
  renderBrush.Opacity = 0.2;
  Pen renderPen = new Pen(new SolidColorBrush(Colors.Navy), 1.5);
  double renderRadius = 5.0;

  // Just draw a circle at each corner.
  drawingContext.DrawEllipse(renderBrush, renderPen, adornedElementRect.TopLeft, renderRadius, renderRadius);
  drawingContext.DrawEllipse(renderBrush, renderPen, adornedElementRect.TopRight, renderRadius, renderRadius);
  drawingContext.DrawEllipse(renderBrush, renderPen, adornedElementRect.BottomLeft, renderRadius, renderRadius);
  drawingContext.DrawEllipse(renderBrush, renderPen, adornedElementRect.BottomRight, renderRadius, renderRadius);
}

.NET Framework

Supported in: 4.5.1, 4.5, 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows Phone 8.1, Windows Phone 8, Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.