Introduction .NET MAUI .NET MAUI, a cross-platform framework, empowers developers to build native mobile and desktop applicatio...

.NET MAUI Barcode Scanner using IRONBARCODE .NET MAUI Barcode Scanner using IRONBARCODE

A blog about android developement

Introduction

.NET MAUI

.NET MAUI, a cross-platform framework, empowers developers to build native mobile and desktop applications using C# and XAML. It enables the creation of apps that seamlessly operate on Android, iOS, macOS, and Windows, all from a unified codebase. This open-source platform is an advancement of Xamarin Forms, expanding its reach to desktop scenarios while enhancing UI controls for improved performance and extensibility.


Using .NET MAUI, you have the capability to develop applications that can run on multiple platforms such as Android, iOS, MacOS, and Windows, all from a single codebase.


.NET MAUI allows for efficient cross-platform development, reducing the need for separate codebases for each platform and simplifying the maintenance and updates of your application.


.NET MAUI saves time and effort and makes it easier to maintain your apps. Visual Studio 2022 is avail with dotnet 7 with .Net Maui app development


In this article, we will see how we can implement a QR code or barcode scanner in the .NET MAUI project using IronBarcode Library.


IronBarcode: C# Barcode Library

The IronBarcode library simplifies barcode detection in .NET applications with its intuitive APIs and eliminates the need for intricate barcode object creation. It offers a wide range of QR code and barcode formats such as Code 39, Code 128, and PDF417.


As a versatile .NET library, it can also function as a QR code reader, decoding input data into readable text from various sources like images and streams. This article explores how to leverage the IronBarcode library for QR code scanning in .NET MAUI applications, providing a comprehensive guide.


Quick Links:


Project Setup:

  • Launch Visual Studio 2022, and in the start window click Create a new project to create a new project.
  • In the Create a new project window, select MAUI in the All project types drop-down, select the .NET MAUI App template, and click the Next button:
  • In the configure your new project window, name your project, choose a suitable location for it, and click the Next button:
  • In the Additional information window, click the Create button:
  • Once the project is created, we can able to see the Android, iOS, Windows and other running options in the toolbar. Press the emulator or run button to build and run the app

Install IronBarcode Library

To install the IronBarcode library via the NuGet Packages Console, simply execute the following command or visit the Nuget package website or search in the Nuget package Manager to download the latest version of the library.

Install-Package BarCode

Implementation of File Picker functionality

Ironbarcode library will read the barcode from the selected image and provide the result. For File Picker functionality, visit the official .NET MAUI essentials link and set up all the mentioned steps in the link.

Designing the screen

In this tutorial, we are using Image, Button, and Editor controls. You can change the design as per your preferences.

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="MAUI_Barcode.MainPage">

    <ScrollView>
        <VerticalStackLayout
            Spacing="25"
            Padding="30,0"
            VerticalOptions="Center">

            <Button
                x:Name="ImageSelect"
                Text="Select Barcode"
                SemanticProperties.Hint="Select Image"
                Clicked="SelectBarcode"
                HorizontalOptions="Center" />
            <Image
                x:Name="barcodeImage"
                SemanticProperties.Description="Selected Barcode"
                HeightRequest="200"
                HorizontalOptions="Center" />
            <Editor x:Name="outputText"
                Placeholder="Output text"
                HeightRequest="100"
                WidthRequest="500"
                    />
        </VerticalStackLayout>
    </ScrollView>

</ContentPage>

Here,

  • Button - used to select barcode images that need to be read.
  • Image - used to display the selected barcode image.
  • Editor - used to display the scanned result from Iron Barcode Library.

