locked
Path does not change when Path.Data is changed

    Question

  • I have several paths for which I programmatically set the Data property. When I do this, the Path does not rerender with the new data. If I place the code in the Loaded event, it works fine, but not if I change it later. How can I make the Path display the new Path.Data? Thanks.

    Nathan Sokalski njsokalski@hotmail.com http://www.nathansokalski.com/

    Monday, October 27, 2014 12:25 AM

Answers

  • It should work if you set the Data to a valid and not-already-used Geometry. Here's a quick test that works for me. The "myPath" variable is a Path in the pages' visual tree.

                    EllipseGeometry geo2 = new EllipseGeometry();
                    geo2.RadiusX = 100;
                    geo2.RadiusY = 100;
                    geo2.Center = new Point(200, 200);
    
                    myPath.Data = geo2;

    If you need help analysing your code please share a minimal project which demonstrates the problem.

    --Rob

    Monday, October 27, 2014 8:09 PM
    Owner

All replies

  • Hi Nathan,

    As I understand from the question, you already changed the Path data, but UI does not update.

    How about UpdateLayout method?

    --James


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Monday, October 27, 2014 1:38 AM
    Moderator
  • I tried using the UpdateLayout() method. I tried calling it for both the Path itself, as well as it's parent (which in my case is a StackPanel), but it did not make any difference. Any other ideas? Thanks.

    Nathan Sokalski njsokalski@hotmail.com http://www.nathansokalski.com/

    Monday, October 27, 2014 3:23 PM
  • It should work if you set the Data to a valid and not-already-used Geometry. Here's a quick test that works for me. The "myPath" variable is a Path in the pages' visual tree.

                    EllipseGeometry geo2 = new EllipseGeometry();
                    geo2.RadiusX = 100;
                    geo2.RadiusY = 100;
                    geo2.Center = new Point(200, 200);
    
                    myPath.Data = geo2;

    If you need help analysing your code please share a minimal project which demonstrates the problem.

    --Rob

    Monday, October 27, 2014 8:09 PM
    Owner
  • I think that solved my problem. I was trying to replace the existing PathFigure with a new PathFigure, but when I replace the entire PathGeometry it seems to work, so I guess I can PROBLEM SOLVED! Thanks!

    Nathan Sokalski njsokalski@hotmail.com http://www.nathansokalski.com/

    Monday, October 27, 2014 9:31 PM