Introduction Supercharge your .NET MAUI projects with Lottie animations! Imagine it as the magic wand for your app's visuals....

Lottie animations in .NET MAUI Lottie animations in .NET MAUI

A blog about android developement

Introduction

Supercharge your .NET MAUI projects with Lottie animations! Imagine it as the magic wand for your app's visuals. Thanks to Adobe After Effects, Lottie speaks a special language called JSON, making animations a breeze. Meet SkiaSharp, a Microsoft buddy that helps Lottie shine in .NET MAUI, making your app look cool without the complexity. Learn the ropes in our beginner-friendly guide! Add a dash of Lottie, sprinkle in some JSON magic, and watch your app come to life!


Top advantages of Lottie Animations:

  • Vector-based Adaptability: Lottie animations, being vector-based, ensure seamless scalability without compromising resolution.
  • Reduced File Size: Compared to formats like GIF or MP4, Lottie files boast significantly smaller sizes while maintaining top-notch quality.

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 Plugin:

  • Library Requirement: SkiaSharp library is essential for displaying Lottie animations.
  • Installation via NuGet: Obtain the SkiaSharp library by searching for "SkiaSharp.Extended.UI.Maui" in the NuGet Package Manager.
  • Enable Prerelease: Ensure the "Include prerelease" flag is enabled during installation, as MAUI support is currently in prerelease.
  • User Interface Guidance: Open the NuGet Package Manager interface to facilitate the installation process.
  • Visual Confirmation: The library, once searched, should appear as "SkiaSharp.Extended.UI.Maui" in the NuGet interface.

Implementation

  • First, we need to open "MauiProgram.cs" and include the following namespace and line to allow the app to use the Lottie Animations.
    using SkiaSharp.Views.Maui.Controls.Hosting;
    .UseSkiaSharp()
  • Open MainPage.xaml file and add the following namespace. (the page will be replaced according to you)
    xmlns:skia="clr-namespace:SkiaSharp.Extended.UI.Controls;assembly=SkiaSharp.Extended.UI"
  • Unlocking the magic of Lottie animations in your .NET MAUI app is a breeze! If you have JSON files, just add them to the Resources\Raw subfolder. For web-hosted animations, effortlessly consume them by passing the URI to the Lottie view. Explore the treasure trove of free and paid animations on Lottiefiles.com, a popular source for dynamic visuals. In our example, we'll use a JSON animation from the Lottie library repository, already included in the code for your convenience. Feel free to switch it up with your preferred animation!
  • We need to add the animation to the Raw folder: Go to Resources ➡ Raw ➡ Right click add ➡ Existing files ➡ animation.json (walking_batman.json in my sample).
  • <skia:SKLottieView RepeatCount="-1"
                               RepeatMode="Reverse"
                               Source="walking_batman.json" 
                               HeightRequest="400"
                               WidthRequest="400" />
  • <skia:SKLottieView>: This is the declaration of the SKLottieView, a specialized view for rendering Lottie animations using the SkiaSharp library.
  • RepeatCount="-1": The RepeatCount attribute determines how many times the animation should repeat. A value of -1 means it will repeat indefinitely.
  • RepeatMode="Reverse": The RepeatMode attribute sets the behavior of the animation when it repeats. In this case, "Reverse" means the animation will play in reverse each time it repeats.
  • Source="walking_batman.json": Specifies the source of the Lottie animation. In this example, the animation is loaded from a file named "Girl.json" located in the project.
  • HeightRequest="400" and WidthRequest="400": These attributes set the desired height and width of the SKLottieView, in this case, both set to 400. This property is very important to visualize Lottie animation.
  • This code essentially integrates a Lottie animation (from the "walking_batman.json" file) into your Xamarin.Forms application, configuring its repeat behavior and dimensions. Adjust these attributes based on your specific animation and layout requirements.


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.

Introduction Our phones and computers are like magic doors to the world, thanks to the apps we use every day. These apps show us ...

Transforming Labels into Hyperlinks with .NET MAUI Transforming Labels into Hyperlinks with .NET MAUI

A blog about android developement

Introduction

