MSDEVBUILD - Community of Microsoft AI, Azure and Xamarin by Suthahar - Solution Architect for Microsoft AI, Azure, Xamarin | Tech Author and Speaker
public class Startup : IStartup
{
public void Configure(IAppHostBuilder appBuilder)
{
appBuilder .UseMauiApp<App>();
}
}
appBuilder
.UseFormsCompatibility()
.UseMauiApp<App>()
.ConfigureFonts(fonts => {
fonts.AddFont("ionicons.ttf", "IonIcons");
})
public void Configure(IAppHostBuilder appBuilder)
{
appBuilder
.ConfigureLifecycleEvents(lifecycle => {
#if ANDROID
lifecycle.AddAndroid(d => {
d.OnBackPressed(activity => {
System.Diagnostics.Debug.WriteLine("Back button pressed!");
});
});
#endif
});
}
using Microsoft.Maui;
using Microsoft.Maui.Controls.PlatformConfiguration.WindowsSpecific;
namespace HelloMaui
{
public partial class App : Microsoft.Maui.Controls.Application
{
public App()
{
InitializeComponent();
}
public override IWindow CreateWindow(IActivationState activationState)
{
Microsoft.Maui.Controls.Compatibility.Forms.Init(activationState);
this.On<Microsoft.Maui.Controls.PlatformConfiguration.Windows>()
.SetImageDirectory("Assets");
return new MainWindow();
}
}
}
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="HelloMaui.MainPage"
BackgroundColor="{DynamicResource PageBackgroundColor}">
<ScrollView>
<StackLayout Padding="{OnPlatform iOS='30,60,30,30', Default='30'}">
<Label Text="Getting started with MAUI Xamarin Forms Application using Visual Studio 2019 Preview 16.10"
SemanticProperties.HeadingLevel="Level1"
FontSize="32"
HorizontalOptions="CenterAndExpand" />
<Label Text="Welcome to .NET MAUI!"
HorizontalOptions="CenterAndExpand" />
<Image
Source="dotnet_bot.png"
SemanticProperties.Description="Cute dotnet bot waving hi to you!"
Margin="40,0" />
</StackLayout>
</ScrollView>
</ContentPage>
{
"sdk": {
"version": "6.0.100-preview.3.21202.5",
"rollForward": "disable",
"allowPrerelease": true
}
}
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<clear />
<!-- ensure only the sources defined below are used -->
<add key="dotnet6" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet6/nuget/v3/index.json" />
<add key="xamarin" value="https://pkgs.dev.azure.com/azure-public/vside/_packaging/xamarin-impl/nuget/v3/index.json" />
<add key="public" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-public/nuget/v3/index.json" />
</packageSources>
<config>
<add key="globalPackagesFolder" value="packages" />
</config>
</configuration>
dotnet build HelloMauiYou can launch the Android project to an attached emulator or device
dotnet build HelloMaui -t:Run -f net6.0-android
dotnet build HelloMaui -t:Run -f net6.0-iosOnce the build is successful, the iOS simulator/ Device will show the output like below

Microsoft AI, Azure & Xamarin specialist. Tech Author, Speaker & Community Builder since 2007.