Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7164185
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T14:01:51+00:00 2026-05-28T14:01:51+00:00

I was trying to create a brush that draws a geometry. Everything worked fine

  • 0

I was trying to create a brush that draws a geometry. Everything worked fine until I tried to add Dashing to the shape.

I found that when I create the geometry using Geometry.Parse, the dashed line appears correctly, but when I create it directly using StreamGeometryContext, nothing gets rendered.

This is the code I’m using:

private void RenderGeometryAndSetAsBackground()
{
    Point startPoint = new Point(3505961.52400725, 3281436.57325874);
    Point[] points = new Point[] {
        new Point(3503831.75515445,3278705.9649394),
        new Point(3503905.74802898,3278449.37713916),
        new Point(3507242.57331039,3276518.41148474),
        new Point(3507700.6914325,3276536.23547958),
        new Point(3510146.73449577,3277964.12812859),
        new Point(3509498.96473447,3278678.60178448),
        new Point(3507412.1889951,3277215.64022219),
        new Point(3504326.22698001,3278682.85514017),
        new Point(3506053.34789057,3281390.66371786)};

    string geom = "M3505961.52400725,3281436.57325874L3503831.75515445,3278705.9649394 3503905.74802898,3278449.37713916 3507242.57331039,3276518.41148474 3507700.6914325,3276536.23547958 3510146.73449577,3277964.12812859 3509498.96473447,3278678.60178448 3507412.1889951,3277215.64022219 3504326.22698001,3278682.85514017 3506053.34789057,3281390.66371786";
    //Geometry geometry = StreamGeometry.Parse(geom);

    StreamGeometry geometry = new StreamGeometry();
    using (StreamGeometryContext sgc = geometry.Open())
    {
        sgc.BeginFigure(startPoint, false, true);
        foreach (Point p in points)
        {
            sgc.LineTo(p, true, true);
        }
    }

    Pen pen = new Pen(Brushes.Yellow, 3);
    pen.DashStyle = new DashStyle(new double[] { 30, 30 }, 0);
    //GeometryDrawing gd = new GeometryDrawing(null, pen, path.RenderedGeometry);
    GeometryDrawing gd = new GeometryDrawing(null, pen, geometry);
    DrawingBrush drawingBrush = new DrawingBrush(gd);
    DrawingBrush tile = drawingBrush.Clone();
    tile.Viewbox = new Rect(0.5, 0, 0.25, 0.25);
    RenderTargetBitmap rtb = new RenderTargetBitmap(256, 256, 96, 96, PixelFormats.Pbgra32);

    var drawingVisual = new DrawingVisual();
    using (DrawingContext context = drawingVisual.RenderOpen())
    {
        context.DrawRectangle(tile, null, new Rect(0, 0, 256, 256));
    }
    rtb.Render(drawingVisual);

    ImageBrush bgBrush = new ImageBrush(rtb);
    Background = bgBrush;
}

When done that way, nothing is getting drawn. If I don’t use dashing (or set the dashing to null) it works fine. It also works if I use the StreamGeometry.Parse(geom) and keeps the dashing.

Trying to call sgc.Close() didn’t help. Currently my only workaround is to call:

geometry = Geometry.Parse(geometry.ToString());

which is not very nice…

What am I missing?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T14:01:52+00:00Added an answer on May 28, 2026 at 2:01 pm

    That’s a pretty fascinating bug you got there, I can confirm it. Some ILSpy digging revealed the cause: the implicit BeginFigure call that is generated by Geometry.Parse sets the isFilled parameter to true, whereas you set it to false in your explicit StreamGeometryContext call. Change the second parameter in sgc.BeginFigure from false to true, and the dashed lines will render.

    The WPF path markup syntax does not allow specifying whether any individual figure should be filled or not, so I suppose that’s why the parser defaults to filling them all, just to be sure. But I can’t see any good reason why dashed lines would require filled figures, that has to be a WPF bug.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying create a WCF service that leverages the WPF MediaPlayer on the
Trying to create my first iPhone app that would play back audio. When I
Trying to create a small monitor application that displays current internet usage as percentage
I'm trying to write an application that can be used to create pictures that
I'm trying create a box in my Django app that displays text (and possibly
I'm trying create a ASMX webservice that can perform a HTTP GET request. I
I'm trying create this function such that if any key besides any of the
I am trying create a table and add this table into tablecell (table inside
I'm trying create a regex that verifies an xml entity name is valid (see
Hi I am trying create a system call that will count the number of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.