Functionality of the screen

  • Add a click event for the button to select the image like below. This event will allow the app to select the barcode image.
    private async void SelectBarcode(object sender, EventArgs e)
    {
    	var images = await FilePicker.Default.PickAsync(new PickOptions
    	{
    		PickerTitle = "Pick Barcode/QR Code Image",
    		FileTypes = FilePickerFileType.Images
    	});
    	var imageSource = images.FullPath.ToString();
    	barcodeImage.Source = imageSource;
    	var result = BarcodeReader.Read(imageSource).First().Text;
    	outputText.Text = result;	
    }
  • Once the barcode image is selected, the File Picker will return the full path of the file.
  • We will assign the file path to the image control to preview the selected image.
  • As well as the selected image's file path will be sent as input to the barcode read library.
  • Once the input is processed, the library will return the scanned output as a result of the barcode read function. This output will be assigned to the editor control for displaying the result in human-readable text.

Full Code

using IronBarCode;

namespace MAUI_Barcode;

public partial class MainPage : ContentPage
{

	public MainPage()
	{
		InitializeComponent();
	}

	private async void SelectBarcode(object sender, EventArgs e)
	{
		var images = await FilePicker.Default.PickAsync(new PickOptions
		{
            PickerTitle = "Pick Barcode/QR Code Image",
            FileTypes = FilePickerFileType.Images
		});
		var imageSource = images.FullPath.ToString();
		barcodeImage.Source = imageSource;
		var result = BarcodeReader.Read(imageSource).First().Text;
		outputText.Text = result;
		
    }
}

Output

Upon selecting the barcode, the editor will display a screenshot similar to the one below, with the output text of the QR Code visible.

Before selecting the barcode, similar to other platforms as well:

After selecting the barcode:

Download Code:

You can download the code from GitHub. If you have any doubts, feel free to post a comment. If you liked this article, and it is useful to you, do like, share the article & star the repository on GitHub.

Conclusion

This article detailed the process of barcode reading in a .NET MAUI application using IronBarcode. IronBarcode proves to be a comprehensive solution equipped with essential tools for barcode operations. Functioning as a QR code reader, IronBarcode delivers accurate and expected output, even when dealing with intricate barcodes. Furthermore, it offers the flexibility to create and customize barcodes using a variety of fonts.


IronBarcode is available for free for development purposes, but a license must be purchased for commercial use. To obtain information about the licensing options, please refer to the following link: https://ironsoftware.com/csharp/barcode/licensing

Introduction .NET MAUI, a cross-platform framework, empowers developers to build native mobile and desktop applications using C# and...

Dynamic Status Bar in .NET MAUI Dynamic Status Bar in .NET MAUI

A blog about android developement

Introduction

.NET MAUI, a cross-platform framework, empowers developers to build native mobile and desktop applications using C# and XAML. It enables the creation of apps that seamlessly operate on Android, iOS, macOS, and Windows, all from a unified codebase. This open-source platform is an advancement of Xamarin Forms, expanding its reach to desktop scenarios while enhancing UI controls for improved performance and extensibility.


In this article, we will see how we can implement Dynamic Status Bar in .NET MAUI project.

Quick Links:


Project Setup:

  • Launch Visual Studio 2022, and in the start window click Create a new project to create a new project.
  • In the Create a new project window, select MAUI in the All project types drop-down, select the .NET MAUI App template, and click the Next button:
  • In the configure your new project window, name your project, choose a suitable location for it, and click the Next button:
  • In the Additional information window, click the Create button:
  • Once the project is created, we can able to see the Android, iOS, Windows and other running options in the toolbar. Press the emulator or run button to build and run the app

Implementation

Screen Design:

As a first point, we need to implement the screen design as per our requirement. In this tutorial, we will use 3 buttons like in the following code block.

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="MauiStatusBarBehaviour.MainPage">

    <ScrollView>
        <VerticalStackLayout
            Spacing="25"
            Padding="30,0"
            VerticalOptions="Center">

            <Button
                Text="Blue"
                SemanticProperties.Hint="Counts the number of times you click"
                Clicked="OnBlueClicked"
                HorizontalOptions="Center" />

            <Button
                Text="Green"
                SemanticProperties.Hint="Counts the number of times you click"
                Clicked="OnGreenClicked"
                HorizontalOptions="Center" />

            <Button
                Text="Default"
                SemanticProperties.Hint="Counts the number of times you click"
                Clicked="OnDefaultClicked"
                HorizontalOptions="Center" />

        </VerticalStackLayout>
    </ScrollView>

