Skip to main content

Microsoft Silverlight

Answered Question can not find GetPointAtFractionLength Method in Silverlight. RSS Feed

(0)

pwzeus
pwzeus

Member

Member

17 points

18 Posts

can not find GetPointAtFractionLength Method in Silverlight.

is there any other way I can find point on the Arc. I am using below code.

EllipseGeometry geo = new EllipseGeometry(new Point(60, 60), 65, 65);

Path p = new Path();

p.Data = geo;

 

in WPF there is a method

 

PathGeometry pathGeo = geo.GetFlattenedPathGeometry();

 

I can not find this for Silver light.

 

Any help or pointers are much appriciated.

 

Thank you

Yi-Lun Luo - MSFT
Yi-Lun L...

All-Star

All-Star

25052 points

2,747 Posts

Answered Question

Re: can not find GetPointAtFractionLength Method in Silverlight.

Unfortunately this method is not available in Silverlight. For this particular scenario, you can use the following code to turn the EllipseGeometry into a PathGeometry that contains a series of LineSegments:

PathGeometry pg = new PathGeometry();
PathFigure pf = new PathFigure();
pf.StartPoint = new Point(125, 60);
for (double i = 0; i <= 2 * Math.PI; i += 0.01)
{
LineSegment ls = new LineSegment();
double x = 60 + 65 * Math.Cos(i);
double y = 60 + 65 * Math.Sin(i);
ls.Point = new Point(x, y);
pf.Segments.Add(ls);
}
LineSegment lsEnd = new LineSegment();
lsEnd.Point = new Point(125, 60);
pf.Segments.Add(lsEnd);
pg.Figures.Add(pf);

 

It's not difficult to write a reusable method based on this code for an EllipseGeometry. But if you want a solution for an arbitrary Geometry, you need to write more code. I think it's not difficult. You can enumerate all Geometries in Silverlight: Line/Rectangle/Ellipse/PathGeometry. And PathGeometry can contain Arc/Bezire/Line/PolyBezire/PolyLine/PolyQuadraticBezire/QuadraticSegments. None of those geometries/segments has complex formulas. So just spend some time to build a robust solution.

shanaolanxing - I'll transfer to the Windows Azure team, and will have limited time to participate in the Silverlight forum. Apologize if I don't answer your questions in time.

endquote
endquote

Member

Member

4 points

24 Posts

Re: can not find GetPointAtFractionLength Method in Silverlight.

This isn't really a great solution, because the Figures collection of a PathGeometry object doesn't actually give you access to the child segments in Silverlight as it does in WPF. For example here is an arbitrary path drawn in Blend:

 <Path Height="56" HorizontalAlignment="Left" Margin="137.5,167.5,0,0" VerticalAlignment="Top" Width="88" Fill="#FFFFFFFF" Stretch="Fill" Stroke="#FF000000" Data="M138,168 L225,222 L139.5,222.5 z" x:Name="TestPath"/>

And some codebehind:

Path path = TestPath;

PathGeometry data = (PathGeometry) path.Data;

PathFigureCollection figures = data.Figures;

The figures collection has nothing in it.

  • Unanswered Question
  • Answered Question
  • Announcement
Microsoft Communities