Our phones and computers are like magic doors to the world, thanks to the apps we use every day. These apps show us stuff using a mix of words, pictures, and special links that let us explore more. 🌐 Links, especially, make it easy for us to dive deep into things. In this guide, we'll learn how to add these special links to your .NET MAUI apps, making it more fun for people to check out what you have to share. Join us on this enlightening journey as we unravel the secrets of Transforming Labels into Hyperlinks with .NET MAUI.


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

  • In this step, we'll include two labels within the horizontal layout to position them closely to each other.
  • The first text will serve as regular text, representing the standard label.
  • The second text will function as a hyperlink, characterized by blue text color and underlined as text decoration.
  • The following code snippet will help in grasping the concept more clearly.
  • <HorizontalStackLayout>
    	<Label
    		Text="To know more about .NET MAUI "
    		SemanticProperties.HeadingLevel="Level1"
    		FontSize="Default"
    		HorizontalOptions="Center" />
    
    	<Label
    		Text="Visit Here"
    		TextDecorations="Underline"
    		TextColor="Blue"
    		SemanticProperties.HeadingLevel="Level1"
    		FontSize="Default"
    		HorizontalOptions="Center" >
    		<Label.GestureRecognizers>
    			<TapGestureRecognizer Tapped="OnUrlClicked"/>
    		</Label.GestureRecognizers>
    	</Label>
    </HorizontalStackLayout>
  • Incorporate the tap gesture event "OnUrlClicked" to open the specified URL link, as demonstrated below.
    private async void OnUrlClicked(object sender, TappedEventArgs e)
    {
    	await Launcher.OpenAsync("https://www.androidmads.info/search/label/.net%20maui");
    }

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.

Introduction Welcome to our newest blog post, where we explore the vibrant realm of MVVM (Model-View-ViewModel) architecture usin...

Mastering MVVM: A Deep Dive into .NET MAUI with MVVM Toolkit Mastering MVVM: A Deep Dive into .NET MAUI with MVVM Toolkit

A blog about android developement

Introduction

Welcome to our newest blog post, where we explore the vibrant realm of MVVM (Model-View-ViewModel) architecture using the cutting-edge MVVM Toolkit in .NET MAUI. In this comprehensive guide, we will unravel the intricacies of MVVM and demonstrate how the MVVM Toolkit in .NET MAUI empowers developers to create robust, responsive, and easily maintainable cross-platform mobile applications. Join us on this enlightening journey as we unravel the secrets of mastering MVVM in the context of .NET MAUI.


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 Plugin:

In this steps, we will see the steps to install "MVVM Toolkit" in .NET MAUI project:
  • Access NuGet Package Manager: In Visual Studio, right-click on your .NET MAUI project in the Solution Explorer. From the context menu, select "Manage NuGet Packages."
  • Search for "CommunityToolkit.Mvvm": In the NuGet Package Manager, click on the "Browse" tab. In the search bar, type "CommunityToolkit.Mvvm" and hit Enter. The package should appear in the search results.
  • Select and Install the Package: Once you find "CommunityToolkit.Mvvm" in the search results, click on it to select it. Ensure you choose the appropriate version compatible with your .NET MAUI project. Click on the "Install" button to begin the installation process.
  • Accept License Agreement: During the installation, you may be prompted to accept the license agreement. Review the terms and conditions and click on the "Accept" button to proceed.
  • Wait for Installation to Complete: Visual Studio will download and install the package along with its dependencies. This process may take a few moments, depending on your internet connection speed.
  • Verify Installation: After the installation is complete, verify that there are no error messages in the Output window. This indicates a successful installation of the package.

Implementation

View Model

  • In this step, we create a ViewModel that inherits from the ObservableObject class. This inheritance is pivotal because ObservableObject implements the INotifyPropertyChanged interface. By doing so, we gain the ability to trigger the PropertyChanged event, a vital mechanism enabling the notification of property value changes to subscribers, primarily the UI. This synchronization is fundamental for effective data binding, ensuring seamless coordination between the user interface and the underlying ViewModel.

    For example:
    public partial class ItemEntryPageModel : ObservableObject
    {
        [ObservableProperty]
        private int _id;
        [ObservableProperty]
    	private string _name;
    	[ObservableProperty]
    	private string _description;
    
        [ICommand]
    	public async void Save()
    	{
            await Application.Current.MainPage.DisplayAlert("MAUI MVVM Sample", "Item Saved Successfully", "OK");
        }
    }
  • When we use the [ObservableProperty] attribute, properties can send automatic alerts when they change. This is important for connecting data and updating the user interface (UI) when properties change. When you apply the [ObservableProperty] attribute to a property, it does a lot of necessary coding work behind the scenes. It sets up the code needed to tell other parts of the program when a property changes. This attribute saves time because you don't have to write all this code manually. For Example: "_description" & "_name" produces "Description" & "Name" respectively.
  • The [ICommand] implementation is a way to connect methods or actions in the app with what the user sees on the screen. For instance, it can create a command called SaveCommand that's linked to the Save method. This linking is crucial for making sure that when a user does something, like clicking a button, the right action happens in the app.

