our

Latest Blogs

How to draw UI using Shapes and Paths in Xamarin.Forms?

iFour Team -July 02, 2021

Listening is fun too.

Straighten your back and cherish with coffee - PLAY !

  •  
  •  
  •  
How to draw UI using Shapes and Paths in Xamarin.Forms?

In this blog, we will be going to discuss about how to draw UI using Shapes and Paths in Xamarin.Forms. Xamarin is the best technology for cross-platform mobile applications. Now Xamarin is upgrading and the latest version is Xamarin.Forms 5. Shapes and paths are the latest control for the version of Xamarin.Forms. These controls are more useful for User Interface. Shapes and paths are useful in all platforms like Android, IOS, UWP, WPF, etc. Because shapes and path controls are using the native library. There are many controls in the new version like Shapes, paths, brushes, CarouselView, Drag and Drop, Swipe View, Radio button, etc. These controls to be useful and create a design more beautiful.

Shapes

There are several built-in controls in xamarin technology. Including a new API with an ellipse, line, polygon, rectangle, polyline, etc. All shapes are supported by common styling properties. You can easily implement such beautiful shapes in an application using the methods below.

  • Enable the flag.
  • You have to implement custom settings, in the custom step indicator.

The shape is a part of the drawing UI feature of xamarin.forms. The developer can convert a shape into a linear code.

The shape is a type of View that enables to draw the screen. The shape can be used inside layout classes and many controls because the shape class is derived from the view class.

Properties of shapes

Aspect

Aspect is a type of stretch. It describes how the shape fills its allocated space and by default the Aspects property value is Stretch.None.

Fill

Fill is a type of Brush. The brush is used to paint in shape interior.

Stroke

A stroke is a type of Brush. It can be used to paint the shape’s outline.

StrokeDashArray

StrokeDashArray is a kind of double collection, it represents a collection of double values showing the line and space patterns used to constrain the shape.

StrokeDashOffset

StrokeDashOffset is a type of double. This property is used for showing distance between one dash line ending to second-line starting and StrokeDashOffset default value is 0.0.

StrokeLineCap

StrokeLineCap is a type of PenLineCap. This property is used for showing the shape of the line segment. StrokeLineCap property’s default value is PenLineCap.Flat.

StrokeLineJoin

StrokeLineJoin is a type of PenLineJoin. This property can define the specific type of join that is used for vertices of the shape. StrokeLineJoin property’s default value is PenLineJoin.Meter.

StrokeMiterLimit

StrokeMiterLimit is a type of double. This property specifies the limit on the ratio of the miter length for the StrokeThickness of shape.StrokeMiterLimit default value is 10.0.

StrokeThickness

StrokeThickness is a type of double. This property indicates the width of the shape outline and StrokeThickness default value is 0.0.

These properties are registered by the BindableProperty objects, which means they can be stylized and data-binding targets.

Example:

Using Rectangle:

 

Using Line:


Paths

Paths control is a control of xamarin.forms 5. The path control can be used for the Custom design. If you use an SVG image, then you are already using Paths.

The Path class is derived from the shape class and you have also created complex shapes and curves. These curves and shapes are described using Geometry objects.

Properties of paths

Data:

Data is a type of Geometry. This property is use for drawing the particular shapes.

RenderTransform:

RenderTransform is a type of transform. This property represents the transform that is applied in geometry using a path before it is drawn

These properties are registered by the BindableProperty objects, which means they can be stylized and be the goal of data-bindings.

How to Create Path?

There are two methods for creating the path the following:

  • Create a Path object and set the property using Data. You can set the Data in property in the Geometry object. Geometry object or GeometryGroup acts that can combine multiple geometry objects into a single object.
  • You can set Data value in a string in XAML, using path mark-up syntax. This approach to be use and path. Data value is consuming a serialization format for graphics, Typically, a string data value that cannot be edit after created the path.

Op zoek naar het beste bedrijf voor de ontwikkeling van mobiele applicaties ? Uw zoekopdracht eindigt hier.

Create a path With Mark-up Syntax:

Example for Rectangle:


Describe

M -M is the Move Command, Establish the start point for the path.

L -L is a Line Command, which specify the starting and ending point of the line.

Z- Z is the Close Command, which creates a line that connects the starting point.

Create a path with Geometry Objects

Curves and shapes can be defined using geometry objects and it is used to set the data property of the Path object. There are three varieties of objects below.

  • EllipseGeometry
  • LineGeometry
  • RectangleGeometry

All geometry is to be used for simple shapes. But if you create complex shapes and curves that can be used as a PathGeometry. PathGeometry objects consist of one or more PathFigure objects. Each PathFigure object represents a different shape. Each PathFigure object itself consists of one or more PathSegment objects, each of which represents the binding part of the shape. There are three segment objects below.

  • LineSegment
  • BezierSegmen
  • ArcSegment

Example using Triangle:

Code:
















 




Describe

The starting point of the triangle is (20,200). A line segment is drawn between (20,200) to (200,200) and (200,200) to (200,60). The numbers in the first and last segment are then linked because of the PathFigure.IsClosed property is set to true.

Conclusion

In this blog, we explain the new features of shapes and paths in Xamarin.Forms 5. Shapes and Paths both controls can be useful for the interactive user interface. These controls are useful in any platform like Android, IOS, UWP, WPF. Paths control can be useful for creating a complex design using geometry in the Xamarin Forms.

Work with us

Well do everything we can to make our next best project!

Our Insights

Check out our most recent blogs

An in-depth guide on Angular Dependency Providers
An in-depth guide on Angular Dependency Providers

What is Angular? Angular is a frontend development framework used for building single-page client applications using HTML and Typescript. It is written in Typescript. What...

A simple guide on AOT Compilation in Angular
A simple guide on AOT Compilation in Angular

What is a Compiler? A compiler is nothing but a part of code that converts one programming language to another. If we talk about some simple programming languages like C, C++,...

Implement Attribute, Class, and Style binding in Angular
Implement Attribute, Class, and Style binding in Angular

What is binding in Angular? Binding in angular apps is the automatic synchronization of data within the model and view components. You can use data binding to define things...

Our Partners

Logo
Logo
Logo
Logo
Logo
Logo
Logo
Logo
Logo
Logo
Logo
Logo
Logo
Logo
Logo
Logo
Logo
Logo
Logo
Logo
Logo
Logo
Logo
Logo
Logo
Logo
Logo
Logo
Logo
Logo
Logo
Logo

Work With Us

Well do everything we can to make our next best project!