How to Run Aspose.CAD in Multi-platform App UI(MAUI)
Prerequisites
- Visual Studio 2022.
- NET 7 SDK is used in the example.
MAUI
.NET Multi-platform App UI (.NET MAUI) is a cross-platform framework for creating native mobile and desktop apps with C# and XAML. Using .NET MAUI, you can develop apps that can run on Android, iOS, macOS, and Windows from a single shared code-base.
.NET MAUI is open-source and is the evolution of Xamarin.Forms, extended from mobile to desktop scenarios, with UI controls rebuilt from the ground up for performance and extensibility. If you’ve previously used Xamarin.Forms to build cross-platform user interfaces, you’ll notice many similarities with .NET MAUI. However, there are also some differences. Using .NET MAUI, you can create multi-platform apps using a single project, but you can add platform-specific source code and resources if necessary. One of the key aims of .NET MAUI is to enable you to implement as much of your app logic and UI layout as possible in a single code-base.
Installation MAUI
- To create .NET MAUI apps, you’ll need the latest version of Visual Studio 2022
- Either install Visual Studio, or modify your existing installation, and install the .NET Multi-platform App UI development workload with its default optional installation options:
Create project
- Launch Visual Studio. 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, choose the version of .NET that you’d like to target and click the Create button:
- Wait for the project to be created and its dependencies to be restored
- Install the latest Aspose.CAD version from NuGet:
- Replace the code in MainPage.xaml
<?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="MauiApp1.MainPage"> <ScrollView> <VerticalStackLayout Spacing="25" Padding="30,0" VerticalOptions="Center"> <Label Text="Welcome to .NET MAUI!" VerticalOptions="Center" HorizontalOptions="Center" /> <Image x:Name="Base64DecodedImage" Source="dotnet_bot.png" SemanticProperties.Description="Cute dot net bot waving hi to you!" HeightRequest="600" HorizontalOptions="Center" /> <Label Text="Hello, World!" SemanticProperties.HeadingLevel="Level1" FontSize="32" HorizontalOptions="Center" /> <Label Text="Welcome to .NET Multi-platform App UI" SemanticProperties.HeadingLevel="Level2" SemanticProperties.Description="Welcome to dot net Multi platform App U I" FontSize="18" HorizontalOptions="Center" /> <Button x:Name="FileSelectrBtn" Text="Select file" SemanticProperties.Hint="Counts the number of times you click" Clicked="OnSelectFileClicked" HorizontalOptions="Center" /> <Button x:Name="ClearBtn" Text="Clear" SemanticProperties.Hint="Counts the number of times you click" Clicked="OnCleanClicked" HorizontalOptions="Center" /> </VerticalStackLayout> </ScrollView> </ContentPage>
- Add new methods in MainPage.xaml.cs
Don’t forget add using Aspose.CAD and using Aspose.CAD.ImageOptions in file.
private void OnCleanClicked(object sender, EventArgs e) { Base64DecodedImage.Source = "dotnet_bot.png"; } private async void OnSelectFileClicked(object sender, EventArgs e) { var result = await FilePicker.PickAsync(new PickOptions() { PickerTitle = "any" }); if (result == null) { return; } var stream = await result.OpenReadAsync(); var img = Aspose.CAD.Image.Load(stream); var ms = new MemoryStream(); await img.SaveAsync(ms, new PngOptions()); Base64DecodedImage.Source = ImageSource.FromStream(() => ms); }
Debug Windows Machine
- In the Visual Studio toolbar, use the Debug Target drop-down to select Framework and then the net7.0-windows entry:
- In the Visual Studio toolbar, press the Windows Machine button to build and run the app:
- In the running app, press the “Select file” button several times and observe that the count of the number of button clicks is incremented:
- Select the required file and click open:
- After processing the file, an image of the converted file should appear on the screen:
Install Android Emulator
- In the Visual Studio toolbar, use the Debug Target drop-down to select Android Emulators and then the Android Emulator entry
- In the Visual Studio toolbar, press the Android Emulator button:
- In the Android SDK - License Agreement window, press the Accept button:
- In the Android SDK - License Agreement window, press the Accept button:
- In the User Account Control dialog, press the Yes button:
- In the License Acceptance window, press the Accept button:
- In the Visual Studio toolbar, press the Android Emulator button:
- In the User Account Control dialog, press the Yes button:
- In the New Device window, press the Create button:
- Close the Android Device Manager window
Debug with Android Emulator
- In the Visual Studio toolbar, press the Pixel 5 - API 33 (Android 13.0 - API 33) button to build and run the app:
- In the running app in the Android emulator, press the “Select file” button several times and observe that the count of the number of button clicks is incremented:
- Select the required file and click select:
- After processing the file, an image of the converted file should appear on the screen:
More Examples
For more samples of how you can use Aspose.CAD in Docker, see the examples.