View

  • Finally, we will design the View, where we create the user interface using XAML. Here, we connect the UI elements to the ViewModel properties using data binding expressions.
  • This connection enables the View to show and modify task data in real-time, ensuring a dynamic and responsive user experience.
  • <?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="MauiMVVM.Views.ItemEntryPage"
                 Title="Item Entry">
        <StackLayout Margin="20"
                     Spacing="10">
            <VerticalStackLayout>
                <Label Text="Name:"
                       FontSize="16"/>
                <Entry Text="{Binding Name}" 
                       Placeholder="Item Name"/>
            </VerticalStackLayout>
    
            <VerticalStackLayout>
                <Label Text="Description:"
                       FontSize="16"/>
                <Entry Text="{Binding Description}" 
                       Placeholder="Item Description"/>
            </VerticalStackLayout>
    
    
            <Button x:Name="btn_save" 
                    Text="Save"
                    Command="{Binding SaveCommand}"/>
        </StackLayout>
    </ContentPage>
  • In .NET MAUI, data binding makes sure that data stays in sync between the ViewModel and the View without manual intervention.
  • For instance, we can link a task's title in the ViewModel to a label in the View. When the title changes, it instantly updates in the UI.
  • This automatic synchronization simplifies UI updates and eliminates the need for handling events manually.

Wire-up View and View Model

  • The created view and view model should be added in MauiProgram.cs like below.
    var builder = MauiApp.CreateBuilder();
    		builder
    			.UseMauiApp<App>()
    			.ConfigureFonts(fonts =>
    			{
    				fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
    				fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold");
    			});
    
    #if DEBUG
    		builder.Logging.AddDebug();
    #endif
            builder.Services.AddTransient<ItemEntryPage>();
            builder.Services.AddTransient<ItemEntryPageModel>();
    
            return builder.Build();

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

To learn more about Data binding and MVVM

Introduction Welcome to our newest blog post, where we explore the vibrant realm of app development with .NET MAUI! In this deta...

Dev Express - Data Grid Control for .NET MAUI (Lifetime - Free plugin) Dev Express - Data Grid Control for .NET MAUI (Lifetime - Free plugin)

A blog about android developement

Introduction

Welcome to our newest blog post, where we explore the vibrant realm of app development with .NET MAUI! In this detailed guide, we dive into the intricacies of the "DataGrid Control for .NET MAUI," an outstanding free plugin crafted to simplify your data management process. Uncover how this plugin enables developers to effortlessly sort, filter, and present data, elevating user experiences across cross-platform applications.


Telerik, SyncFusion, and DevExpress offer paid licenses, often accompanied by trial versions or community licenses under specific terms. However, DevExpress stands out by providing a set of controls that you can use absolutely free!. As the demand for seamless data visualization and interaction grows, this free plugin emerges as a game-changer for .NET MAUI enthusiasts.


How can I obtain a free license for DevExpress?

  • Visit the following link FREE Xamarin UI Controls
  • Click "GET IT FREE" button in the screen, will redirect to another page.
  • In this page, you need to enter your details and valid mail id.
  • After the successful submission, the DevExpress team will send the nuget api link to the entered email id.

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 Plugin:

In this steps, we will see the steps to install "DevExpress Grid" in Visual Studio 2022:
  • Access NuGet Package Manager: In Visual Studio, right-click on your .NET MAUI project in the Solution Explorer. From the context menu, select "Manage NuGet Packages."
  • Search for "DevExpress.XamarinForms.DataGrid": In the NuGet Package Manager, click on the "Browse" tab. In the search bar, type "DevExpress.XamarinForms.DataGrid" and hit Enter. The package should appear in the search results.
  • Select and Install the Package: Once you find "DevExpress.XamarinForms.DataGrid" in the search results, click on it to select it. Ensure you choose the appropriate version compatible with your .NET MAUI project. Click on the "Install" button to begin the installation process.
  • Accept License Agreement: During the installation, you may be prompted to accept the license agreement. Review the terms and conditions and click on the "Accept" button to proceed.
  • Wait for Installation to Complete: Visual Studio will download and install the package along with its dependencies. This process may take a few moments, depending on your internet connection speed.
  • Verify Installation: After the installation is complete, verify that there are no error messages in the Output window. This indicates a successful installation of the package.

