Skip to content

Commit 76eb4b3

Browse files
authored
#239 added MAUI example (#241)
1 parent 088edbb commit 76eb4b3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+9044
-2
lines changed

examples/Directory.Build.props

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
<Optimize>true</Optimize>
2727
</PropertyGroup>
2828
<PropertyGroup>
29-
<Log4NetPackageVersion>3.0.3</Log4NetPackageVersion>
29+
<Log4NetPackageVersion>*</Log4NetPackageVersion>
3030
<MicrosoftNetAnalyzersPackageVersion>8.0.0</MicrosoftNetAnalyzersPackageVersion>
3131
</PropertyGroup>
3232
<PropertyGroup Label="GenerateAssemblyInfo">

examples/Layouts/SampleLayoutsApp/Layout/ForwardingLayout.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public virtual void ActivateOptions()
8484
/// the <paramref name="loggingEvent"/> as text.
8585
/// </para>
8686
/// </remarks>
87-
virtual public void Format(TextWriter writer, LoggingEvent loggingEvent)
87+
public virtual void Format(TextWriter writer, LoggingEvent loggingEvent)
8888
=> Layout?.Format(writer, loggingEvent);
8989

9090
/// <summary>

examples/Maui/.editorconfig

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[*.cs]
2+
# Naming styles
3+
dotnet_style_namespace_match_folder = false:suggestion
4+
# IDE1006: Naming Styles
5+
dotnet_diagnostic.IDE1006.severity = none

examples/Maui/App.xaml

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version = "1.0" encoding = "UTF-8" ?>
2+
<Application xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
4+
xmlns:local="clr-namespace:MauiTestApplication"
5+
x:Class="MauiTestApplication.App">
6+
<Application.Resources>
7+
<ResourceDictionary>
8+
<ResourceDictionary.MergedDictionaries>
9+
<ResourceDictionary Source="Resources/Styles/Colors.xaml" />
10+
<ResourceDictionary Source="Resources/Styles/Styles.xaml" />
11+
</ResourceDictionary.MergedDictionaries>
12+
</ResourceDictionary>
13+
</Application.Resources>
14+
</Application>

examples/Maui/App.xaml.cs

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using System.Diagnostics.CodeAnalysis;
2+
3+
namespace MauiTestApplication;
4+
5+
/// <inheritdoc/>
6+
[SuppressMessage("Naming", "CA1724:Type names should not match namespaces")]
7+
[SuppressMessage("Microsoft.Maintainability", "CA1501:AvoidExcessiveInheritance")]
8+
public partial class App : Application
9+
{
10+
/// <inheritdoc/>
11+
public App() => InitializeComponent();
12+
13+
/// <inheritdoc/>
14+
protected override Window CreateWindow(IActivationState? activationState)
15+
=> new(new AppShell());
16+
}

examples/Maui/AppShell.xaml

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<Shell
3+
x:Class="MauiTestApplication.AppShell"
4+
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
5+
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
6+
xmlns:local="clr-namespace:MauiTestApplication"
7+
Shell.FlyoutBehavior="Flyout"
8+
Title="MauiTestApplication">
9+
<ShellContent
10+
Title="Home"
11+
ContentTemplate="{DataTemplate local:MainPage}"
12+
Route="MainPage" />
13+
</Shell>

examples/Maui/AppShell.xaml.cs

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using System.Diagnostics.CodeAnalysis;
2+
3+
namespace MauiTestApplication;
4+
5+
/// <inheritdoc/>
6+
[SuppressMessage("Microsoft.Maintainability", "CA1501:AvoidExcessiveInheritance")]
7+
public partial class AppShell : Shell
8+
{
9+
/// <inheritdoc/>
10+
public AppShell() => InitializeComponent();
11+
}

