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 892671
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T14:05:41+00:00 2026-05-15T14:05:41+00:00

In a WPF UI I have nodes connected by bezier paths, like so: It

  • 0

In a WPF UI I have nodes connected by bezier paths, like so:

It might be… atomic http://nv3wrg.blu.livefilestore.com/y1pIGBd33lCC6lF-9H0MqgnL40BdNEoEemZDENzgpEI1IL2j4B-qb3qS3WlxMSys28IjqNngR7mdfvQBnPzerf4cFJQj9VqHBh4/acurve.png?psid=1

When the user drags a node around, the connecting paths need to be updated in real-time. However, I’ve noticed some slowdown (especially if one node is connected to many others, or multiple nodes are being dragged at once). I profiled it, and the main problem appears to be here:

Proof I actually used a profiler, so please don't be all like "OMG, premature opiumzation; you are DEMON!!" http://nv3wrg.blu.livefilestore.com/y1pjRfQYuN57yei5qdUxW4Dlh4vVCzPy8TcfEzlw_8cUicfOR6BwHCTntcQbQUspRAgBdKcItC0ZcEJbIWMKaYrCtDMOtCBKB4g/profile.png?psid=1

This is the function that is called each time either the source or destination property is changed. The geometry that makes up the path seems to be being regenerated internally each time any of the control points change. Perhaps if there were a way to prevent the geometry from being regenerated until after all the relevant dependency properties have been set?

EDIT: Mart’s solution to use StreamGeometry sped it up exponentially; the function is nowhere close to a bottleneck. A little Reflecting suggests that PathGeometry uses StreamGeometry internally, and every time any of the dependency properties are changed, the StreamGeometry is recalculated. So this way just cuts out the middleman. The final result is:

private void onRouteChanged()
{
    Point src = Source;
    Point dst = Destination;
    if (!src.X.isValid() || !src.Y.isValid() || !dst.X.isValid() || !dst.Y.isValid())
    {
        _shouldDraw = false;
        return;
    }

    /*
        * The control points are all laid out along midpoint lines, something like this:
        * 
        *   -------------------------------- 
        *  |          |          |          |
        *  |   SRC    |    CP1   |          |
        *  |          |          |          |
        *   -------------------------------- 
        *  |          |          |          |
        *  |          |    MID   |          |
        *  |          |          |          |
        *   ------------------------------- 
        *  |          |          |          |
        *  |          |    CP2   |    DST   |
        *  |          |          |          |
        *   -------------------------------- 
        *   
        * This causes it to be horizontal at the endpoints and vertical
        * at the midpoint.
        */

    double mx = (src.X + dst.X) / 2;
    double my = (src.Y + dst.Y) / 2;
    Point mid = new Point(mx, my);
    Point cp1 = new Point(mx, src.Y);
    Point cp2 = new Point(mx, dst.Y);

    _geometry.Clear();
    _shouldDraw = true;
    using(StreamGeometryContext ctx = _geometry.Open())
    {
        ctx.BeginFigure(src, false, false);
        ctx.QuadraticBezierTo(cp1, mid, true, false);
        ctx.QuadraticBezierTo(cp2, dst, true, false);
    }
}

The full source code of the project is available at http://zeal.codeplex.com for the curious.

  • 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-15T14:05:41+00:00Added an answer on May 15, 2026 at 2:05 pm

    1- I would try to use StreamGeometry:

            StreamGeometry streamGeo = new StreamGeometry();
            Stopwatch sw = new Stopwatch();
            sw.Start();
            for (int i = 0; i < 10000; i++)
            {
                streamGeo.Clear();
                var ctx = streamGeo.Open();
                ctx.BeginFigure(new Point(0, 0), false, false);
                ctx.QuadraticBezierTo(new Point(10, 10), new Point(10, i), true, true);
                ctx.Close();
            }
            sw.Stop();
            Console.WriteLine(sw.ElapsedMilliseconds); // For 10k it took 30 ms
    

    It looks much faster than PathGeometry+PathFigure.

    When you set the Point for the QuadraticBezierSegment it recalculates everything. That’s why it is slow. And more slow when it is already added to a geometry.

    2- Try to use only 1 frameworkelement for all of your curves. Check this:
    Writing More Efficient ItemsControls

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

Sidebar

Related Questions

Hey guys, I have a WPF TreeView that has three nodes, I would like
I have a WPF Path object which is created by reading nodes from a
I have a strange WPF/XAML problem. By default, I want all of the nodes
I am working on an interactive WPF graph/tree tool and have nodes and links
Say I have a 3-level data-bound WPF TreeView like this one: a aa aaa
I am trying to create something like the UDK or Maya material editor http://www.google.com/search?q=udk+material+editor&oe=utf-8&rls=org.mozilla:en-US:official&client=firefox-a&um=1&ie=UTF-8&hl=en&tbm=isch&source=og&sa=N&tab=wi&biw=1144&bih=929
Let's assume I have dragable nodes in an WPF MVVM application. I need to
do routed events from wpf have something in common with the chain of responsibility
WPF controls have certain properties (UserControl.Resources, UserControl.CommandBindings) that can have items added to them
I have WPF Span that is used as a source to a TextBlock. I

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.