Implementation

Open MauiProgram.cs file, and add ".UseDevExpress()" in builder like below

var builder = MauiApp.CreateBuilder();
builder
.UseMauiApp<App>()
.UseDevExpress()
.ConfigureFonts(fonts =>
{
fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold");
});

Add Namespace in XAML:

In your .NET MAUI XAML files where you intend to use the Dev Express - DataGrid, make sure to add the appropriate XML namespace. For example:

xmlns:dxg="clr-namespace:DevExpress.Maui.DataGrid;assembly=DevExpress.Maui.DataGrid"
xmlns:dxe="clr-namespace:DevExpress.Maui.Editors;assembly=DevExpress.Maui.Editors"
xmlns:dxc="clr-namespace:DevExpress.Maui.Controls;assembly=DevExpress.Maui.Controls"

Adjust the namespace and assembly name based on the specifics of the DataGrid component you installed.


Implement DataGrid in Your XAML:

You can now implement the DataGrid control in your XAML files using the namespace you added. For example:

<dg:DataGrid RefreshingEnabled="True"
             BackgroundColor="White"
                     IsRefreshing="{Binding Refreshing}"
                     PullToRefreshCommand="{Binding OnDataGridRefreshCommand}"
                     SelectionEnabled="True"
                     SelectedItem="{Binding SelectedItem}"
                     RowHeight="70"
                     HeaderHeight="70"
                     ItemsSource="{Binding Items}"
                     HeaderBackground="Red">

    <dg:DataGrid.NoDataView>
        <Label Text="Nothing to see here" HorizontalOptions="Center" VerticalOptions="Center" />
    </dg:DataGrid.NoDataView>
    <dg:DataGrid.Columns>
        <dg:DataGridColumn Title="Image" PropertyName="Image" Width="150" SortingEnabled="False">
            <dg:DataGridColumn.CellTemplate>
                <DataTemplate>
                    <Image Source="{Binding}" HorizontalOptions="Center" VerticalOptions="Center"
                           Aspect="AspectFit" HeightRequest="60" />
                </DataTemplate>
            </dg:DataGridColumn.CellTemplate>
        </dg:DataGridColumn>
        <dg:DataGridColumn Title="Name" PropertyName="Name" Width="100"/>
        <dg:DataGridColumn Title="Location" PropertyName="Location"  Width="100"/>
        <dg:DataGridColumn Title="Population" PropertyName="Population"  Width="100"/>
        <dg:DataGridColumn Title="Latitude" PropertyName="Latitude"  Width="100"/>
        <dg:DataGridColumn Title="Longitude" PropertyName="Longitude"  Width="100"/>
    </dg:DataGrid.Columns>
    <dg:DataGrid.RowsBackgroundColorPalette>
        <dg:PaletteCollection>
            <Color>#e1e1e1</Color>
            <Color>#ffffff</Color>
        </dg:PaletteCollection>
    </dg:DataGrid.RowsBackgroundColorPalette>
</dg:DataGrid>

The above code snippet represents a DataGrid component in .NET MAUI application. Let's break down the properties and their meanings in the context of this DataGrid:

  • ItemsSource="{Binding Items}": Binds the DataGrid to a collection of items represented by the "Items" property in the ViewModel. Each item in this collection corresponds to a row in the DataGrid.
  • dxg:DataGridView.Columns: Specifies the columns to be displayed in the DataGrid.
  • dxg:TemplateColumn: We can use the custom templated column
  • dxg:TextColumn: Used to display the values in the column
  • dxg:DateColumn: Used to display the date values with datepicker selection in the column
  • dxg:ComoboxColumn: Used to display the values with dropdown selection in the column
  • dxg:CheckBoxColumn : Used to display the boolen selection with checkbox in the column

The below code snippet configures a DataGrid component with specific properties and templates, allowing users to view and interact with data in a visually appealing manner.


The Code Behind or MVVM view model properties are similar to listview control and no specific code required

using System.Collections.ObjectModel;
using System.Net.Http;
using System.Net.Http.Json;

namespace MauiDevExpress
{
    public partial class MainPage : ContentPage
    {
        public MainPage()
        {
            BindingContext = this;
            InitializeComponent();
        }

        protected override async void OnAppearing()
        {
            base.OnAppearing();
            await Task.Delay(2000);
            LoadData();
        }

