Migrate from Xamarin.Forms SfLinearGauge to .NET MAUI SfLinearGauge
28 Apr 202216 minutes to read
To make the migration from the Xamarin SfLinearGauge to the .NET MAUI SfLinearGauge easier, most of the similar APIs from the Xamarin SfLinearGauge were kept in the.NET MAUI SfLinearGauge. Also, the APIs has been restructured by considering various use cases and maintaining API consistency. Please find the difference in the following topics.
Initialize control
To initialize the control, import the gauge namespace and initialize SfLinearGauge as shown in the following code sample.
Xamarin SfLinearGauge | .NET MAUI SfLinearGauge |
---|---|
|
|
Scale
In the .NET MAUI linear gauge, we do not expose APIs for adding scale objects and their collections, like in the Xamarin linear gauge. You can add scale element settings such as axis line, ticks, labels, ranges, and pointers directly to the linear gauge.
Also, for creating multiple scales in the .NET MAUI, you can use multiple linear gauge objects. Since control measures are based on their inner elements.
Xamarin SfLinearGauge | .NET MAUI SfLinearGauge | Description |
---|---|---|
Gets or sets the minimum value of the axis. | ||
Gets or sets the maximum value of the axis. | ||
Gets or sets a value indicating whether it inverts the axis from right to left for a horizontal linear gauge or top to bottom for a vertical linear gauge. | ||
Gets or sets a value indicating whether the linear gauge should be mirrored. | ||
Gets or sets a value to customize the style of default major ticks. | ||
Gets or sets a value to customize the style of default minor ticks. | ||
Gets or sets the maximum number of labels to be displayed in 100 logical pixels. |
The following code example explains how to initialize the axis in Xamarin SfLinearGauge and .NET MAUI SfLinearGauge.
Xamarin SfLinearGauge | .NET MAUI SfLinearGauge |
---|---|
|
|
Range
Xamarin SfLinearGauge | .NET MAUI SfLinearGauge | Description |
---|---|---|
Gets or sets the brush that paints the interior area of the range. | ||
Gets or sets the value that indicates the position of the range inside, or cross, or outside the axis line. |
The following code example explains how to initialize the range in Xamarin SfLinearGauge and .NET MAUI SfLinearGauge.
Xamarin SfLinearGauge | .NET MAUI SfLinearGauge |
---|---|
|
|
Pointers
In Xamarin SfLinearGauge and .NET MAUI SfLinearGauge, pointers can be classified as mentioned in the following table.
Xamarin SfLinearGauge | .NET MAUI SfLinearGauge | Description |
---|---|---|
Create the pointer to indicate the value with a needle or arrow shape. | ||
Divided into and | Represents the pointer that is used to indicate the value with any visual content or with a built-in shapes. |
Also, in the .NET MAUI, bar pointer can be added to the BarPointers collection, and a shape and content pointer can be added to the MarkerPointers collection.
NOTE
In .NET MAUI SfLinearGauge SymbolPointer has been divided into two types. They are LinearShapePointer and LinearContentPointer.
Bar pointer
Xamarin SfLinearGauge | .NET MAUI SfLinearGauge | Description |
---|---|---|
Gets or sets a CornerStyle enumeration value that describes the corner/edge style of the BarPointer. | ||
Gets or sets a value that indicates the brush used to paint the pointer interior. | ||
Gets or sets the value that specifies the height of BarPointer for a horizontal linear gauge, or the width of BarPointer for a vertical linear gauge. |
The following code example, explains how to initialize the bar pointer in Xamarin SfLinearGauge and .NET MAUI SfLinearGauge.
Xamarin SfLinearGauge | .NET MAUI SfLinearGauge |
---|---|
|
|
Symbol pointer
Xamarin SfLinearGauge | .NET MAUI SfLinearGauge | Description |
---|---|---|
in class | Gets or sets a value that specifies the default shape type of the pointer. | |
in | Gets or sets a value that indicates the brush used to paint the pointer interior. | in | Gets or sets the placement (start, center or end) of the marker pointer relative to its position. | </tr>
The following code example, explains how to initialize the shape pointer in Xamarin SfLinearGauge and .NET MAUI SfLinearGauge.
Xamarin SfLinearGauge | .NET MAUI SfLinearGauge |
---|---|
|
|
Content pointer
The ContentPointer in the .NET MAUI SfLinearGauge allows using of any content or image or text as a pointer. In Xamarin, you can add an image as a pointer through the ImageSource property, and in MAUI, you can directly add an image control as a pointer in the content pointer.
Xamarin SfLinearGauge | .NET MAUI SfLinearGauge | Description |
---|---|---|
- | Gets or sets the any visual content of a LinearContentPointer. |
The following code example, explains how to initialize content pointer .NET MAUI SfLinearGauge. The content pointer feature is not applicable in Xamarin SfLinearGauge.
<gauge:SfLinearGauge>
<gauge:SfLinearGauge.MarkerPointers>
<gauge:LinearContentPointer Value="50" Alignment="End">
<gauge:LinearContentPointer.Content>
<Grid HeightRequest="25" WidthRequest="25">
<RoundRectangle CornerRadius="5"
Fill="#ff0074E3"/>
<Label Text="50" HorizontalOptions="Center"
VerticalOptions="Center" TextColor="White"/>
</Grid>
</gauge:LinearContentPointer.Content>
</gauge:LinearContentPointer>
</gauge:SfLinearGauge.MarkerPointers>
</gauge:SfLinearGauge>
SfLinearGauge gauge = new SfLinearGauge();
Grid views = new Grid() { HeightRequest = 25, WidthRequest = 25 };
views.Add(new RoundRectangle()
{
Fill = new SolidColorBrush(Color.FromArgb("#ff0074E3")),
CornerRadius = 5
});
views.Add(new Label()
{
Text = "50",
TextColor = Colors.White,
HorizontalOptions = LayoutOptions.Center,
VerticalOptions = LayoutOptions.Center
});
LinearContentPointer contentPointer = new LinearContentPointer();
contentPointer.Value = 50;
contentPointer.Alignment = GaugeAlignment.End;
contentPointer.Content = views;
gauge.MarkerPointers.Add(contentPointer);
this.Content = gauge;
Unsupported feature
The Annotation feature cannot be supported in the MAUI SfLinearGauge, since this feature requirement can be met using the content pointer support itself. So, you can use the content pointer as an annotation in.NET MAUI SfLinearGauge.