UIElement.OnRender(DrawingContext) 方法

定義

在衍生類別中覆寫時,參與由配置系統導向的呈現作業。 這個項目的呈現指令不會在叫用此方法時直接使用,而是會加以保留,以便稍後由配置和繪圖做非同步使用。

protected:
 virtual void OnRender(System::Windows::Media::DrawingContext ^ drawingContext);
protected virtual void OnRender (System.Windows.Media.DrawingContext drawingContext);
abstract member OnRender : System.Windows.Media.DrawingContext -> unit
override this.OnRender : System.Windows.Media.DrawingContext -> unit
Protected Overridable Sub OnRender (drawingContext As DrawingContext)

參數

drawingContext
DrawingContext

特定項目的繪圖指令。 此內容會提供給配置系統。

範例

下列程式碼範例示範面板衍生類別的可能實作。

// Override the OnRender call to add a Background and Border to the OffSetPanel
protected override void OnRender(DrawingContext dc)
{
    SolidColorBrush mySolidColorBrush  = new SolidColorBrush();
    mySolidColorBrush.Color = Colors.LimeGreen;
    Pen myPen = new Pen(Brushes.Blue, 10);
    Rect myRect = new Rect(0, 0, 500, 500);
    dc.DrawRectangle(mySolidColorBrush, myPen, myRect);
}
' Override the OnRender call to add a Background and Border to the OffSetPanel
Protected Overrides Sub OnRender(ByVal dc As DrawingContext)
    Dim mySolidColorBrush As New SolidColorBrush()
    mySolidColorBrush.Color = Colors.LimeGreen
    Dim myPen As New Pen(Brushes.Blue, 10)
    Dim myRect As New Rect(0, 0, 500, 500)
    dc.DrawRectangle(mySolidColorBrush, myPen, myRect)
End Sub

備註

這個方法在 類別中沒有預設實作 UIElement

給繼承者的注意事項

OnRender(DrawingContext)您可以覆寫 方法,將先前未定義于邏輯樹狀結構 () 的圖形化專案新增至轉譯的專案,例如效果或裝飾項。 DrawingContext物件會傳遞為引數,其提供繪製圖形、文字、影像或影片的方法。

適用於