        private void LoadData()
        {
            var monkeys = new List<Monkey>
            {
                new Monkey
                {
                    Name = "Chimpanzee",
                    Location = "Africa",
                    Details = "Chimpanzees are intelligent primates known for their problem-solving abilities.",
                    Image = "chimpanzee.jpg",
                    Population = 150000,
                    Latitude = -1.2921f,
                    Longitude = 36.8219f,
                    BirthDate = new DateTime(2000, 1, 15),
                    AccessLevel = AccessLevel.Admin
                },
                new Monkey
                {
                    Name = "Orangutan",
                    Location = "Borneo",
                    Details = "Orangutans are great apes native to the rainforests of Borneo and Sumatra.",
                    Image = "orangutan.jpg",
                    Population = 70000,
                    Latitude = 1.3521f,
                    Longitude = 110.4647f,
                    BirthDate = new DateTime(2005, 3, 20),
                    AccessLevel = AccessLevel.User
                },
                new Monkey
                {
                    Name = "Gorilla",
                    Location = "Africa",
                    Details = "Gorillas are the largest primates and share about 98.3% of their DNA with humans.",
                    Image = "gorilla.jpg",
                    Population = 100000,
                    Latitude = -0.2280f,
                    Longitude = 15.8277f,
                    BirthDate = new DateTime(1998, 7, 10),
                    AccessLevel = AccessLevel.Admin
                },
                // Add more monkey instances with BirthDate and AccessLevel properties
                new Monkey
                {
                    Name = "Howler Monkey",
                    Location = "South America",
                    Details = "Howler monkeys are known for their loud vocalizations that can be heard up to 3 miles away.",
                    Image = "howler_monkey.jpg",
                    Population = 50000,
                    Latitude = -14.2350f,
                    Longitude = -51.9253f,
                    BirthDate = new DateTime(2002, 5, 3),
                    AccessLevel = AccessLevel.User
                },
                new Monkey
                {
                    Name = "Capuchin Monkey",
                    Location = "Central and South America",
                    Details = "Capuchin monkeys are highly intelligent and are often used in scientific research.",
                    Image = "capuchin_monkey.jpg",
                    Population = 30000,
                    Latitude = 4.7100f,
                    Longitude = -74.0721f,
                    BirthDate = new DateTime(2007, 9, 18),
                    AccessLevel = AccessLevel.Admin
                },
                new Monkey
                {
                    Name = "Spider Monkey",
                    Location = "Central and South America",
                    Details = "Spider monkeys are known for their long limbs and prehensile tail, which they use to swing through trees.",
                    Image = "spider_monkey.jpg",
                    Population = 25000,
                    Latitude = 14.634915f,
                    Longitude = -90.506882f,
                    BirthDate = new DateTime(1999, 11, 7),
                    AccessLevel = AccessLevel.User
                },
                new Monkey
                {
                    Name = "Mandrill",
                    Location = "Africa",
                    Details = "Mandrills are colorful monkeys found in the rainforests of Central Africa.",
                    Image = "mandrill.jpg",
                    Population = 10000,
                    Latitude = 0.2280f,
                    Longitude = 14.8277f,
                    BirthDate = new DateTime(2004, 2, 14),
                    AccessLevel = AccessLevel.Admin
                },
                new Monkey
                {
                    Name = "Tarsier",
                    Location = "Southeast Asia",
                    Details = "Tarsiers are small primates known for their big eyes and unique hunting skills.",
                    Image = "tarsier.jpg",
                    Population = 5000,
                    Latitude = 9.3275f,
                    Longitude = 123.3076f,
                    BirthDate = new DateTime(2001, 8, 22),
                    AccessLevel = AccessLevel.User
                },
                new Monkey
                {
                    Name = "Golden Lion Tamarin",
                    Location = "Brazil",
                    Details = "Golden lion tamarins are endangered primates with striking orange fur and manes.",
                    Image = "golden_lion_tamarin.jpg",
                    Population = 1500,
                    Latitude = -22.9068f,
                    Longitude = -43.1729f,
                    BirthDate = new DateTime(2006, 12, 5),
                    AccessLevel = AccessLevel.Admin
                },
                new Monkey
                {
                    Name = "Proboscis Monkey",
                    Location = "Borneo",
                    Details = "Proboscis monkeys have large noses and are excellent swimmers.",
                    Image = "proboscis_monkey.jpg",
                    Population = 700,
                    Latitude = 2.4604f,
                    Longitude = 115.3502f,
                    BirthDate = new DateTime(2003, 4, 30),
                    AccessLevel = AccessLevel.User
                },
                // Add more monkey instances as needed
                // ...
            };

            dxg.ItemsSource = new ObservableCollection<Monkey>(monkeys);
        }


