Stroke.DrawCore(DrawingContext, DrawingAttributes) 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
使用指定的 Stroke 在指定的 DrawingContext 上呈现 DrawingAttributes。
protected:
virtual void DrawCore(System::Windows::Media::DrawingContext ^ drawingContext, System::Windows::Ink::DrawingAttributes ^ drawingAttributes);
protected virtual void DrawCore (System.Windows.Media.DrawingContext drawingContext, System.Windows.Ink.DrawingAttributes drawingAttributes);
abstract member DrawCore : System.Windows.Media.DrawingContext * System.Windows.Ink.DrawingAttributes -> unit
override this.DrawCore : System.Windows.Media.DrawingContext * System.Windows.Ink.DrawingAttributes -> unit
Protected Overridable Sub DrawCore (drawingContext As DrawingContext, drawingAttributes As DrawingAttributes)
参数
- drawingContext
- DrawingContext
将在其上呈现笔画的 DrawingContext 对象。
- drawingAttributes
- DrawingAttributes
DrawingAttributes 对象,用于定义所绘制笔画的特性。
示例
下面的示例演示如何在每 StylusPoint 一个 Stroke位置绘制一个圆。 如果属性 FitToCurve 设置为 true
该属性,则 GetBezierStylusPoints 用于获取触笔点。 否则,将使用该 StylusPoints 属性。
protected override void DrawCore(DrawingContext context, DrawingAttributes overrides)
{
// Draw the stroke. Calling base.DrawCore accomplishes the same thing.
Geometry geometry = GetGeometry(overrides);
context.DrawGeometry(new SolidColorBrush(overrides.Color), null, geometry);
StylusPointCollection points;
// Get the stylus points used to draw the stroke. The points used depends on
// the value of FitToCurve.
if (this.DrawingAttributes.FitToCurve)
{
points = this.GetBezierStylusPoints();
}
else
{
points = this.StylusPoints;
}
// Draw a circle at each stylus point.
foreach (StylusPoint p in points)
{
context.DrawEllipse(null, new Pen(Brushes.Black, 1), (Point)p, 5, 5);
}
}
Protected Overrides Sub DrawCore(ByVal context As DrawingContext, _
ByVal overridedAttributes As DrawingAttributes)
' Draw the stroke. Calling base.DrawCore accomplishes the same thing.
Dim geometry As Geometry = GetGeometry(overridedAttributes)
context.DrawGeometry(New SolidColorBrush(overridedAttributes.Color), Nothing, geometry)
Dim points As StylusPointCollection
' Get the stylus points used to draw the stroke. The points used depends on
' the value of FitToCurve.
If Me.DrawingAttributes.FitToCurve Then
points = Me.GetBezierStylusPoints()
Else
points = Me.StylusPoints
End If
' Draw a circle at each stylus point.
Dim p As StylusPoint
For Each p In points
context.DrawEllipse(Nothing, New Pen(Brushes.Black, 1), CType(p, Point), 5, 5)
Next p
End Sub
注解
重写从 DrawCore 类继承 Stroke 时执行自定义绘图的方法。