Pregunta

tengo un descendiente de FrameworkElement con los siguientes métodos:

class HexVisual : FrameworkElement {

    /* ... */

    private PathGeometry GetHexGeometry(Hexagon Hexagon) {
        var geometry = default(PathGeometry);
        if(mHexGeometries.TryGetValue(Hexagon, out geometry)){
            return geometry;
        }

        PathFigure figure = new PathFigure();

        int i = 0;
        foreach (Point point in Hexagon.Polygon.Points) {
            if (i == 0) {
                figure.StartPoint = point;
                i++;
                continue;
            }

            figure.Segments.Add(new LineSegment(point, true));
        }

        geometry = new PathGeometry();
        geometry.Figures.Add(figure);
        geometry.FillRule = FillRule.Nonzero;

        return geometry;

    }

    private DrawingVisual CreateHexVisual() {
        DrawingVisual visual = new DrawingVisual();
        using (DrawingContext context = visual.RenderOpen()) {
            context.DrawGeometry(BorderBrush, BorderPen, mHexGeometry);
        }

        return visual;

    }
}

Cuando agrego este objeto visual al Canvas, obtengo un hexágono relleno en lugar de solo el trazo (borde).¿Qué estoy haciendo mal aquí que hace que la geometría se llene?

¿Fue útil?

Solución

No estoy seguro de si realmente entiendo su pregunta, porque no puede "agregar visuales a un lienzo", pero quizás simplemente establezca BorderBrush en null o Transparent, o reemplace

context.DrawGeometry(BorderBrush, BorderPen, mHexGeometry);

con

context.DrawGeometry(null, BorderPen, mHexGeometry);

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top