        public class Monkey
        {
            public string Name { get; set; }
            public string Location { get; set; }
            public string Details { get; set; }
            public string Image { get; set; }
            public int Population { get; set; }
            public float Latitude { get; set; }
            public float Longitude { get; set; }
            public AccessLevel AccessLevel { get; set; }
            public DateTime BirthDate { get; set; }
        }
        public enum AccessLevel
        {
            Admin,
            User
        }
    }

}

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

To learn more about DevExpress DataGrid

Introduction Welcome to our latest blog post, where we delve into the dynamic world of app development using .NET MAUI! In this comp...

Data Grid Control for .NET MAUI (Free plugin to Sort, Filter & Show Data) Data Grid Control for .NET MAUI (Free plugin to Sort, Filter & Show Data)

A blog about android developement

Introduction

Welcome to our latest blog post, where we delve into the dynamic world of app development using .NET MAUI! In this comprehensive guide, we explore the intricacies of the "DataGrid Control for .NET MAUI," an exceptional free plugin designed to streamline your data management process. Discover how this plugin empowers developers to effortlessly sort, filter, and display data, enhancing user experiences within cross-platform applications.


In our latest article, we unveil the power of the "DataGrid Control for .NET MAUI," an invaluable plugin that simplifies the complexities of data management in cross-platform app development. As the demand for seamless data visualization and interaction grows, this free plugin emerges as a game-changer for .NET MAUI enthusiasts.


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 Plugin:

In this steps, we will see the steps to install "akgul.Maui.DataGrid" in Visual Studio 2022:
  • Access NuGet Package Manager: In Visual Studio, right-click on your .NET MAUI project in the Solution Explorer. From the context menu, select "Manage NuGet Packages."
  • Search for "akgul.Maui.DataGrid": In the NuGet Package Manager, click on the "Browse" tab. In the search bar, type "akgul.Maui.DataGrid" and hit Enter. The package should appear in the search results.
  • Select and Install the Package: Once you find "akgul.Maui.DataGrid" in the search results, click on it to select it. Ensure you choose the appropriate version compatible with your .NET MAUI project. Click on the "Install" button to begin the installation process.
  • Accept License Agreement: During the installation, you may be prompted to accept the license agreement. Review the terms and conditions and click on the "Accept" button to proceed.
  • Wait for Installation to Complete: Visual Studio will download and install the package along with its dependencies. This process may take a few moments, depending on your internet connection speed.
  • Verify Installation: After the installation is complete, verify that there are no error messages in the Output window. This indicates a successful installation of the "akgul.Maui.DataGrid" package.

Implementation

Add Namespace in XAML:

In your .NET MAUI XAML files where you intend to use the DataGrid, make sure to add the appropriate XML namespace. For example:

xmlns:dg="clr-namespace:Maui.DataGrid;assembly=Maui.DataGrid"

Adjust the namespace and assembly name based on the specifics of the DataGrid component you installed.


Implement DataGrid in Your XAML:

You can now implement the DataGrid control in your XAML files using the namespace you added. For example:

<dg:DataGrid RefreshingEnabled="True"
             BackgroundColor="White"
                     IsRefreshing="{Binding Refreshing}"
                     PullToRefreshCommand="{Binding OnDataGridRefreshCommand}"
                     SelectionEnabled="True"
                     SelectedItem="{Binding SelectedItem}"
                     RowHeight="70"
                     HeaderHeight="70"
                     ItemsSource="{Binding Items}"
                     HeaderBackground="Red">

    <dg:DataGrid.NoDataView>
        <Label Text="Nothing to see here" HorizontalOptions="Center" VerticalOptions="Center" />
    </dg:DataGrid.NoDataView>
    <dg:DataGrid.Columns>
        <dg:DataGridColumn Title="Image" PropertyName="Image" Width="150" SortingEnabled="False">
            <dg:DataGridColumn.CellTemplate>
                <DataTemplate>
                    <Image Source="{Binding}" HorizontalOptions="Center" VerticalOptions="Center"
                           Aspect="AspectFit" HeightRequest="60" />
                </DataTemplate>
            </dg:DataGridColumn.CellTemplate>
        </dg:DataGridColumn>
        <dg:DataGridColumn Title="Name" PropertyName="Name" Width="100"/>
        <dg:DataGridColumn Title="Location" PropertyName="Location"  Width="100"/>
        <dg:DataGridColumn Title="Population" PropertyName="Population"  Width="100"/>
        <dg:DataGridColumn Title="Latitude" PropertyName="Latitude"  Width="100"/>
        <dg:DataGridColumn Title="Longitude" PropertyName="Longitude"  Width="100"/>
    </dg:DataGrid.Columns>
    <dg:DataGrid.RowsBackgroundColorPalette>
        <dg:PaletteCollection>
            <Color>#e1e1e1</Color>
            <Color>#ffffff</Color>
        </dg:PaletteCollection>
    </dg:DataGrid.RowsBackgroundColorPalette>
