mrtouya
Topic Author
Posts: 6
Joined: 03 Mar 2017, 16:32

How do I create a new GeometryCollection from code?

27 Mar 2017, 18:20

I am creating a new GeometryGroup from code. It seems like I am unable to create a GeometryCollection because the method is protected. Is there a way around that??

This is what I am trying to do in code.
 private Path ConstructPath()
        {
            if (WedgeAngle >= 360)
            {
                Path path = new Path()
                {
                    Fill = this.Fill,
                    Stroke = this.Stroke,
                    StrokeThickness = 1,
                    Data = new GeometryGroup()
                    {
                        FillRule = FillRule.EvenOdd,
                        Children = new GeometryCollection()
            {
              new EllipseGeometry()
              {
                Center = new Point(CentreX, CentreY),
                RadiusX = Radius,
                RadiusY = Radius
              },
              new EllipseGeometry()
              {
                Center = new Point(CentreX, CentreY),
                RadiusX = InnerRadius,
                RadiusY = InnerRadius
              }
              ...
              
I am stuck. Please let me know if there is something I am not seeing.

I get the error on this line:

Children = new GeometryCollection().

I cannot access GeometryCollection due to it's protection level..So how do I add a geometry collection programatically?

Thanks!!
 
kemarofangs
Posts: 32
Joined: 13 Jun 2014, 21:30

Re: How do I create a new GeometryCollection from code?

27 Mar 2017, 19:37

I think they have worked on geometry classes some but there is a lot of support missing. I had put in a feature request but never got around to testing their resolution yet (as of 1.2.6f6 version). This concerned reading simple geometry data in the xaml from the code behind. Issue Tracker
<Path x:Name="m_path_outline" Data="M 0,0 L100,50 L0,100 Z" Stroke="Black" StrokeThickness="5" Fill="White" />
path.Data.ToString();
Maybe this code could help?
Noesis.Path path1 = new Noesis.Path() { Data = "M 0,0 L100,50 L0,100 Z" };
Noesis.Path path2 = new Noesis.Path() { Data = "M 70,44 L80,50 L70,56 Z" };
CombinedGeometry combinedGeometry = new CombinedGeometry(path1, path2, GeometryCombineMode.Exclude);
combinedGeometry.Freeze();
Noesis.Path pathCombined = new Noesis.Path() { Data = combinedGeometry };
Just wait for the developers to reply about all the supported Geometry objects and classes. They know best. Good luck.
 
User avatar
sfernandez
Site Admin
Posts: 1918
Joined: 22 Dec 2011, 19:20

Re: How do I create a new GeometryCollection from code?

28 Mar 2017, 18:39

This is clearly a bug, GeometryCollection (and I saw that other collection classes have the same problem) should have its default constructor public instead of protected.
We will fix it for the next release.

Meanwhile, the good thing is that we assign an empty collection to the Children property when GeometryGroup gets created, so you can just do the following:
var g = new GeometryGroup() { FillRule = FillRule.EvenOdd };
g.Children.Add(new EllipseGeometry { Center = new Point(CentreX, CentreY), RadiusX = Radius });
...
 
mrtouya
Topic Author
Posts: 6
Joined: 03 Mar 2017, 16:32

Re: How do I create a new GeometryCollection from code?

28 Mar 2017, 20:01

Thanks Guys :-)

Who is online

Users browsing this forum: No registered users and 1 guest