user1200540
user1200540

Reputation:

Is Converting a Path To A Shape Possible?

So i basically have a Stack Panel, And i'm using a foreach loop to iterate through the children, and all of the children are 'path' formats, but some are lines and some are ellipses (or were atleast, before converted to path)

My question is, how can i tell which ones are lines, and which ones are ellipses? , i'm using the isMouseOver event to check if the mouse is over Ellipses to make them change accordingly on MouseDown

private void GraphPanel_PreviewMouseDown(object sender, MouseButtonEventArgs e)
    {
        foreach (var x in GraphPanel.Children)
        {

                if (((Path)x).IsMouseOver)
                {
                    var converter = new System.Windows.Media.BrushConverter();
                    var brush = (Brush)converter.ConvertFromString("#FFB1D100");
                    ((Path)x).Stroke = brush;
                    ((Path)x).StrokeThickness = 8;
                }
                else
                {

                    ((Path)x).Stroke = Brushes.Black;
                    ((Path)x).StrokeThickness = 4;
                }
            }

        }
    }

Upvotes: 1

Views: 251

Answers (2)

Clemens
Clemens

Reputation: 128180

You can check the type of the Path.Data property, which is a class derived from Geometry.

Besides some complex Geometry types, the basic derived Geometry types are EllipseGeometry, LineGeometry and RectangleGeometry.

Path path = (Path)x;
Geometry geometry = path.Data;
if (geometry is EllipseGeometry)
{
    ...
}
else if (geometry is LineGeometry)
{
    ...
}
...

Upvotes: 2

user1200540
user1200540

Reputation:

This may not be the most efficient way, but this is what I've Figured out

if((Path)x).Data.ToString() == "System.Windows.Media.EllipseGeometry"){}

Upvotes: 0

Related Questions