이 예제에서는 레이아웃 요소에 사용자 지정 그래픽 효과를 추가하기 위해 Panel의 OnRender 메서드를 재정의하는 방법을 보여 줍니다.
예제
렌더링된 패널 요소에 그래픽 효과를 추가하려면 OnRender 메서드를 사용합니다. 예를 들어 이 메서드를 통해 사용자 지정 테두리나 배경 효과를 추가할 수 있습니다. DrawingContext 개체가 인수로 전달되어 도형, 텍스트, 이미지 또는 동영상을 그리는 메서드를 제공합니다. 따라서 이 메서드는 Panel 개체를 사용자 지정하려는 경우 유용합니다.
' 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
// 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);
}