diff --git a/src/Templates/src/templates/maui-blazor/App.xaml.cs b/src/Templates/src/templates/maui-blazor/App.xaml.cs index 147ef09ada30..68334f8da5d1 100644 --- a/src/Templates/src/templates/maui-blazor/App.xaml.cs +++ b/src/Templates/src/templates/maui-blazor/App.xaml.cs @@ -1,17 +1,11 @@ -using Microsoft.Maui; -using Microsoft.Maui.Controls; -using Microsoft.Maui.Controls.PlatformConfiguration.WindowsSpecific; -using Application = Microsoft.Maui.Controls.Application; +namespace MauiApp._1; -namespace MauiApp._1 +public partial class App : Application { - public partial class App : Application + public App() { - public App() - { - InitializeComponent(); + InitializeComponent(); - MainPage = new MainPage(); - } + MainPage = new MainPage(); } } diff --git a/src/Templates/src/templates/maui-blazor/Data/WeatherForecast.cs b/src/Templates/src/templates/maui-blazor/Data/WeatherForecast.cs index 905541d8048d..ae62090cfc65 100644 --- a/src/Templates/src/templates/maui-blazor/Data/WeatherForecast.cs +++ b/src/Templates/src/templates/maui-blazor/Data/WeatherForecast.cs @@ -1,15 +1,12 @@ -using System; +namespace MauiApp._1.Data; -namespace MauiApp._1.Data +public class WeatherForecast { - public class WeatherForecast - { - public DateTime Date { get; set; } + public DateTime Date { get; set; } - public int TemperatureC { get; set; } + public int TemperatureC { get; set; } - public int TemperatureF => 32 + (int)(TemperatureC / 0.5556); + public int TemperatureF => 32 + (int)(TemperatureC / 0.5556); - public string Summary { get; set; } - } + public string Summary { get; set; } } diff --git a/src/Templates/src/templates/maui-blazor/Data/WeatherForecastService.cs b/src/Templates/src/templates/maui-blazor/Data/WeatherForecastService.cs index a1c36686a7bf..60b37c417636 100644 --- a/src/Templates/src/templates/maui-blazor/Data/WeatherForecastService.cs +++ b/src/Templates/src/templates/maui-blazor/Data/WeatherForecastService.cs @@ -1,24 +1,20 @@ -using System; -using System.Linq; -using System.Threading.Tasks; +namespace MauiApp._1.Data; -namespace MauiApp._1.Data +public class WeatherForecastService { - public class WeatherForecastService + private static readonly string[] Summaries = new[] { - private static readonly string[] Summaries = new[] - { - "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching" - }; + "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching" + }; - public Task GetForecastAsync(DateTime startDate) + public Task GetForecastAsync(DateTime startDate) + { + return Task.FromResult(Enumerable.Range(1, 5).Select(index => new WeatherForecast { - return Task.FromResult(Enumerable.Range(1, 5).Select(index => new WeatherForecast - { - Date = startDate.AddDays(index), - TemperatureC = Random.Shared.Next(-20, 55), - Summary = Summaries[Random.Shared.Next(Summaries.Length)] - }).ToArray()); - } + Date = startDate.AddDays(index), + TemperatureC = Random.Shared.Next(-20, 55), + Summary = Summaries[Random.Shared.Next(Summaries.Length)] + }).ToArray()); } } + diff --git a/src/Templates/src/templates/maui-blazor/GlobalUsings.cs b/src/Templates/src/templates/maui-blazor/GlobalUsings.cs new file mode 100644 index 000000000000..47acf5b44b52 --- /dev/null +++ b/src/Templates/src/templates/maui-blazor/GlobalUsings.cs @@ -0,0 +1,14 @@ +global using Microsoft.Extensions.DependencyInjection; +global using Microsoft.Maui; +global using Microsoft.Maui.Controls; +global using Microsoft.Maui.Controls.Hosting; +global using Microsoft.Maui.Controls.Xaml; +global using Microsoft.Maui.Essentials; +global using Microsoft.Maui.Hosting; +global using System; +global using System.Collections.Generic; +global using System.IO; +global using System.Linq; +global using System.Net.Http; +global using System.Threading; +global using System.Threading.Tasks; \ No newline at end of file diff --git a/src/Templates/src/templates/maui-blazor/MainPage.xaml.cs b/src/Templates/src/templates/maui-blazor/MainPage.xaml.cs index 0dbdbc7f3250..5bf5834c5f0c 100644 --- a/src/Templates/src/templates/maui-blazor/MainPage.xaml.cs +++ b/src/Templates/src/templates/maui-blazor/MainPage.xaml.cs @@ -1,13 +1,9 @@ -using System; -using Microsoft.Maui.Controls; +namespace MauiApp._1; -namespace MauiApp._1 +public partial class MainPage : ContentPage { - public partial class MainPage : ContentPage + public MainPage() { - public MainPage() - { - InitializeComponent(); - } + InitializeComponent(); } } diff --git a/src/Templates/src/templates/maui-blazor/MauiProgram.cs b/src/Templates/src/templates/maui-blazor/MauiProgram.cs index 6b3c8a54dcfd..6d5379b282e8 100644 --- a/src/Templates/src/templates/maui-blazor/MauiProgram.cs +++ b/src/Templates/src/templates/maui-blazor/MauiProgram.cs @@ -1,30 +1,24 @@ using Microsoft.AspNetCore.Components.WebView.Maui; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Maui; -using Microsoft.Maui.Hosting; -using Microsoft.Maui.Controls.Compatibility; -using Microsoft.Maui.Controls.Hosting; using MauiApp._1.Data; -namespace MauiApp._1 +namespace MauiApp._1; + +public static class MauiProgram { - public static class MauiProgram + public static MauiApp CreateMauiApp() { - public static MauiApp CreateMauiApp() - { - var builder = MauiApp.CreateBuilder(); - builder - .RegisterBlazorMauiWebView() - .UseMauiApp() - .ConfigureFonts(fonts => - { - fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular"); - }); + var builder = MauiApp.CreateBuilder(); + builder + .RegisterBlazorMauiWebView() + .UseMauiApp() + .ConfigureFonts(fonts => + { + fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular"); + }); - builder.Services.AddBlazorWebView(); - builder.Services.AddSingleton(); + builder.Services.AddBlazorWebView(); + builder.Services.AddSingleton(); - return builder.Build(); - } + return builder.Build(); } -} \ No newline at end of file +} diff --git a/src/Templates/src/templates/maui-blazor/Platforms/Android/MainActivity.cs b/src/Templates/src/templates/maui-blazor/Platforms/Android/MainActivity.cs index 7f12c68d473f..b189df660d25 100644 --- a/src/Templates/src/templates/maui-blazor/Platforms/Android/MainActivity.cs +++ b/src/Templates/src/templates/maui-blazor/Platforms/Android/MainActivity.cs @@ -1,11 +1,22 @@ using Android.App; using Android.Content.PM; -using Microsoft.Maui; +using Android.OS; -namespace MauiApp._1 +namespace MauiApp._1; + +[Activity(Theme = "@style/Maui.SplashTheme", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation | ConfigChanges.UiMode | ConfigChanges.ScreenLayout | ConfigChanges.SmallestScreenSize)] +public class MainActivity : MauiAppCompatActivity { - [Activity(Theme = "@style/Maui.SplashTheme", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation | ConfigChanges.UiMode | ConfigChanges.ScreenLayout | ConfigChanges.SmallestScreenSize)] - public class MainActivity : MauiAppCompatActivity + protected override void OnCreate(Bundle savedInstanceState) { + base.OnCreate(savedInstanceState); + Platform.Init(this, savedInstanceState); + } + + public override void OnRequestPermissionsResult(int requestCode, string[] permissions, Permission[] grantResults) + { + Platform.OnRequestPermissionsResult(requestCode, permissions, grantResults); + + base.OnRequestPermissionsResult(requestCode, permissions, grantResults); } -} \ No newline at end of file +} diff --git a/src/Templates/src/templates/maui-blazor/Platforms/Android/MainApplication.cs b/src/Templates/src/templates/maui-blazor/Platforms/Android/MainApplication.cs index 4fe7e7a9d8e5..83b97cfe1aeb 100644 --- a/src/Templates/src/templates/maui-blazor/Platforms/Android/MainApplication.cs +++ b/src/Templates/src/templates/maui-blazor/Platforms/Android/MainApplication.cs @@ -1,19 +1,15 @@ -using System; -using Android.App; +using Android.App; using Android.Runtime; -using Microsoft.Maui; -using Microsoft.Maui.Hosting; -namespace MauiApp._1 +namespace MauiApp._1; + +[Application] +public class MainApplication : MauiApplication { - [Application] - public class MainApplication : MauiApplication + public MainApplication(IntPtr handle, JniHandleOwnership ownership) + : base(handle, ownership) { - public MainApplication(IntPtr handle, JniHandleOwnership ownership) - : base(handle, ownership) - { - } - - protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp(); } -} \ No newline at end of file + + protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp(); +} diff --git a/src/Templates/src/templates/maui-blazor/Platforms/MacCatalyst/AppDelegate.cs b/src/Templates/src/templates/maui-blazor/Platforms/MacCatalyst/AppDelegate.cs index 1c07e0e4a78f..f703ee61a345 100644 --- a/src/Templates/src/templates/maui-blazor/Platforms/MacCatalyst/AppDelegate.cs +++ b/src/Templates/src/templates/maui-blazor/Platforms/MacCatalyst/AppDelegate.cs @@ -1,12 +1,9 @@ using Foundation; -using Microsoft.Maui; -using Microsoft.Maui.Hosting; -namespace MauiApp._1 +namespace MauiApp._1; + +[Register("AppDelegate")] +public class AppDelegate : MauiUIApplicationDelegate { - [Register("AppDelegate")] - public class AppDelegate : MauiUIApplicationDelegate - { - protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp(); - } -} \ No newline at end of file + protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp(); +} diff --git a/src/Templates/src/templates/maui-blazor/Platforms/MacCatalyst/Program.cs b/src/Templates/src/templates/maui-blazor/Platforms/MacCatalyst/Program.cs index c9227639e685..c817b80805b2 100644 --- a/src/Templates/src/templates/maui-blazor/Platforms/MacCatalyst/Program.cs +++ b/src/Templates/src/templates/maui-blazor/Platforms/MacCatalyst/Program.cs @@ -1,15 +1,14 @@ using UIKit; -namespace MauiApp._1 +namespace MauiApp._1; + +public class Program { - public class Program + // This is the main entry point of the application. + static void Main(string[] args) { - // This is the main entry point of the application. - static void Main(string[] args) - { - // if you want to use a different Application Delegate class from "AppDelegate" - // you can specify it here. - UIApplication.Main(args, null, typeof(AppDelegate)); - } + // if you want to use a different Application Delegate class from "AppDelegate" + // you can specify it here. + UIApplication.Main(args, null, typeof(AppDelegate)); } } \ No newline at end of file diff --git a/src/Templates/src/templates/maui-blazor/Platforms/Windows/App.xaml.cs b/src/Templates/src/templates/maui-blazor/Platforms/Windows/App.xaml.cs index 5e0e454ec7d3..784c92201fe2 100644 --- a/src/Templates/src/templates/maui-blazor/Platforms/Windows/App.xaml.cs +++ b/src/Templates/src/templates/maui-blazor/Platforms/Windows/App.xaml.cs @@ -1,34 +1,31 @@ -using Microsoft.Maui; -using Microsoft.Maui.Hosting; -using Microsoft.UI.Xaml; -using Windows.ApplicationModel; +using Microsoft.UI.Xaml; // To learn more about WinUI, the WinUI project structure, // and more about our project templates, see: http://aka.ms/winui-project-info. -namespace MauiApp._1.WinUI +namespace MauiApp._1.WinUI; + +/// +/// Provides application-specific behavior to supplement the default Application class. +/// +public partial class App : MauiWinUIApplication { /// - /// Provides application-specific behavior to supplement the default Application class. + /// Initializes the singleton application object. This is the first line of authored code + /// executed, and as such is the logical equivalent of main() or WinMain(). /// - public partial class App : MauiWinUIApplication + public App() { - /// - /// Initializes the singleton application object. This is the first line of authored code - /// executed, and as such is the logical equivalent of main() or WinMain(). - /// - public App() - { - this.InitializeComponent(); - } + this.InitializeComponent(); + } - protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp(); + protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp(); - protected override void OnLaunched(LaunchActivatedEventArgs args) - { - base.OnLaunched(args); + protected override void OnLaunched(LaunchActivatedEventArgs args) + { + base.OnLaunched(args); - Microsoft.Maui.Essentials.Platform.OnLaunched(args); - } + Platform.OnLaunched(args); } } + diff --git a/src/Templates/src/templates/maui-blazor/Platforms/iOS/AppDelegate.cs b/src/Templates/src/templates/maui-blazor/Platforms/iOS/AppDelegate.cs index 1c07e0e4a78f..f703ee61a345 100644 --- a/src/Templates/src/templates/maui-blazor/Platforms/iOS/AppDelegate.cs +++ b/src/Templates/src/templates/maui-blazor/Platforms/iOS/AppDelegate.cs @@ -1,12 +1,9 @@ using Foundation; -using Microsoft.Maui; -using Microsoft.Maui.Hosting; -namespace MauiApp._1 +namespace MauiApp._1; + +[Register("AppDelegate")] +public class AppDelegate : MauiUIApplicationDelegate { - [Register("AppDelegate")] - public class AppDelegate : MauiUIApplicationDelegate - { - protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp(); - } -} \ No newline at end of file + protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp(); +} diff --git a/src/Templates/src/templates/maui-blazor/Platforms/iOS/Program.cs b/src/Templates/src/templates/maui-blazor/Platforms/iOS/Program.cs index c9227639e685..9d4c5c10d63b 100644 --- a/src/Templates/src/templates/maui-blazor/Platforms/iOS/Program.cs +++ b/src/Templates/src/templates/maui-blazor/Platforms/iOS/Program.cs @@ -1,15 +1,14 @@ using UIKit; -namespace MauiApp._1 +namespace MauiApp._1; + +public class Program { - public class Program + // This is the main entry point of the application. + static void Main(string[] args) { - // This is the main entry point of the application. - static void Main(string[] args) - { - // if you want to use a different Application Delegate class from "AppDelegate" - // you can specify it here. - UIApplication.Main(args, null, typeof(AppDelegate)); - } + // if you want to use a different Application Delegate class from "AppDelegate" + // you can specify it here. + UIApplication.Main(args, null, typeof(AppDelegate)); } -} \ No newline at end of file +} diff --git a/src/Templates/src/templates/maui-lib/Class1.cs b/src/Templates/src/templates/maui-lib/Class1.cs index af03b9692d6a..90d85dc14ffb 100644 --- a/src/Templates/src/templates/maui-lib/Class1.cs +++ b/src/Templates/src/templates/maui-lib/Class1.cs @@ -1,9 +1,6 @@ -using System; +namespace MauiLib1; -namespace MauiLib1 +// All the code in this file is included in all platforms. +public class Class1 { - // All the code in this file is included in all platforms. - public class Class1 - { - } -} \ No newline at end of file +} diff --git a/src/Templates/src/templates/maui-lib/Platforms/Android/PlatformClass1.cs b/src/Templates/src/templates/maui-lib/Platforms/Android/PlatformClass1.cs index 8247e4af1424..ded3cc02ff58 100644 --- a/src/Templates/src/templates/maui-lib/Platforms/Android/PlatformClass1.cs +++ b/src/Templates/src/templates/maui-lib/Platforms/Android/PlatformClass1.cs @@ -1,9 +1,6 @@ -using System; +namespace MauiLib1; -namespace MauiLib1 +// All the code in this file is only included on Android. +public class PlatformClass1 { - // All the code in this file is only included on Android. - public class PlatformClass1 - { - } -} \ No newline at end of file +} diff --git a/src/Templates/src/templates/maui-lib/Platforms/MacCatalyst/PlatformClass1.cs b/src/Templates/src/templates/maui-lib/Platforms/MacCatalyst/PlatformClass1.cs index 404be11489fd..3897b9cd402b 100644 --- a/src/Templates/src/templates/maui-lib/Platforms/MacCatalyst/PlatformClass1.cs +++ b/src/Templates/src/templates/maui-lib/Platforms/MacCatalyst/PlatformClass1.cs @@ -1,9 +1,6 @@ -using System; +namespace MauiLib1; -namespace MauiLib1 +// All the code in this file is only included on Mac Catalyst. +public class PlatformClass1 { - // All the code in this file is only included on Mac Catalyst. - public class PlatformClass1 - { - } -} \ No newline at end of file +} diff --git a/src/Templates/src/templates/maui-lib/Platforms/Windows/PlatformClass1.cs b/src/Templates/src/templates/maui-lib/Platforms/Windows/PlatformClass1.cs index feb45db71f3f..0a25465d0855 100644 --- a/src/Templates/src/templates/maui-lib/Platforms/Windows/PlatformClass1.cs +++ b/src/Templates/src/templates/maui-lib/Platforms/Windows/PlatformClass1.cs @@ -1,9 +1,6 @@ -using System; +namespace MauiLib1; -namespace MauiLib1 +// All the code in this file is only included on Windows. +public class PlatformClass1 { - // All the code in this file is only included on Windows. - public class PlatformClass1 - { - } -} \ No newline at end of file +} diff --git a/src/Templates/src/templates/maui-lib/Platforms/iOS/PlatformClass1.cs b/src/Templates/src/templates/maui-lib/Platforms/iOS/PlatformClass1.cs index b48f3106af42..df8b1d52b427 100644 --- a/src/Templates/src/templates/maui-lib/Platforms/iOS/PlatformClass1.cs +++ b/src/Templates/src/templates/maui-lib/Platforms/iOS/PlatformClass1.cs @@ -1,9 +1,6 @@ -using System; +namespace MauiLib1; -namespace MauiLib1 +// All the code in this file is only included on iOS. +public class PlatformClass1 { - // All the code in this file is only included on iOS. - public class PlatformClass1 - { - } -} \ No newline at end of file +} diff --git a/src/Templates/src/templates/maui-mobile/App.xaml.cs b/src/Templates/src/templates/maui-mobile/App.xaml.cs index 147ef09ada30..68334f8da5d1 100644 --- a/src/Templates/src/templates/maui-mobile/App.xaml.cs +++ b/src/Templates/src/templates/maui-mobile/App.xaml.cs @@ -1,17 +1,11 @@ -using Microsoft.Maui; -using Microsoft.Maui.Controls; -using Microsoft.Maui.Controls.PlatformConfiguration.WindowsSpecific; -using Application = Microsoft.Maui.Controls.Application; +namespace MauiApp._1; -namespace MauiApp._1 +public partial class App : Application { - public partial class App : Application + public App() { - public App() - { - InitializeComponent(); + InitializeComponent(); - MainPage = new MainPage(); - } + MainPage = new MainPage(); } } diff --git a/src/Templates/src/templates/maui-mobile/GlobalUsings.cs b/src/Templates/src/templates/maui-mobile/GlobalUsings.cs new file mode 100644 index 000000000000..47acf5b44b52 --- /dev/null +++ b/src/Templates/src/templates/maui-mobile/GlobalUsings.cs @@ -0,0 +1,14 @@ +global using Microsoft.Extensions.DependencyInjection; +global using Microsoft.Maui; +global using Microsoft.Maui.Controls; +global using Microsoft.Maui.Controls.Hosting; +global using Microsoft.Maui.Controls.Xaml; +global using Microsoft.Maui.Essentials; +global using Microsoft.Maui.Hosting; +global using System; +global using System.Collections.Generic; +global using System.IO; +global using System.Linq; +global using System.Net.Http; +global using System.Threading; +global using System.Threading.Tasks; \ No newline at end of file diff --git a/src/Templates/src/templates/maui-mobile/MainPage.xaml.cs b/src/Templates/src/templates/maui-mobile/MainPage.xaml.cs index 70ce790edc5b..5825d4b101af 100644 --- a/src/Templates/src/templates/maui-mobile/MainPage.xaml.cs +++ b/src/Templates/src/templates/maui-mobile/MainPage.xaml.cs @@ -1,24 +1,20 @@ -using System; -using Microsoft.Maui.Controls; -using Microsoft.Maui.Essentials; +namespace MauiApp._1; -namespace MauiApp._1 +public partial class MainPage : ContentPage { - public partial class MainPage : ContentPage - { - int count = 0; + int count = 0; - public MainPage() - { - InitializeComponent(); - } + public MainPage() + { + InitializeComponent(); + } - private void OnCounterClicked(object sender, EventArgs e) - { - count++; - CounterLabel.Text = $"Current count: {count}"; + private void OnCounterClicked(object sender, EventArgs e) + { + count++; + CounterLabel.Text = $"Current count: {count}"; - SemanticScreenReader.Announce(CounterLabel.Text); - } + SemanticScreenReader.Announce(CounterLabel.Text); } } + diff --git a/src/Templates/src/templates/maui-mobile/MauiApp.1.csproj b/src/Templates/src/templates/maui-mobile/MauiApp.1.csproj index c730b09f441c..26838a0416ef 100644 --- a/src/Templates/src/templates/maui-mobile/MauiApp.1.csproj +++ b/src/Templates/src/templates/maui-mobile/MauiApp.1.csproj @@ -8,7 +8,7 @@ true true true - + MauiApp.1 @@ -30,10 +30,7 @@ - + diff --git a/src/Templates/src/templates/maui-mobile/MauiProgram.cs b/src/Templates/src/templates/maui-mobile/MauiProgram.cs index 2dc6c5c0edf7..a83edefa6c15 100644 --- a/src/Templates/src/templates/maui-mobile/MauiProgram.cs +++ b/src/Templates/src/templates/maui-mobile/MauiProgram.cs @@ -1,23 +1,17 @@ -using Microsoft.Maui; -using Microsoft.Maui.Hosting; -using Microsoft.Maui.Controls.Compatibility; -using Microsoft.Maui.Controls.Hosting; +namespace MauiApp._1; -namespace MauiApp._1 +public static class MauiProgram { - public static class MauiProgram + public static MauiApp CreateMauiApp() { - public static MauiApp CreateMauiApp() - { - var builder = MauiApp.CreateBuilder(); - builder - .UseMauiApp() - .ConfigureFonts(fonts => - { - fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular"); - }); + var builder = MauiApp.CreateBuilder(); + builder + .UseMauiApp() + .ConfigureFonts(fonts => + { + fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular"); + }); - return builder.Build(); - } + return builder.Build(); } -} \ No newline at end of file +} diff --git a/src/Templates/src/templates/maui-mobile/Platforms/Android/MainActivity.cs b/src/Templates/src/templates/maui-mobile/Platforms/Android/MainActivity.cs index 7f12c68d473f..b189df660d25 100644 --- a/src/Templates/src/templates/maui-mobile/Platforms/Android/MainActivity.cs +++ b/src/Templates/src/templates/maui-mobile/Platforms/Android/MainActivity.cs @@ -1,11 +1,22 @@ using Android.App; using Android.Content.PM; -using Microsoft.Maui; +using Android.OS; -namespace MauiApp._1 +namespace MauiApp._1; + +[Activity(Theme = "@style/Maui.SplashTheme", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation | ConfigChanges.UiMode | ConfigChanges.ScreenLayout | ConfigChanges.SmallestScreenSize)] +public class MainActivity : MauiAppCompatActivity { - [Activity(Theme = "@style/Maui.SplashTheme", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation | ConfigChanges.UiMode | ConfigChanges.ScreenLayout | ConfigChanges.SmallestScreenSize)] - public class MainActivity : MauiAppCompatActivity + protected override void OnCreate(Bundle savedInstanceState) { + base.OnCreate(savedInstanceState); + Platform.Init(this, savedInstanceState); + } + + public override void OnRequestPermissionsResult(int requestCode, string[] permissions, Permission[] grantResults) + { + Platform.OnRequestPermissionsResult(requestCode, permissions, grantResults); + + base.OnRequestPermissionsResult(requestCode, permissions, grantResults); } -} \ No newline at end of file +} diff --git a/src/Templates/src/templates/maui-mobile/Platforms/Android/MainApplication.cs b/src/Templates/src/templates/maui-mobile/Platforms/Android/MainApplication.cs index 4fe7e7a9d8e5..83b97cfe1aeb 100644 --- a/src/Templates/src/templates/maui-mobile/Platforms/Android/MainApplication.cs +++ b/src/Templates/src/templates/maui-mobile/Platforms/Android/MainApplication.cs @@ -1,19 +1,15 @@ -using System; -using Android.App; +using Android.App; using Android.Runtime; -using Microsoft.Maui; -using Microsoft.Maui.Hosting; -namespace MauiApp._1 +namespace MauiApp._1; + +[Application] +public class MainApplication : MauiApplication { - [Application] - public class MainApplication : MauiApplication + public MainApplication(IntPtr handle, JniHandleOwnership ownership) + : base(handle, ownership) { - public MainApplication(IntPtr handle, JniHandleOwnership ownership) - : base(handle, ownership) - { - } - - protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp(); } -} \ No newline at end of file + + protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp(); +} diff --git a/src/Templates/src/templates/maui-mobile/Platforms/MacCatalyst/AppDelegate.cs b/src/Templates/src/templates/maui-mobile/Platforms/MacCatalyst/AppDelegate.cs index 1c07e0e4a78f..f703ee61a345 100644 --- a/src/Templates/src/templates/maui-mobile/Platforms/MacCatalyst/AppDelegate.cs +++ b/src/Templates/src/templates/maui-mobile/Platforms/MacCatalyst/AppDelegate.cs @@ -1,12 +1,9 @@ using Foundation; -using Microsoft.Maui; -using Microsoft.Maui.Hosting; -namespace MauiApp._1 +namespace MauiApp._1; + +[Register("AppDelegate")] +public class AppDelegate : MauiUIApplicationDelegate { - [Register("AppDelegate")] - public class AppDelegate : MauiUIApplicationDelegate - { - protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp(); - } -} \ No newline at end of file + protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp(); +} diff --git a/src/Templates/src/templates/maui-mobile/Platforms/MacCatalyst/Program.cs b/src/Templates/src/templates/maui-mobile/Platforms/MacCatalyst/Program.cs index c9227639e685..9d4c5c10d63b 100644 --- a/src/Templates/src/templates/maui-mobile/Platforms/MacCatalyst/Program.cs +++ b/src/Templates/src/templates/maui-mobile/Platforms/MacCatalyst/Program.cs @@ -1,15 +1,14 @@ using UIKit; -namespace MauiApp._1 +namespace MauiApp._1; + +public class Program { - public class Program + // This is the main entry point of the application. + static void Main(string[] args) { - // This is the main entry point of the application. - static void Main(string[] args) - { - // if you want to use a different Application Delegate class from "AppDelegate" - // you can specify it here. - UIApplication.Main(args, null, typeof(AppDelegate)); - } + // if you want to use a different Application Delegate class from "AppDelegate" + // you can specify it here. + UIApplication.Main(args, null, typeof(AppDelegate)); } -} \ No newline at end of file +} diff --git a/src/Templates/src/templates/maui-mobile/Platforms/Windows/App.xaml.cs b/src/Templates/src/templates/maui-mobile/Platforms/Windows/App.xaml.cs index 5e0e454ec7d3..784c92201fe2 100644 --- a/src/Templates/src/templates/maui-mobile/Platforms/Windows/App.xaml.cs +++ b/src/Templates/src/templates/maui-mobile/Platforms/Windows/App.xaml.cs @@ -1,34 +1,31 @@ -using Microsoft.Maui; -using Microsoft.Maui.Hosting; -using Microsoft.UI.Xaml; -using Windows.ApplicationModel; +using Microsoft.UI.Xaml; // To learn more about WinUI, the WinUI project structure, // and more about our project templates, see: http://aka.ms/winui-project-info. -namespace MauiApp._1.WinUI +namespace MauiApp._1.WinUI; + +/// +/// Provides application-specific behavior to supplement the default Application class. +/// +public partial class App : MauiWinUIApplication { /// - /// Provides application-specific behavior to supplement the default Application class. + /// Initializes the singleton application object. This is the first line of authored code + /// executed, and as such is the logical equivalent of main() or WinMain(). /// - public partial class App : MauiWinUIApplication + public App() { - /// - /// Initializes the singleton application object. This is the first line of authored code - /// executed, and as such is the logical equivalent of main() or WinMain(). - /// - public App() - { - this.InitializeComponent(); - } + this.InitializeComponent(); + } - protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp(); + protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp(); - protected override void OnLaunched(LaunchActivatedEventArgs args) - { - base.OnLaunched(args); + protected override void OnLaunched(LaunchActivatedEventArgs args) + { + base.OnLaunched(args); - Microsoft.Maui.Essentials.Platform.OnLaunched(args); - } + Platform.OnLaunched(args); } } + diff --git a/src/Templates/src/templates/maui-mobile/Platforms/iOS/AppDelegate.cs b/src/Templates/src/templates/maui-mobile/Platforms/iOS/AppDelegate.cs index 1c07e0e4a78f..f703ee61a345 100644 --- a/src/Templates/src/templates/maui-mobile/Platforms/iOS/AppDelegate.cs +++ b/src/Templates/src/templates/maui-mobile/Platforms/iOS/AppDelegate.cs @@ -1,12 +1,9 @@ using Foundation; -using Microsoft.Maui; -using Microsoft.Maui.Hosting; -namespace MauiApp._1 +namespace MauiApp._1; + +[Register("AppDelegate")] +public class AppDelegate : MauiUIApplicationDelegate { - [Register("AppDelegate")] - public class AppDelegate : MauiUIApplicationDelegate - { - protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp(); - } -} \ No newline at end of file + protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp(); +} diff --git a/src/Templates/src/templates/maui-mobile/Platforms/iOS/Program.cs b/src/Templates/src/templates/maui-mobile/Platforms/iOS/Program.cs index c9227639e685..9d4c5c10d63b 100644 --- a/src/Templates/src/templates/maui-mobile/Platforms/iOS/Program.cs +++ b/src/Templates/src/templates/maui-mobile/Platforms/iOS/Program.cs @@ -1,15 +1,14 @@ using UIKit; -namespace MauiApp._1 +namespace MauiApp._1; + +public class Program { - public class Program + // This is the main entry point of the application. + static void Main(string[] args) { - // This is the main entry point of the application. - static void Main(string[] args) - { - // if you want to use a different Application Delegate class from "AppDelegate" - // you can specify it here. - UIApplication.Main(args, null, typeof(AppDelegate)); - } + // if you want to use a different Application Delegate class from "AppDelegate" + // you can specify it here. + UIApplication.Main(args, null, typeof(AppDelegate)); } -} \ No newline at end of file +}