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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 5 additions & 0 deletions
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

Lines changed: 14 additions & 0 deletions
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

Lines changed: 16 additions & 0 deletions
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

Lines changed: 13 additions & 0 deletions
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

Lines changed: 11 additions & 0 deletions
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

Lines changed: 36 additions & 0 deletions
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

Lines changed: 20 additions & 0 deletions
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

Lines changed: 33 additions & 0 deletions
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+
}

0 commit comments

Comments
 (0)