UIElement.OnRender(DrawingContext) 方法

定義

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

C#
protected virtual void OnRender(System.Windows.Media.DrawingContext drawingContext);

參數

drawingContext
DrawingContext

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

範例

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

C#
// 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);
}

備註

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

給繼承者的注意事項

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

適用於

產品 版本
.NET Framework 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10