</ContentPage>

Methods:

To implement this, we can implement in the following methodlogies.

  • Applying Behaviour in XAML.
  • Applying Behaviour in Code behind.
  • Applying without behaviour in Code behind.

In this article, we are going to see "Applying without behaviour in Code behind.".

  • Just install the .NET MAUI community toolkit to your project.
    Install-Package CommunityToolkit.Maui -Version 3.1.0
  • Add it to the MauiProgram.cs
    var builder = MauiApp.CreateBuilder();
    builder
    .UseMauiApp<App>()
    .UseMauiCommunityToolkit()
    .ConfigureFonts(fonts => {
        fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
        fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold");
    });
  • Add event in code behind for each button click and apply the below code.
    CommunityToolkit.Maui.Core.Platform.StatusBar.SetColor(statusBarColor);
    CommunityToolkit.Maui.Core.Platform.StatusBar.SetStyle(StatusBarStyle.LightContent);

Full Code:

Demo

Download Code:

You can download the code from GitHub. If you have any doubts, feel free to post a comment. If you liked this article, and it is useful to you, do like, share the article & star the repository on GitHub.

References

https://learn.microsoft.com/en-us/dotnet/communitytoolkit/maui/behaviors/statusbar-behavior

Introduction .NET MAUI, a cross-platform framework, empowers developers to build native mobile and desktop applications using C# and ...

Localisation in .NET MAUI Localisation in .NET MAUI

A blog about android developement

Introduction

.NET MAUI, a cross-platform framework, empowers developers to build native mobile and desktop applications using C# and XAML. It enables the creation of apps that seamlessly operate on Android, iOS, macOS, and Windows, all from a unified codebase. This open-source platform is an advancement of Xamarin Forms, expanding its reach to desktop scenarios while enhancing UI controls for improved performance and extensibility.


In this article, we will see how we can implement Localisation in .NET MAUI project.


Advantages of Localisation

  • Localisation improves user experience by providing content and language that is culturally relevant and easily understandable to users in different regions, increasing engagement and satisfaction.
  • It expands market reach by making products or services accessible to a global audience, tapping into new markets and driving business growth.
  • Localisation helps build trust and credibility with international customers by demonstrating a commitment to their specific needs and preferences, fostering stronger relationships and customer loyalty.

Quick Links:


Project Setup:

  • Launch Visual Studio 2022, and in the start window click Create a new project to create a new project.
  • In the Create a new project window, select MAUI in the All project types drop-down, select the .NET MAUI App template, and click the Next button:
  • In the configure your new project window, name your project, choose a suitable location for it, and click the Next button:
  • In the Additional information window, click the Create button:
  • Once the project is created, we can able to see the Android, iOS, Windows and other running options in the toolbar. Press the emulator or run button to build and run the app

Implementation

Screen Design:

As a first point, we need to implement the screen design as per our requirement. In this tutorial, we will use 3 controls - 2 labels, and button like in the following code block.

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:resource="clr-namespace:MauiLocalization"
             x:Class="MauiLocalization.MainPage">

    <ScrollView>
        <VerticalStackLayout
            Spacing="25"
            Padding="30,0"
            VerticalOptions="Center">

            <Image
                Source="dotnet_bot.png"
                SemanticProperties.Description="Cute dot net bot waving hi to you!"
                HeightRequest="200"
                HorizontalOptions="Center" />

            <Label
                Text="{x:Static resource:LangResources.Helloworld}"
                SemanticProperties.HeadingLevel="Level1"
                FontSize="32"
                HorizontalOptions="Center" />

            <Label
                Text="{x:Static resource:LangResources.WelcomeNote}"
                SemanticProperties.HeadingLevel="Level2"
                SemanticProperties.Description="Welcome to dot net Multi platform App U I"
                FontSize="18"
                HorizontalOptions="Center" />

            <Button
                x:Name="CounterBtn"
                Text="Change to Tamil"
                SemanticProperties.Hint="Counts the number of times you click"
                Clicked="OnCounterClicked"
                HorizontalOptions="Center" />

        </VerticalStackLayout>
    </ScrollView>

