UIElement.RenderSize Property


The .NET API Reference documentation has a new home. Visit the .NET API Browser on docs.microsoft.com to see the new experience.

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

Namespace:   System.Windows
Assembly:  PresentationCore (in PresentationCore.dll)

Public Property RenderSize As Size

Property Value

Type: System.Windows.Size

The rendered size for this element.


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 OnRenderimplementation.

 Protected Overrides Sub OnRender(ByVal drawingContext As 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.
Dim adornedElementRect As New Rect(Me.AdornedElement.RenderSize)

' Some arbitrary drawing implements.
Dim renderBrush As New SolidColorBrush(Colors.Green)
renderBrush.Opacity = 0.2
Dim renderPen As New Pen(New SolidColorBrush(Colors.Navy), 1.5)
Dim renderRadius As Double = 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)
 End Sub

.NET Framework
Available since 3.0
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Return to top