UIElement.RenderSize 属性

定义

获取(或设置)此元素的最终呈现大小。Gets (or sets) the final render size of this element.

public:
 property System::Windows::Size RenderSize { System::Windows::Size get(); void set(System::Windows::Size value); };
public System.Windows.Size RenderSize { get; set; }
member this.RenderSize : System.Windows.Size with get, set
Public Property RenderSize As Size

属性值

此元素的呈现大小。The rendered size for this element.

示例

下面的示例演示自定义装饰器如何使用 RenderSize 值,以便在其 OnRender 实现中创建定义装饰器的矩形图形并调整其大小。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);
}
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

注解

重要

如果使用的是 WPF 框架级别布局系统,请不要尝试在 XAMLXAML 中或在代码中设置此属性。Do not attempt to set this property, either in XAMLXAML or in code, if using the WPF framework-level layout system. 几乎所有典型的应用程序方案都将使用此布局系统。Nearly all typical application scenarios will use this layout system. 布局系统将不会直接遵循 RenderSize 属性中设置的大小。The layout system will not respect sizes set in the RenderSize property directly. 仅将 RenderSize 属性声明为可写,以启用特意避开典型布局协议的某些 WPF 核心级桥接方案,如对 Adorner 类的支持。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.

此属性可用于在布局系统替代(如 OnRenderGetLayoutClip)内检查适用的呈现大小。This property can be used for checking the applicable render size within layout system overrides such as OnRender or GetLayoutClip.

更常见的情况是处理具有类处理程序重写或 OnRenderSizeChanged 事件的 SizeChanged 事件。A more common scenario is handling the SizeChanged event with the class handler override or the OnRenderSizeChanged event.

适用于

另请参阅