examples/Maui/MainPage.xaml

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
4+
x:Class="MauiTestApplication.MainPage">
5+
6+
<ScrollView>
7+
<VerticalStackLayout
8+
Padding="30,0"
9+
Spacing="25">
10+
<Image
11+
Source="dotnet_bot.png"
12+
HeightRequest="185"
13+
Aspect="AspectFit"
14+
SemanticProperties.Description="dot net bot in a hovercraft number nine" />
15+
16+
<Label
17+
Text="Hello, World!"
18+
Style="{StaticResource Headline}"
19+
SemanticProperties.HeadingLevel="Level1" />
20+
21+
<Label
22+
Text="Welcome to &#10;.NET Multi-platform App UI"
23+
Style="{StaticResource SubHeadline}"
24+
SemanticProperties.HeadingLevel="Level2"
25+
SemanticProperties.Description="Welcome to dot net Multi platform App U I" />
26+
27+
<Button
28+
x:Name="CounterBtn"
29+
Text="Click me"
30+
SemanticProperties.Hint="Counts the number of times you click"
31+
Clicked="OnCounterClicked"
32+
HorizontalOptions="Fill" />
33+
</VerticalStackLayout>
34+
</ScrollView>
35+
36+
</ContentPage>

examples/Maui/MainPage.xaml.cs

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using System.Diagnostics.CodeAnalysis;
2+
3+
namespace MauiTestApplication;
4+
5+
/// <inheritdoc/>
6+
[SuppressMessage("Microsoft.Maintainability", "CA1501:AvoidExcessiveInheritance")]
7+
public partial class MainPage : ContentPage
8+
{
9+
private int _count;
10+
11+
/// <inheritdoc/>
12+
public MainPage() => InitializeComponent();
13+
14+
private void OnCounterClicked(object sender, EventArgs e)
15+
{
16+
_count++;
17+
CounterBtn.Text = $"Clicked {_count} time{(_count > 1 ? 's' : ' ')}";
18+
SemanticScreenReader.Announce(CounterBtn.Text);
19+
}
20+
}