</dg:DataGrid>

The above code snippet represents a DataGrid component in .NET MAUI application. Let's break down the properties and their meanings in the context of this DataGrid:

  • RefreshingEnabled="True": Indicates that the DataGrid supports pull-to-refresh functionality. Users can pull down to refresh the data displayed in the grid.
  • BackgroundColor="White": Sets the background color of the entire DataGrid component to white.
  • IsRefreshing="{Binding Refreshing}": Binds the IsRefreshing property of the DataGrid to a boolean property named "Refreshing" in the underlying ViewModel. This property likely controls the visual indication of whether the DataGrid is currently refreshing data.
  • PullToRefreshCommand="{Binding OnDataGridRefreshCommand}": Binds the pull-to-refresh action to a command named "OnDataGridRefreshCommand" in the ViewModel. This command is executed when the user performs a pull-to-refresh gesture.
  • SelectionEnabled="True": Allows users to select rows in the DataGrid.
  • SelectedItem="{Binding SelectedItem}": Binds the selected item in the DataGrid to a property named "SelectedItem" in the ViewModel. This property holds the currently selected item in the grid.
  • RowHeight="70": Sets the height of each row in the DataGrid to 70 units.
  • HeaderHeight="70": Sets the height of the header row in the DataGrid to 70 units.
  • ItemsSource="{Binding Items}": Binds the DataGrid to a collection of items represented by the "Items" property in the ViewModel. Each item in this collection corresponds to a row in the DataGrid.
  • HeaderBackground="Red": Sets the background color of the header row to red.
  • dg:DataGrid.NoDataView: Defines a custom view to be displayed when there is no data to show in the DataGrid. In this case, a Label with the text "Nothing to see here" is centered both horizontally and vertically.
  • dg:DataGrid.Columns: Specifies the columns to be displayed in the DataGrid.
  • dg:DataGrid.RowsBackgroundColorPalette: Defines a color palette for alternating row colors in the DataGrid.

This code snippet configures a DataGrid component with specific properties and templates, allowing users to view and interact with data in a visually appealing manner.


The Code Behind or MVVM view model properties are similar to listview control and no specific code required


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

To learn more about Swipe View

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

.NET MAUI - Swipe View .NET MAUI - Swipe View

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 to use SwipeView in .NET MAUI project. SwipeView is a container control that wraps around an item of content, and provides context menu items that are revealed by a swipe gesture.


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

SwipeView defines the following attributes:

  • LeftItems: This property, of type SwipeItems, represents the swipe items accessible when swiping the control from the left side.
  • RightItems: This property, of type SwipeItems, represents the swipe items accessible when swiping the control from the right side.
  • TopItems: This property, of type SwipeItems, represents the swipe items accessible when swiping the control from top to bottom.
  • BottomItems: This property, of type SwipeItems, represents the swipe items accessible when swiping the control from bottom to top.
  • Threshold: This property, of type double, determines the number of device-independent units required to trigger a swipe gesture and fully reveal swipe items.

The SwipeView class additionally introduces three events:

  • SwipeStarted: This event is triggered when a swipe commences. It is accompanied by a SwipeStartedEventArgs object that includes a property named SwipeDirection of type SwipeDirection.
  • SwipeChanging: Raised during the progression of a swipe, the SwipeChanging event provides a SwipeChangingEventArgs object. This object encompasses a SwipeDirection property of type SwipeDirection and an Offset property of type double.
  • SwipeEnded: When a swipe concludes, the SwipeEnded event is raised. Its accompanying SwipeEndedEventArgs object contains a SwipeDirection property of type SwipeDirection and an IsOpen property of type bool.

Here's an example demonstrating how to create a SwipeView in XAML.

