我有一个带有一些图像的画布,并且我也在使用 DrawGeometry 来绘制一个在时间流逝时正在填充的圆圈。
这就是我在 DrawingContext 中绘制圆圈的方式:
protected override void OnRender(DrawingContext drawingContext)
{
base.OnRender(drawingContext);
MyUtils.RenderProgressClock(drawingContext, clockPosition, 50, gameTime / totalTime);
}
并调用 InvalidateVisual(); 调用它。
但是这样做我的圈子在我的图像后面,我看不到它,我怎么能在它们前面画呢?
我对 WPF 完全陌生,这让我很难过....
这是请求的其他方法代码:
private static PathGeometry GetClockGeometry(Point position, double percentage, double radius)
{
const double innerFactor = 0.90;
double innerRadius = radius * innerFactor;
PathGeometry pie = new PathGeometry();
PathFigure pathFigure = new PathFigure();
pathFigure.StartPoint = new Point(0, -innerRadius);
pathFigure.IsClosed = true;
if (percentage > kMaxClockPercentage)
{
percentage = kMaxClockPercentage;
}
double angle = 360.0 * percentage;
// Starting Point
LineSegment inOutLine = new LineSegment(new Point(0, -radius), true);
// Arc
ArcSegment outerArc = new ArcSegment();
outerArc.IsLargeArc = angle >= 180.0;
outerArc.Point = new Point(Math.Cos((angle - 90) * Math.PI / 180.0) * radius, Math.Sin((angle - 90) * Math.PI / 180.0) * radius);
outerArc.Size = new Size(radius, radius);
outerArc.SweepDirection = SweepDirection.Clockwise;
LineSegment outInLine = new LineSegment(new Point(outerArc.Point.X * innerFactor, outerArc.Point.Y * innerFactor), true);
ArcSegment innerArc = new ArcSegment();
innerArc.IsLargeArc = angle >= 180.0;
innerArc.Point = pathFigure.StartPoint;
innerArc.Size = new Size(innerRadius, innerRadius);
innerArc.SweepDirection = SweepDirection.Counterclockwise;
pathFigure.Segments.Add(inOutLine);
pathFigure.Segments.Add(outerArc);
pathFigure.Segments.Add(outInLine);
pathFigure.Segments.Add(innerArc);
pie.Transform = new TranslateTransform(position.X, position.Y);
pie.Figures.Add(pathFigure);
return pie;
}