Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.8.0.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Material3HandlerCustomization", "Material3HandlerCustomization\Material3HandlerCustomization.csproj", "{EA372BBF-C9CD-48B4-B86F-81C9E45D74E3}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{EA372BBF-C9CD-48B4-B86F-81C9E45D74E3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{EA372BBF-C9CD-48B4-B86F-81C9E45D74E3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{EA372BBF-C9CD-48B4-B86F-81C9E45D74E3}.Debug|Any CPU.Deploy.0 = Debug|Any CPU
{EA372BBF-C9CD-48B4-B86F-81C9E45D74E3}.Release|Any CPU.ActiveCfg = Release|Any CPU
{EA372BBF-C9CD-48B4-B86F-81C9E45D74E3}.Release|Any CPU.Build.0 = Release|Any CPU
{EA372BBF-C9CD-48B4-B86F-81C9E45D74E3}.Release|Any CPU.Deploy.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {2E2E5E48-7898-438F-8886-C7773FD2DE51}
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8" ?>
<Application xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:Material3HandlerCustomization"
x:Class="Material3HandlerCustomization.App">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Resources/Styles/Colors.xaml" />
<ResourceDictionary Source="Resources/Styles/Styles.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
</Application>
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
namespace Material3HandlerCustomization;

public partial class App : Application
{
public App()
{
InitializeComponent();
}

protected override Window CreateWindow(IActivationState? activationState)
{
return new Window(new MainPage())
{
Title = "Material 3 Handler Customization - .NET MAUI 11"
};
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
global using Microsoft.Maui.Controls;
global using Microsoft.Maui.Controls.Xaml;
global using Microsoft.Maui.Controls.Shapes;
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?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="Material3HandlerCustomization.MainPage"
Title="Material 3 customization"
BackgroundColor="#F0F2F5">

<ScrollView>
<VerticalStackLayout Padding="20,40" Spacing="20">

<Label Text="Material 3 handler customization"
FontSize="26"
FontAttributes="Bold"
TextColor="#512BD4" />

<Label Text="The Android Material 3 platform views and helper types are public in .NET MAUI 11, so an app can subclass them and wire the result up via the handler's PlatformViewFactory."
FontSize="14"
TextColor="#666666" />

<Label Text="Editor (custom MauiMaterialEditText on Android)"
FontSize="16"
FontAttributes="Bold"
TextColor="#333333"
Margin="0,10,0,0" />

<Border StrokeShape="RoundRectangle 12"
StrokeThickness="0"
BackgroundColor="White"
Padding="12">
<Editor Placeholder="Type something here..."
HeightRequest="120"
TextColor="#512BD4"
AutoSize="TextChanges" />
</Border>

<Label Text="On Android, this Editor renders through a custom MauiMaterialEditText subclass that capitalises every keystroke and changes the cursor color. On other platforms it uses the default Editor handler."
FontSize="13"
TextColor="#888888" />

</VerticalStackLayout>
</ScrollView>

</ContentPage>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace Material3HandlerCustomization;

public partial class MainPage : ContentPage
{
public MainPage()
{
InitializeComponent();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net11.0-android;net11.0-ios;net11.0-maccatalyst</TargetFrameworks>
<TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('windows'))">$(TargetFrameworks);net11.0-windows10.0.19041.0</TargetFrameworks>

<OutputType>Exe</OutputType>
<RootNamespace>Material3HandlerCustomization</RootNamespace>
<UseMaui>true</UseMaui>
<SingleProject>true</SingleProject>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>

<MauiEnableXamlCBindingWithSourceCompilation>true</MauiEnableXamlCBindingWithSourceCompilation>

<!-- Opt in to Material 3 on Android. Activates LabelHandler2, EditorHandler2, PickerHandler2, RadioButtonHandler2, TimePickerHandler2. -->
<UseMaterial3>true</UseMaterial3>

<!-- Display name -->
<ApplicationTitle>Material3HandlerCustomization</ApplicationTitle>

<!-- App Identifier -->
<ApplicationId>com.companyname.material3handlercustomization</ApplicationId>

<!-- Versions -->
<ApplicationDisplayVersion>1.0</ApplicationDisplayVersion>
<ApplicationVersion>1</ApplicationVersion>

<WindowsPackageType>None</WindowsPackageType>

<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'ios'">15.0</SupportedOSPlatformVersion>
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'maccatalyst'">17.0</SupportedOSPlatformVersion>
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'android'">24.0</SupportedOSPlatformVersion>
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">10.0.17763.0</SupportedOSPlatformVersion>
<TargetPlatformMinVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">10.0.17763.0</TargetPlatformMinVersion>
</PropertyGroup>

<ItemGroup>
<!-- App Icon -->
<MauiIcon Include="Resources\AppIcon\appicon.svg" ForegroundFile="Resources\AppIcon\appiconfg.svg" Color="#512BD4" />

<!-- Splash Screen -->
<MauiSplashScreen Include="Resources\Splash\splash.svg" Color="#512BD4" BaseSize="128,128" />

<!-- Images -->
<MauiImage Include="Resources\Images\*" />
<MauiImage Update="Resources\Images\dotnet_bot.png" Resize="True" BaseSize="300,185" />

<!-- Custom Fonts -->
<MauiFont Include="Resources\Fonts\*" />

<!-- Raw Assets (also remove the "Resources\Raw" prefix) -->
<MauiAsset Include="Resources\Raw\**" LogicalName="%(RecursiveDir)%(Filename)%(Extension)" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Maui.Controls" Version="$(MauiVersion)" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="$(DotNetVersion)" />
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.4.0" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using Microsoft.Extensions.Logging;

namespace Material3HandlerCustomization;

public static class MauiProgram
{
public static MauiApp CreateMauiApp()
{
var builder = MauiApp.CreateBuilder();
builder
.UseMauiApp<App>()
.ConfigureFonts(fonts =>
{
fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold");
});

#if ANDROID
// Wire a custom MauiMaterialEditText subclass into EditorHandler2.
MaterialEditorSetup.RegisterCustomEditor();
#endif

#if DEBUG
builder.Logging.AddDebug();
#endif

return builder.Build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<application android:allowBackup="true" android:icon="@mipmap/appicon" android:roundIcon="@mipmap/appicon_round" android:supportsRtl="true"></application>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using Android.App;
using Android.Content.PM;
using Android.OS;

namespace Material3HandlerCustomization
{
[Activity(Theme = "@style/Maui.SplashTheme", MainLauncher = true, LaunchMode = LaunchMode.SingleTop, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation | ConfigChanges.UiMode | ConfigChanges.ScreenLayout | ConfigChanges.SmallestScreenSize | ConfigChanges.Density)]
public class MainActivity : MauiAppCompatActivity
{
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using Android.App;
using Android.Runtime;

namespace Material3HandlerCustomization
{
[Application]
public class MainApplication : MauiApplication
{
public MainApplication(IntPtr handle, JniHandleOwnership ownership)
: base(handle, ownership)
{
}

protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#if ANDROID
using Android.Views;
using Android.Views.InputMethods;
using Microsoft.Maui.Handlers;
using Microsoft.Maui.Platform;

namespace Material3HandlerCustomization;

internal static class MaterialEditorSetup
{
// <docregion_platformviewfactory>
public static void RegisterCustomEditor()
{
EditorHandler2.PlatformViewFactory = handler =>
{
var context = MauiMaterialContextThemeWrapper.Create(handler.Context!);
var editText = new MyMaterialEditText(context)
{
ImeOptions = ImeAction.Done,
Gravity = GravityFlags.Top,
TextAlignment = global::Android.Views.TextAlignment.ViewStart,
};
editText.SetSingleLine(false);
editText.SetHorizontallyScrolling(false);
return editText;
};
}
// </docregion_platformviewfactory>
}
#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#if ANDROID
using Android.Content;
using Android.Text;
using Android.Util;
using Java.Lang;
using Microsoft.Maui.Platform;

namespace Material3HandlerCustomization;

// <docregion_custom_edittext>
public class MyMaterialEditText : MauiMaterialEditText

Check failure on line 11 in 11.0/UserInterface/Material3/Material3HandlerCustomization/Material3HandlerCustomization/Platforms/Android/MyMaterialEditText.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest)

'MauiMaterialEditText' is inaccessible due to its protection level

Check failure on line 11 in 11.0/UserInterface/Material3/Material3HandlerCustomization/Material3HandlerCustomization/Platforms/Android/MyMaterialEditText.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest)

'MauiMaterialEditText' is inaccessible due to its protection level

Check failure on line 11 in 11.0/UserInterface/Material3/Material3HandlerCustomization/Material3HandlerCustomization/Platforms/Android/MyMaterialEditText.cs

View workflow job for this annotation

GitHub Actions / build (macos-26)

'MauiMaterialEditText' is inaccessible due to its protection level

Check failure on line 11 in 11.0/UserInterface/Material3/Material3HandlerCustomization/Material3HandlerCustomization/Platforms/Android/MyMaterialEditText.cs

View workflow job for this annotation

GitHub Actions / build (macos-26)

'MauiMaterialEditText' is inaccessible due to its protection level
{
public MyMaterialEditText(Context context) : base(context)
{
}

public MyMaterialEditText(Context context, IAttributeSet? attrs) : base(context, attrs)
{
}

protected override void OnTextChanged(ICharSequence? text, int start, int lengthBefore, int lengthAfter)
{
base.OnTextChanged(text, start, lengthBefore, lengthAfter);

// Force the displayed text to upper case as the user types.
var current = text?.ToString() ?? string.Empty;
var upper = current.ToUpperInvariant();
if (current != upper)
{
var cursor = SelectionStart;
SetText(upper, TextView.BufferType.Editable);
SetSelection(System.Math.Min(cursor, upper.Length));
}
}
}
// </docregion_custom_edittext>
#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorPrimary">#512BD4</color>
<color name="colorPrimaryDark">#2B0B98</color>
<color name="colorAccent">#2B0B98</color>
</resources>
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using Foundation;

namespace Material3HandlerCustomization
{
[Register("AppDelegate")]
public class AppDelegate : MauiUIApplicationDelegate
{
protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>com.apple.security.app-sandbox</key>
<true/>
<key>com.apple.security.network.client</key>
<true/>
</dict>
</plist>
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>UIDeviceFamily</key>
<array>
<integer>2</integer>
</array>
<key>UIRequiredDeviceCapabilities</key>
<array>
<string>arm64</string>
</array>
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>UISupportedInterfaceOrientations~ipad</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationPortraitUpsideDown</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>XSAppIconAssets</key>
<string>Assets.xcassets/appicon.appiconset</string>
</dict>
</plist>
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using ObjCRuntime;
using UIKit;

namespace Material3HandlerCustomization
{
public class Program
{
static void Main(string[] args)
{
UIApplication.Main(args, null, typeof(AppDelegate));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<maui:MauiWinUIApplication
x:Class="Material3HandlerCustomization.WinUI.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:maui="using:Microsoft.Maui"
xmlns:local="using:Material3HandlerCustomization.WinUI">

</maui:MauiWinUIApplication>
Loading
Loading