[Question] Create Shape with C# #11529
-
There are documentation related to Paths and Shapes, but all show XAML examples. I didn't find any content that show how to create a Shape with C#. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
@ronymesquita Yes, everything available in the Shapes API can be used both from XAML and from C# code. Example:
|
Beta Was this translation helpful? Give feedback.
-
Hello, @jsuarezruiz. I've tested a bit more. It's a little verbose, but is relatively easy. var trianglePathSegmentCollection = new PathSegmentCollection();
trianglePathSegmentCollection.Add(new LineSegment {Point = new Point(x: 100, y: 100)});
trianglePathSegmentCollection.Add(new LineSegment {Point = new Point(x: 100, y: 50)});
var trianglePathFigureCollection = new PathFigureCollection();
trianglePathFigureCollection.Add(new PathFigure()
{
IsClosed = true,
StartPoint = new Point( x: 10, y: 100),
Segments = trianglePathSegmentCollection
});
var trianglePath = new Path
{
Stroke = Brush.Black,
StrokeThickness = 1,
Aspect = Stretch.Uniform,
HorizontalOptions = LayoutOptions.Start,
Data = new PathGeometry
{
Figures = trianglePathFigureCollection
}
}; |
Beta Was this translation helpful? Give feedback.
@ronymesquita Yes, everything available in the Shapes API can be used both from XAML and from C# code. Example: