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.

這個屬性可以用來檢查版面配置系統覆寫內適用的轉譯大小,例如 OnRenderGetLayoutClipThis 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.

適用於

另請參閱