<SwipeView>
	<SwipeView.LeftItems>
		<SwipeItems>
			<SwipeItem Text="Favorite"
					   IconImageSource="heart.png"
					   BackgroundColor="LightGreen"
					   Invoked="OnFavoriteSwipeItemInvoked" />
		</SwipeItems>
	</SwipeView.LeftItems>
	<SwipeView.RightItems>
		<SwipeItems>
			<SwipeItem Text="Delete"
					   IconImageSource="delete.png"
					   BackgroundColor="LightPink"
					   Invoked="OnDeleteSwipeItemInvoked" />
		</SwipeItems>
	</SwipeView.RightItems>
	<!-- Content -->
	<Grid BackgroundColor="LightGray">
		<Label Text="Swipe Right or Left"
			   HorizontalOptions="Center"
			   VerticalOptions="Center" />
	</Grid>
</SwipeView>

In this example, we will use the listview to display the swipe view and the full example below

<?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="MauiSwipeView.MainPage">

    <ListView x:Name="list">
        <ListView.ItemTemplate>
            <DataTemplate>
                <ViewCell>
                    <SwipeView>
                        <SwipeView.LeftItems>
                            <SwipeItems>
                                <SwipeItem Text="Favorite"
										   IconImageSource="heart.png"
										   BackgroundColor="LightGreen"
										   Invoked="OnFavoriteSwipeItemInvoked" />
                            </SwipeItems>
                        </SwipeView.LeftItems>
                        <SwipeView.RightItems>
                            <SwipeItems>
                                <SwipeItem Text="Delete"
										   IconImageSource="delete.png"
										   BackgroundColor="LightPink"
										   Invoked="OnDeleteSwipeItemInvoked" />
                            </SwipeItems>
                        </SwipeView.RightItems>
                        <!-- Content -->
                        <Grid BackgroundColor="LightGray">
                            <Label Text="Swipe Right or Left"
								   HorizontalOptions="Center"
								   VerticalOptions="Center" />
                        </Grid>
                    </SwipeView>
                </ViewCell>
            </DataTemplate>
        </ListView.ItemTemplate>
    </ListView>

</ContentPage>

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

To learn more about Swipe View

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

MOPUP (Alternative of Rg.Plugin.Popup) in .NET MAUI MOPUP (Alternative of Rg.Plugin.Popup) 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.

Mopups is a replacement for the "Rg.Plugins.Popups" plugin for Xamarin. Mopups intends to provide a similar experience to this plugin, however also clean up the code base and provide forward looking enhancements.


In this article, we will see how we can see the alternative to Rg.Plugin.Popup - MOPUP Page 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

Install Plugins:

  • Open Nuget Package Manager. Search MOPUPS and click install to the install the plugins in the projects.

Implementation

Initialize Mopups

In your MauiProgram.cs file, inside the CreateMauiAppBuilder method, include a call to .ConfigureMopups() on the host builder to set up the Mopups library:

using Mopups;
// ... 
public static MauiApp CreateMauiAppBuilder()
{
    var builder = MauiApp.CreateBuilder();
    // Other configurations
    builder.ConfigureMopups();
    builder.Services.AddSingleton<IPopupNavigation>(MopupService.Instance);
    builder.Services.AddTransient<MainPage>();
    return builder.Build();
}

Create a Custom PopupPage

Include a new ContentPage in your project and update the base class of the XAML file to PopupPage. Don't forget to add the required namespace declaration for the Mopups.Pages namespace:
<?xml version="1.0" encoding="utf-8" ?>
<mopup:PopupPage xmlns="http://xamarin.com/schemas/2014/forms"
                 xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
                 xmlns:local="clr-namespace:YourNamespace"
                 xmlns:mopup="clr-namespace:Mopups.Pages;assembly=Mopups"
                 x:Class="YourNamespace.YourPopupPage">

    <!-- Your PopupPage content goes here -->

</mopup:PopupPage>

Create and Display the Popup

Open MainPage.xaml.cs add the event to open the popup like below.

public partial class MainPage : ContentPage
{
	IPopupNavigation popupNavigation;

	public MainPage(IPopupNavigation popupNavigation)
	{
		InitializeComponent();

		this.popupNavigation = popupNavigation;
	}

	private void OnCounterClicked(object sender, EventArgs e)
	{
		popupNavigation.PushAsync(new MyPopupPage());
	}
}

Add the following code to close the popup screen

MopupService.Instance.PopAsync();

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://github.com/LuckyDucko/Mopups