examples/Maui/MauiProgram.cs

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
using log4net;
2+
using log4net.Config;
3+
using Microsoft.Extensions.Logging;
4+
5+
namespace MauiTestApplication;
6+
7+
/// <inheritdoc/>
8+
public static class MauiProgram
9+
{
10+
/// <inheritdoc/>
11+
public static MauiApp CreateMauiApp()
12+
{
13+
using Stream stream = typeof(MauiProgram).Assembly.GetManifestResourceStream(nameof(MauiTestApplication) + ".log4net.xml")
14+
?? throw new InvalidOperationException();
15+
ILog log = LogManager.GetLogger(typeof(MauiProgram));
16+
XmlConfigurator.Configure(stream);
17+
log.Info("Entering application.");
18+
MauiAppBuilder builder = MauiApp.CreateBuilder();
19+
builder
20+
.UseMauiApp<App>()
21+
.ConfigureFonts(fonts =>
22+
{
23+
fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
24+
fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold");
25+
});
26+
27+
#if DEBUG
28+
builder.Logging.AddDebug();
29+
#endif
30+
31+
return builder.Build();
32+
}
33+
}
+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFrameworks>net9.0-android;net9.0-ios;net9.0-maccatalyst</TargetFrameworks>
5+
<TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('windows'))">$(TargetFrameworks);net9.0-windows10.0.19041.0</TargetFrameworks>
6+
<!-- Uncomment to also build the tizen app. You will need to install tizen by following this: https://github.com/Samsung/Tizen.NET -->
7+
<!-- <TargetFrameworks>$(TargetFrameworks);net9.0-tizen</TargetFrameworks> -->
8+
9+
<!-- Note for MacCatalyst:
10+
The default runtime is maccatalyst-x64, except in Release config, in which case the default is maccatalyst-x64;maccatalyst-arm64.
11+
When specifying both architectures, use the plural <RuntimeIdentifiers> instead of the singular <RuntimeIdentifier>.
12+
The Mac App Store will NOT accept apps with ONLY maccatalyst-arm64 indicated;
13+
either BOTH runtimes must be indicated or ONLY macatalyst-x64. -->
14+
<!-- For example: <RuntimeIdentifiers>maccatalyst-x64;maccatalyst-arm64</RuntimeIdentifiers> -->
15+
16+
<OutputType>Exe</OutputType>
17+
<RootNamespace>MauiTestApplication</RootNamespace>
18+
<UseMaui>true</UseMaui>
19+
<SingleProject>true</SingleProject>
20+
<ImplicitUsings>enable</ImplicitUsings>
21+
<NoWarn>$(NoWarn);CS1591</NoWarn>
22+
<DefaultLanguage>en-us</DefaultLanguage>
23+
24+
<!-- Display name -->
25+
<ApplicationTitle>MauiTestApplication</ApplicationTitle>
26+
27+
<!-- App Identifier -->
28+
<ApplicationId>org.apache.logging.mauiapp</ApplicationId>
29+
30+
<!-- Versions -->
31+
<ApplicationDisplayVersion>1.0</ApplicationDisplayVersion>
32+
<ApplicationVersion>1</ApplicationVersion>
33+
34+
<!-- To develop, package, and publish an app to the Microsoft Store, see: https://aka.ms/MauiTemplateUnpackaged -->
35+
<WindowsPackageType>None</WindowsPackageType>
36+
37+
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'ios'">15.0</SupportedOSPlatformVersion>
38+
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'maccatalyst'">15.0</SupportedOSPlatformVersion>
39+
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'android'">21.0</SupportedOSPlatformVersion>
40+
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">10.0.17763.0</SupportedOSPlatformVersion>
41+
<TargetPlatformMinVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">10.0.17763.0</TargetPlatformMinVersion>
42+
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'tizen'">6.5</SupportedOSPlatformVersion>
43+
</PropertyGroup>
44+
45+
<ItemGroup>
46+
<!-- App Icon -->
47+
<MauiIcon Include="Resources\AppIcon\appicon.svg" ForegroundFile="Resources\AppIcon\appiconfg.svg" Color="#512BD4" />
48+
49+
<!-- Splash Screen -->
50+
<MauiSplashScreen Include="Resources\Splash\splash.svg" Color="#512BD4" BaseSize="128,128" />
51+
52+
<!-- Images -->
53+
<MauiImage Include="Resources\Images\*" />
54+
<MauiImage Update="Resources\Images\dotnet_bot.png" Resize="True" BaseSize="300,185" />
55+
56+
<!-- Custom Fonts -->
57+
<MauiFont Include="Resources\Fonts\*" />
58+
59+
<!-- Raw Assets (also remove the "Resources\Raw" prefix) -->
60+
<MauiAsset Include="Resources\Raw\**" LogicalName="%(RecursiveDir)%(Filename)%(Extension)" />
61+
</ItemGroup>
62+
63+
<ItemGroup>
64+
<PackageReference Include="log4net" Version="$(Log4NetPackageVersion)" />
65+
<PackageReference Include="Microsoft.Maui.Controls" Version="$(MauiVersion)" />
66+
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="9.0.0" />
67+
</ItemGroup>
68+
69+
<ItemGroup>
70+
<EmbeddedResource Include="log4net.xml" />
71+
</ItemGroup>
72+
</Project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
3+
<application android:allowBackup="true" android:icon="@mipmap/appicon" android:roundIcon="@mipmap/appicon_round" android:supportsRtl="true"></application>
4+
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
5+
<uses-permission android:name="android.permission.INTERNET" />
6+
</manifest>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using System.Diagnostics.CodeAnalysis;
2+
using Android.App;
3+
using Android.Content.PM;
4+
5+
namespace MauiTestApplication;
6+
7+
/// <inheritdoc/>
8+
[SuppressMessage("Microsoft.Maintainability", "CA1501:AvoidExcessiveInheritance")]
9+
[Activity(Theme = "@style/Maui.SplashTheme", MainLauncher = true, LaunchMode = LaunchMode.SingleTop, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation | ConfigChanges.UiMode | ConfigChanges.ScreenLayout | ConfigChanges.SmallestScreenSize | ConfigChanges.Density)]
10+
public class MainActivity : MauiAppCompatActivity
11+
{ }
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using Android.App;
2+
using Android.Runtime;
3+
4+
namespace MauiTestApplication;
5+
6+
/// <inheritdoc/>
7+
[Application]
8+
public class MainApplication(IntPtr handle, JniHandleOwnership ownership)
9+
: MauiApplication(handle, ownership)
10+
{
11+
/// <inheritdoc/>
12+
protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp();
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<resources>
3+
<color name="colorPrimary">#512BD4</color>
4+
<color name="colorPrimaryDark">#2B0B98</color>
5+
<color name="colorAccent">#2B0B98</color>
6+
</resources>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using Foundation;
2+
3+
namespace MauiTestApplication;
4+
5+
/// <inheritdoc/>
6+
[Register("AppDelegate")]
7+
[System.Diagnostics.CodeAnalysis.SuppressMessage("Naming", "CA1711:Identifiers should not have incorrect suffix")]
8+
public class AppDelegate : MauiUIApplicationDelegate
9+
{
10+
/// <inheritdoc/>
11+
protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp();
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<!-- See https://aka.ms/maui-publish-app-store#add-entitlements for more information about adding entitlements.-->
5+
<dict>
6+
<!-- App Sandbox must be enabled to distribute a MacCatalyst app through the Mac App Store. -->
7+
<key>com.apple.security.app-sandbox</key>
8+
<true/>
9+
<!-- When App Sandbox is enabled, this value is required to open outgoing network connections. -->
10+
<key>com.apple.security.network.client</key>
11+
<true/>
12+
</dict>
13+
</plist>
14+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<!-- The Mac App Store requires you specify if the app uses encryption. -->
6+
<!-- Please consult https://developer.apple.com/documentation/bundleresources/information_property_list/itsappusesnonexemptencryption -->
7+
<!-- <key>ITSAppUsesNonExemptEncryption</key> -->
8+
<!-- Please indicate <true/> or <false/> here. -->
9+
10+
<!-- Specify the category for your app here. -->
11+
<!-- Please consult https://developer.apple.com/documentation/bundleresources/information_property_list/lsapplicationcategorytype -->
12+
<!-- <key>LSApplicationCategoryType</key> -->
13+
<!-- <string>public.app-category.YOUR-CATEGORY-HERE</string> -->
14+
<key>UIDeviceFamily</key>
15+
<array>
16+
<integer>2</integer>
17+
</array>
18+
<key>UIRequiredDeviceCapabilities</key>
19+
<array>
20+
<string>arm64</string>
21+
</array>
22+
<key>UISupportedInterfaceOrientations</key>
23+
<array>
24+
<string>UIInterfaceOrientationPortrait</string>
25+
<string>UIInterfaceOrientationLandscapeLeft</string>
26+
<string>UIInterfaceOrientationLandscapeRight</string>
27+
</array>
28+
<key>UISupportedInterfaceOrientations~ipad</key>
29+
<array>
30+
<string>UIInterfaceOrientationPortrait</string>
31+
<string>UIInterfaceOrientationPortraitUpsideDown</string>
32+
<string>UIInterfaceOrientationLandscapeLeft</string>
33+
<string>UIInterfaceOrientationLandscapeRight</string>
34+
</array>
35+
<key>XSAppIconAssets</key>
36+
<string>Assets.xcassets/appicon.appiconset</string>
37+
</dict>
38+
</plist>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using UIKit;
2+
3+
namespace MauiTestApplication;
4+
5+
/// <inheritdoc/>
6+
public class Program
7+
{
8+
// This is the main entry point of the application.
9+
private static void Main(string[] args)
10+
// if you want to use a different Application Delegate class from "AppDelegate"
11+
// you can specify it here.
12+
=> UIApplication.Main(args, null, typeof(AppDelegate));
13+
}

examples/Maui/Platforms/Tizen/Main.cs

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using System;
2+
using Microsoft.Maui;
3+
using Microsoft.Maui.Hosting;
4+
5+
namespace MauiApp;
6+
7+
/// <inheritdoc/>
8+
internal static class Program : MauiApplication
9+
{
10+
/// <inheritdoc/>
11+
protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp();
12+
13+
private static void Main(string[] args) => new Program().Run(args);
14+
}

0 commit comments

Comments
 (0)