</ContentPage>

Create RESX file

In this step, we will see the steps to create RESX file.

  • In the Solution Explorer, right-click on the project or folder where you want to add the RESX file.
  • Select "Add" from the context menu and then choose "New Item" or "New Folder" if you want to organize your resources in a separate folder.
  • In the "Add New Item" dialog box, search for "Resource File" or navigate to "General" -> "Text File" and name the file with the .resx extension.
  • Click the "Add" button to create the resource file.
  • We created two resources file. One is default and another one prefixed with the language code.
    1. LangResources.resx
    2. LangResources.ta.resx (Contains the resource equivalent in tamil)

RESX Files in XAML

  • To utilize your resources, you first need to import the XML namespace associated with them.
  • xmlns:resource="clr-namespace:MauiLocalization"
  • Then, you can access your strings by using the [x:Static](https://learn.microsoft.com/en-us/xamarin/xamarin-forms/xaml/xaml-basics/xaml-markup-extensions#the-xstatic-markup-extension) markup extension, treating them as properties.
    Text="{x:Static resource:LangResources.Helloworld}"

Language Update

  • Add click event to the button to change language based on the language code of the resource file.
    private void OnCounterClicked(object sender, EventArgs e)
    {
    	if (CounterBtn.Text.Contains("Tamil"))
    	{
    		LangResources.Culture = new CultureInfo("ta");
    		CounterBtn.Text = "Change to English";
    	}
    	else
    	{
    		LangResources.Culture = CultureInfo.InvariantCulture;
    		CounterBtn.Text = "Change to Tamil";
    	}
    	App.Current.MainPage = new MainPage();
    }
  • Here, "App.Current.MainPage = new MainPage();" is used to refresh page once the language changed
  • Then, we will add the below block in the page constructor to retain the language change once the button clicked and page refreshed.
    if (LangResources.Culture != null && LangResources.Culture.TwoLetterISOLanguageName.Contains("ta"))
    {
    	CounterBtn.Text = "Change to English";
    }
    else
    {
    	CounterBtn.Text = "Change to Tamil";
    }

Full Code:

Demo

Android:

Download Code:

You can download the code from GitHub. If you have any doubts, feel free to post a comment. If you liked this article, and it is useful to you, do like, share the article & star the repository on GitHub.

References

https://learn.microsoft.com/en-us/dotnet/core/extensions/resources

Introduction .NET MAUI, a cross-platform framework, empowers developers to build native mobile and desktop applications using C#...

File Picker in .NET MAUI File Picker in .NET MAUI

A blog about android developement

Introduction

.NET MAUI, a cross-platform framework, empowers developers to build native mobile and desktop applications using C# and XAML. It enables the creation of apps that seamlessly operate on Android, iOS, macOS, and Windows, all from a unified codebase. This open-source platform is an advancement of Xamarin Forms, expanding its reach to desktop scenarios while enhancing UI controls for improved performance and extensibility.


In this article, we will see how we can implement a File Picker in the .NET MAUI project.


Quick Links:


Project Setup:

  • Launch Visual Studio 2022, and in the start window click Create a new project to create a new project.
  • In the Create a new project window, select MAUI in the All project types drop-down, select the .NET MAUI App template, and click the Next button:
  • In the configure your new project window, name your project, choose a suitable location for it, and click the Next button:
  • In the Additional information window, click the Create button:
  • Once the project is created, we can able to see the Android, iOS, Windows and other running options in the toolbar. Press the emulator or run button to build and run the app

Implementation:

As a first point, we need to implement the screen design as per our requirement. In this tutorial, we will use 3 controls - button, image, and label like in the following code block.


<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="MauiFilePicker.MainPage">

    <ScrollView>
        <VerticalStackLayout
            Spacing="25"
            Padding="30"
            VerticalOptions="Start">

            <Button
                x:Name="ImageSelect"
                Text="Select Barcode"
                SemanticProperties.Hint="Select Image"
                Clicked="SelectBarcode"
                HorizontalOptions="Center" />
            <Label x:Name="outputText"
                   Padding="10"/>
            <Image
                x:Name="barcodeImage"
                SemanticProperties.Description="Selected Barcode"
                HeightRequest="200"
                HorizontalOptions="Center" />
        </VerticalStackLayout>
    </ScrollView>

</ContentPage>

Here,

  • Button - used to select images from device.
  • Image - used to display the selected image.
  • Label - used to display the file path once the image selected through file picker.

Functional part

  • Add a click event for the button to select the image like below.
    private async void SelectBarcode(object sender, EventArgs e)
    {
    	var images = await FilePicker.Default.PickAsync(new PickOptions
    	{
    		PickerTitle = "Pick Barcode/QR Code Image",
    		FileTypes = FilePickerFileType.Images
    	});
    	var imageSource = images.FullPath.ToString();
    	barcodeImage.Source = imageSource;
    	outputText.Text = imageSource;
    }

    Here,

    • FileTypes: The default file types available for selection in the FilePicker are FilePickerFileType.Images, FilePickerFileType.Png, and FilePickerFileType.Videos. However, if you need to specify custom file types for a specific platform, you can create an instance of the FilePickerFileType class. This allows you to define the desired file types according to your requirements.
    • PickerTitle: The PickOptions.PickerTitle is presented to the user and its behavior varies across different platforms.

    Full Code:

    Demo

    Android:
    android
    Windows:
    windows

    Download Code:

    You can download the code from GitHub. If you have any doubts, feel free to post a comment. If you liked this article, and it is useful to you, do like, share the article & star the repository on GitHub.

    References

    https://learn.microsoft.com/en-us/dotnet/maui/platform-integration/storage/file-picker

.NET MAUI, a powerful platform for developing cross-platform mobile applications, provides a seamless way to incorporate Toast fun...

Toast in .NET MAUI Toast in .NET MAUI

A blog about android developement

.NET MAUI, a powerful platform for developing cross-platform mobile applications, provides a seamless way to incorporate Toast functionality into your app. With the aid of the appropriate tools and resources, implementing an Toast in .NET MAUI using the .NET MAUI Community Toolkit is a straightforward process. In this tutorial, we will guide you through the necessary steps to successfully integrate Toast into your .NET MAUI application.


Quick Links:


Project Setup:

  • Launch Visual Studio 2022, and in the start window click Create a new project to create a new project.
  • In the Create a new project window, select MAUI in the All project types drop-down, select the .NET MAUI App template, and click the Next button:
  • In the configure your new project window, name your project, choose a suitable location for it, and click the Next button:
  • In the Additional information window, click the Create button:
  • Once the project is created, we can able to see the Android, iOS, Windows and other running options in the toolbar. Press the emulator or run button to build and run the app

Implementation:

.NET MAUI Community Toolkit is the key to achieve drawing in our App is to use Community.ToolKit.Maui NuGet package. It is a collection of reusable elements such as animations, behaviors converters, among others, for developing applications for iOS, Android, macOS and WinUI using MAUI.


Install .NET MAUI Community Toolkit

  • Install .NET MAUI Community Toolkit nuGet package on your .NET MAUI application.
  • Now initialize the plugin. Go to your MauiProgram.cs file. In the CreateMauiApp method, place in the .UseMauiApp<App>() line and just below it add the following line of code.
var builder = MauiApp.CreateBuilder();
builder
	.UseMauiApp<App>()
	.UseMauiCommunityToolkit()
	.ConfigureFonts(fonts =>
	{
		fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
		fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold");
	});
    CancellationTokenSource cancellationTokenSource = new CancellationTokenSource();
            await Toast.Make("Hi, How are you?",
                      ToastDuration.Long,
                      16)
                .Show(cancellationTokenSource.Token);
  • The methods Make() and Show() are essential for displaying Toast messages on the screen. Each of these methods possesses specific attributes that facilitate the configuration of the Toast. Let's delve into a closer examination of these attributes.
  • Make:

    The Make() method is responsible for creating the Toast and requires the following parameters:
    • Text: This is a mandatory parameter represents the message that will be displayed in the Toast.
    • Duration: This parameter specifies the exact duration for which the Toast message will be shown on the screen before fading away. It is an optional parameter and it's default ToastDuration type is ToastDuration.Short:
    • TextSize: This parameter is an optional paramter to set the text size of the Toast. Default value of this parameter is 14 and it's type is double.

    Show:

    This method is responsible for displaying the requested Toast message on the screen.

    Full Code:

    Demo

    Download Code:

    You can download the code from GitHub. If you have any doubts, feel free to post a comment. If you liked this article, and it is useful to you, do like, share the article & star the repository on GitHub.

    The idea behind this tutorial is from "AskXammy"

.NET MAUI is a powerful platform for building cross-platform mobile applications, and with the right tools and resources, it's eas...

Avatar View in .NET MAUI Community Toolkit Avatar View in .NET MAUI Community Toolkit

A blog about android developement

.NET MAUI is a powerful platform for building cross-platform mobile applications, and with the right tools and resources, it's easy to implement Avatar View to your app. In this tutorial, we'll walk you through the steps for adding Avatar View in .NET MAUI using .NET MAUI Community Toolkit.


Quick Links:


Project Setup:

  • Launch Visual Studio 2022, and in the start window click Create a new project to create a new project.
  • In the Create a new project window, select MAUI in the All project types drop-down, select the .NET MAUI App template, and click the Next button:
  • In the configure your new project window, name your project, choose a suitable location for it, and click the Next button:
  • In the Additional information window, click the Create button:
  • Once the project is created, we can able to see the Android, iOS, Windows and other running options in the toolbar. Press the emulator or run button to build and run the app

Implementation:

.NET MAUI Community Toolkit is the key to achieve drawing in our App is to use Community.ToolKit.Maui NuGet package. It is a collection of reusable elements such as animations, behaviors converters, among others, for developing applications for iOS, Android, macOS and WinUI using MAUI.


Install .NET MAUI Community Toolkit

  • Install .NET MAUI Community Toolkit nuGet package on your .NET MAUI application.
  • Now initialize the plugin. Go to your MauiProgram.cs file. In the CreateMauiApp method, place in the .UseMauiApp<App>() line and just below it add the following line of code.
var builder = MauiApp.CreateBuilder();
builder
	.UseMauiApp<App>()
	.UseMauiCommunityToolkit()
	.ConfigureFonts(fonts =>
	{
		fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
		fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold");
	});
  • A graphical representation known as an avatar is connected to a particular user in order to identify them. This is frequently utilised in programmes that we use every day, therefore it's crucial that you have access to the tools that will enable you to accomplish it. This tutorial will teach you how to quickly and easily construct the.NET Maui Community Toolkit AvatarView!
  • Add the following namespace in the xaml file.
    xmlns:toolkit="clr-namespace:CommunityToolkit.Maui.Views;assembly=CommunityToolkit.Maui"
  • Once the namespace added, you have to add the AvatarView tag with the properties that we required like below.
    <toolkit:AvatarView Text="AM"
    					FontSize="30"
                        TextColor="White"
                        BackgroundColor="Green"
                        BorderColor="White"
                        BorderWidth="5" 
                        HeightRequest="150"
                        WidthRequest="150"                                
                        CornerRadius="120"
                        ImageSource="dotnet_bot.png"/>
  • AvatarView’s properties

    • Text: This property help to set the text to the view
    • ImageSource: This property help to set the image to the view
    • CornerRadius: Determines the shape of the control. The properties can be set in the below ways.
    • Sample 1: CornerRadius="120"
    • Sample 2: CornerRadius="120,40,120,40"

    Full Code:

    Demo

    Download Code:

    You can download the code from GitHub. If you have any doubts, feel free to post a comment. If you liked this article, and it is useful to you, do like, share the article & star the repository on GitHub.

.NET MAUI is a powerful platform for building cross-platform mobile applications, and with the right tools and resources, it's...

Signature Pad using .NET MAUI Community Toolkit Signature Pad using .NET MAUI Community Toolkit

A blog about android developement

.NET MAUI is a powerful platform for building cross-platform mobile applications, and with the right tools and resources, it's easy to add signature pad functionality to your app. In this tutorial, we'll walk you through the steps of signature pad in .NET MAUI using .NET MAUI Community Toolkit.


Quick Links:


Project Setup:

  • Launch Visual Studio 2022, and in the start window click Create a new project to create a new project.
  • In the Create a new project window, select MAUI in the All project types drop-down, select the .NET MAUI App template, and click the Next button:
  • In the configure your new project window, name your project, choose a suitable location for it, and click the Next button:
  • In the Additional information window, click the Create button:
  • Once the project is created, we can able to see the Android, iOS, Windows and other running options in the toolbar. Press the emulator or run button to build and run the app

Implementation:

.NET MAUI Community Toolkit is the key to achieve drawing in our App is to use Community.ToolKit.Maui NuGet package. It is a collection of reusable elements such as animations, behaviors converters, among others, for developing applications for iOS, Android, macOS and WinUI using MAUI.


Install .NET MAUI Community Toolkit

  • Install .NET MAUI Community Toolkit nuGet package on your .NET MAUI application.
  • Now initialize the plugin. Go to your MauiProgram.cs file. In the CreateMauiApp method, place in the .UseMauiApp<App>() line and just below it add the following line of code.
var builder = MauiApp.CreateBuilder();
builder
	.UseMauiApp<App>()
	.UseMauiCommunityToolkit()
	.ConfigureFonts(fonts =>
	{
		fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
		fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold");
	});
  • DrawView is a class provided by Community.Toolkit.Maui which is responsible for providing a surface that allows drawing lines through touch or mouse interaction.
  • Add the following namespace in the xaml file.
    xmlns:mct="clr-namespace:CommunityToolkit.Maui.Views;assembly=CommunityToolkit.Maui"
  • Once the namespace added, you have to add the DrawingView tag with the properties that we required like below.
    <mct:DrawingView x:Name="DrawBoard"
                        LineColor="Black"
                        LineWidth="5" 
                        HorizontalOptions="FillAndExpand"
                        VerticalOptions="FillAndExpand"
                        HeightRequest="250"
                        IsMultiLineModeEnabled="True"
                        DrawingLineCompleted="DrawBoard_DrawingLineCompleted"
                        BackgroundColor="AliceBlue"/>
  • DrawingView’s properties

    • WidthRequest and HeightRequest: These properties help to set the width and height respectively.
      Keep in mind that you must add both properties to your DrawingView in order for it to be displayed correctly in your app.
    • LineColor: It’s the color of the drawing line.
    • LineWidth: It’s the width of the drawing line.
    • IsMultiLineModeEnabled: By default, the DrawingView allows only one stroke to be drawn at a time. The IsMultiLineModeEnabled property allows you to change this and draw multiple lines at once. It receives Bool values. To activate it you need to set the value to True.

    Cleaning the DrawView:

    • If you want to clear the DrawView, add the following
      DrawBoard.Lines.Clear();
    • The clear function can be called using the button click event and can be called like below
      <Button Text="Clear Board" 
                          Clicked="Button_Clicked"/>
      void Button_Clicked(System.Object sender, System.EventArgs e)
      {
      	DrawBoard.Lines.Clear();
      }

    Previewing the signature or drawing from DrawView:

    • Add an Image control to your XAML.
    • <Image x:Name="ImageView"
             WidthRequest="200"
             HeightRequest="200"/>
  • Add an event for DrawingLineCompleted in the code behind.
  • private void DrawBoard_DrawingLineCompleted(System.Object sender, CommunityToolkit.Maui.Core.DrawingLineCompletedEventArgs e)
    {
    	ImageView.Dispatcher.Dispatch(async() =>
    	{
    		var stream = await DrawBoard.GetImageStream(300, 300);
    		ImageView.Source = ImageSource.FromStream(() => stream);
    	});
    }
Full Code:

Demo

Download Code:

You can download the code from GitHub. If you have any doubts, feel free to post a comment. If you liked this article, and it is useful to you, do like, share the article & star the repository on GitHub.

Install On Air: Without going through the official App Store approval procedure, InstallOnAir is an online platform that lets iOS...

How to install the Adhoc iOS app without using Mac Machine - InstallOnAir How to install the Adhoc iOS app without using Mac Machine - InstallOnAir

A blog about android developement

Install On Air:

Without going through the official App Store approval procedure, InstallOnAir is an online platform that lets iOS app developers distribute their programs to a select group of users. The platform is user-friendly and gives developers an easy way to distribute their apps to beta testers, customers, and other interested parties.


Developers can utilize the platform to test their apps with a select number of users before making them available to the wider public. Since customers who are familiar with their specific wants and expectations may provide input, this is particularly crucial for developers who are creating apps for niche markets or audiences.


Developers only need to upload their software file, create an installation link, and publish it with their target audience to use InstallOnAir. By clicking the URL the developer has supplied, users can then download the software immediately to their iOS devices. The platform also provides analytics to help developers track downloads and user engagement.


The ability to circumvent the App Store approval process is one of the main advantages of InstallOnAir. For developers who are eager to get their app in front of customers, the review process can be time-consuming and irritating even while it is crucial for guaranteeing the quality and safety of apps. By using InstallOnAir, developers can skip the review process and quickly distribute their app to a limited audience.


The fact that InstallOnAir offers a straightforward and user-friendly interface for both developers and consumers is another advantage. The platform is simple to use, and downloading or uploading programs doesn't require any technical knowledge. This opens it up to a variety of people, including those who might not be familiar with the iOS ecosystem or the App Store.


InstallOnAir should not be utilized in place of the official App Store review procedure, it is crucial to remember this. App developers shouldn't rely entirely on InstallOnAir to distribute their programs; the approval procedure is in place to guarantee the reliability and safety of apps. It is also important to follow Apple's guidelines for app development and distribution to avoid any potential legal or technical issues.


How to use?

  • Upload your IPA file for iOS or APK file for Android.
  • Click on Submit to get the installation link.
  • Share that link to your clients, friends or developers or use it for your own device.
  • Open that link in particular device.Either iOS or Android.

Conclusion:

InstallOnAir is a helpful solution for iOS app developers that wish to distribute their programs to a specific audience without going through the App Store approval procedure, to sum up. The platform offers a straightforward and user-friendly interface for developers as well as users, and it can assist developers in gathering insightful feedback from their intended audience. To guarantee the caliber and security of their programs, developers should use InstallOnAir in conjunction with the official App Store review procedure and adhere to Apple's rules for app development and distribution.