Skip to content

Commit 93a8a1b

Browse files
committed
.NET MAUI 9 HybridWebView sample app
1 parent f6b26b9 commit 93a8a1b

Some content is hidden

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

43 files changed

+1405
-4
lines changed

README.md

+6-4
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,12 @@ Made available in the `src\NET_8\` directory:
2727
- Both Xamarin.Forms and .NET MAUI from a single project - `DateCalculator.UI`
2828

2929
Made available in the `src\NET_9\` directory:
30-
* `EmbeddedWindows` - .NET MAUI Page embedded in a Native WinUI 3 App, targeting .NET 9 (`net9.0-windows10.0.19041.0`)
31-
- Refer to this [article](https://egvijayanand.in/2024/02/29/dotnet-maui-native-embedding/) for working with this sample
32-
* `MapsApp` - .NET MAUI Maps embedded in a Native WinUI 3 App, targeting .NET 9 (`net9.0-windows10.0.19041.0`)
33-
- Refer to this [article](https://egvijayanand.in/2024/03/07/dotnet-maui-community-toolkit-maps-in-winui-3-app/) for working with this sample
30+
31+
|Solution Title|Description|
32+
|:---:|:---|
33+
|`EmbeddedWindows`|.NET MAUI Page embedded in a Native WinUI 3 App, targeting .NET 9 <br /> Refer to this [article](https://egvijayanand.in/2024/02/29/dotnet-maui-native-embedding/) for working with this sample|
34+
|`MapsApp`|.NET MAUI Maps embedded in a Native WinUI 3 App, targeting .NET 9 <br /> Refer to this [article](https://egvijayanand.in/2024/03/07/dotnet-maui-community-toolkit-maps-in-winui-3-app/) for working with this sample|
35+
|`HybridWebViewApp`|A sample .NET MAUI App showcasing the features of the new [HybridWebView](https://learn.microsoft.com/en-us/dotnet/maui/whats-new/dotnet-9?view=net-maui-9.0#hybridwebview) control.|
3436

3537
Made available in the the `src\` directory:
3638

src/NET_9/HybridWebViewApp/App.xaml

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<Application
3+
x:Class="HybridWebViewApp.App"
4+
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
5+
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
6+
xmlns:d="http://schemas.microsoft.com/dotnet/2021/maui/design"
7+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
8+
xmlns:local="clr-namespace:HybridWebViewApp"
9+
mc:Ignorable="d">
10+
<Application.Resources>
11+
<ResourceDictionary>
12+
<ResourceDictionary.MergedDictionaries>
13+
<ResourceDictionary Source="Resources/Colors.xaml" />
14+
<ResourceDictionary Source="Resources/Styles.xaml" />
15+
</ResourceDictionary.MergedDictionaries>
16+
<!-- Additional Styles -->
17+
<x:Double x:Key="ItemSpacing">10</x:Double>
18+
19+
<Style ApplyToDerivedTypes="True" TargetType="StackBase">
20+
<Setter Property="Spacing"
21+
Value="{StaticResource ItemSpacing}" />
22+
</Style>
23+
24+
<Style x:Key="MauiLabel" TargetType="Label">
25+
<Setter Property="TextColor"
26+
Value="{AppThemeBinding Dark={StaticResource White}, Light={StaticResource Primary}}" />
27+
</Style>
28+
29+
<Style x:Key="Action" TargetType="Button">
30+
<Setter Property="BackgroundColor"
31+
Value="{AppThemeBinding Dark={StaticResource BackgroundDark}, Light={StaticResource BackgroundLight}}" />
32+
<Setter Property="TextColor"
33+
Value="{AppThemeBinding Dark={StaticResource TextDark}, Light={StaticResource TextLight}}" />
34+
<Setter Property="FontFamily"
35+
Value="{StaticResource AppFont}" />
36+
<Setter Property="FontSize"
37+
Value="{StaticResource AppFontSize}" />
38+
<Setter Property="Padding"
39+
Value="14,10" />
40+
</Style>
41+
42+
<Style x:Key="PrimaryAction"
43+
TargetType="Button"
44+
BasedOn="{StaticResource Action}">
45+
<Setter Property="BackgroundColor"
46+
Value="{StaticResource Primary}" />
47+
<Setter Property="FontAttributes"
48+
Value="Bold" />
49+
<Setter Property="TextColor"
50+
Value="{StaticResource White}" />
51+
</Style>
52+
</ResourceDictionary>
53+
</Application.Resources>
54+
</Application>
+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
namespace HybridWebViewApp
2+
{
3+
public partial class App : Application
4+
{
5+
public App()
6+
{
7+
InitializeComponent();
8+
UserAppTheme = PlatformAppTheme;
9+
}
10+
11+
protected override Window CreateWindow(IActivationState? activationState)
12+
=> new Window(new MainPage()) { Title = "HybridWebViewApp" };
13+
}
14+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"folders": [
3+
{
4+
"path": "."
5+
}
6+
],
7+
"settings": {},
8+
"extensions": {
9+
"recommendations": [
10+
"ms-dotnettools.csharp",
11+
"ms-dotnettools.dotnet-maui",
12+
"VisualStudioExptTeam.vscodeintellicode"
13+
]
14+
}
15+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<Project Sdk="Microsoft.NET.Sdk">
3+
<PropertyGroup>
4+
<TargetFrameworks>net9.0-android</TargetFrameworks>
5+
<TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('osx'))">$(TargetFrameworks);net9.0-ios;net9.0-maccatalyst</TargetFrameworks>
6+
<TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('windows'))">$(TargetFrameworks);net9.0-ios;net9.0-maccatalyst;net9.0-windows10.0.19041.0</TargetFrameworks>
7+
<!-- <TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('windows'))">$(TargetFrameworks);net9.0-tizen</TargetFrameworks> -->
8+
<TargetFrameworks>$(TargetFrameworks);net9.0</TargetFrameworks>
9+
<OutputType Condition="'$(TargetFramework)' != 'net9.0'">Exe</OutputType>
10+
11+
<!-- .NET MAUI -->
12+
<UseMaui>true</UseMaui>
13+
<SingleProject>true</SingleProject>
14+
15+
<!-- Project Options -->
16+
<Nullable>enable</Nullable>
17+
<LangVersion>latest</LangVersion>
18+
<ImplicitUsings>enable</ImplicitUsings>
19+
<RootNamespace>HybridWebViewApp</RootNamespace>
20+
<WindowsPackageType>None</WindowsPackageType>
21+
22+
<!-- Display name -->
23+
<ApplicationTitle>HybridWebViewApp</ApplicationTitle>
24+
25+
<!-- App Identifier -->
26+
<ApplicationId>com.companyname.hybridwebviewapp</ApplicationId>
27+
28+
<!-- Versions -->
29+
<ApplicationDisplayVersion>1.0</ApplicationDisplayVersion>
30+
<ApplicationVersion>1</ApplicationVersion>
31+
32+
<!-- Target Platform Options -->
33+
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'ios'">15.0</SupportedOSPlatformVersion>
34+
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'maccatalyst'">15.0</SupportedOSPlatformVersion>
35+
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'android'">21.0</SupportedOSPlatformVersion>
36+
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'tizen'">6.5</SupportedOSPlatformVersion>
37+
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">10.0.17763.0</SupportedOSPlatformVersion>
38+
39+
<!-- Minimum Target OS Version for Windows Platform -->
40+
<TargetPlatformMinVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">10.0.17763.0</TargetPlatformMinVersion>
41+
</PropertyGroup>
42+
43+
<ItemGroup>
44+
<!-- App Icon -->
45+
<MauiIcon Include="Resources\appicon.svg" ForegroundFile="Resources\appiconfg.svg" Color="#512BD4" />
46+
<!-- Splash Screen -->
47+
<MauiSplashScreen Include="Resources\appiconfg.svg" Color="#512BD4" BaseSize="128,128" />
48+
<!-- Images -->
49+
<MauiImage Include="Resources\Images\*" />
50+
<MauiImage Update="Resources\Images\dotnet_bot.svg" BaseSize="168,208" />
51+
<!-- Custom Fonts -->
52+
<MauiFont Include="Resources\Fonts\*" />
53+
<!-- Raw Assets (also remove the "Resources\Raw" prefix) -->
54+
<MauiAsset Include="Resources\Raw\**" LogicalName="%(RecursiveDir)%(Filename)%(Extension)" />
55+
</ItemGroup>
56+
57+
<ItemGroup>
58+
<None Remove="HybridWebViewApp.code-workspace" />
59+
<None Remove="HybridWebViewApp.slnx" />
60+
</ItemGroup>
61+
62+
<ItemGroup>
63+
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="9.*-*" Condition="'$(Configuration)' == 'Debug'" />
64+
<PackageReference Include="Microsoft.Maui.Controls" Version="$(MauiVersion)" />
65+
</ItemGroup>
66+
67+
<ItemGroup Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'ios'">
68+
<BundleResource Include="Platforms\iOS\PrivacyInfo.xcprivacy" LogicalName="PrivacyInfo.xcprivacy" />
69+
</ItemGroup>
70+
71+
<ItemGroup Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'maccatalyst'">
72+
<BundleResource Include="Platforms\MacCatalyst\PrivacyInfo.xcprivacy" LogicalName="PrivacyInfo.xcprivacy" />
73+
</ItemGroup>
74+
</Project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.0.31611.283
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{371A51A3-7E6B-415E-A4CD-ADAC03BCC115}") = "HybridWebViewApp", "HybridWebViewApp.csproj", "{A46627CB-85E6-4A7B-BAA0-A785D0B73BC1}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{A46627CB-85E6-4A7B-BAA0-A785D0B73BC1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{A46627CB-85E6-4A7B-BAA0-A785D0B73BC1}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{A46627CB-85E6-4A7B-BAA0-A785D0B73BC1}.Debug|Any CPU.Deploy.0 = Debug|Any CPU
17+
{A46627CB-85E6-4A7B-BAA0-A785D0B73BC1}.Release|Any CPU.ActiveCfg = Release|Any CPU
18+
{A46627CB-85E6-4A7B-BAA0-A785D0B73BC1}.Release|Any CPU.Build.0 = Release|Any CPU
19+
{A46627CB-85E6-4A7B-BAA0-A785D0B73BC1}.Release|Any CPU.Deploy.0 = Release|Any CPU
20+
EndGlobalSection
21+
GlobalSection(SolutionProperties) = preSolution
22+
HideSolutionNode = FALSE
23+
EndGlobalSection
24+
GlobalSection(ExtensibilityGlobals) = postSolution
25+
SolutionGuid = {5C1129A5-874B-4811-96D2-0ADA1CB519F8}
26+
EndGlobalSection
27+
EndGlobal
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<Solution>
2+
<Project Path="HybridWebViewApp.csproj">
3+
<Deploy />
4+
</Project>
5+
<Properties Name="Visual Studio">
6+
<!-- Support is provisionally available on Visual Studio 17.10 and later versions. -->
7+
<Property Name="OpenWith" Value="17" />
8+
</Properties>
9+
</Solution>

src/NET_9/HybridWebViewApp/Imports.cs

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
global using HybridWebViewApp;
2+
global using HybridWebViewApp.Views;
3+
4+
// Static
5+
global using static Microsoft.Maui.Graphics.Colors;
+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using Microsoft.Extensions.Logging;
2+
3+
namespace HybridWebViewApp
4+
{
5+
public static partial class MauiProgram
6+
{
7+
public static MauiApp CreateMauiApp()
8+
{
9+
var builder = MauiApp.CreateBuilder();
10+
builder.UseMauiApp<App>()
11+
.ConfigureFonts(fonts =>
12+
{
13+
fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
14+
fonts.AddFont("OpenSans-SemiBold.ttf", "OpenSansSemiBold");
15+
});
16+
17+
#if DEBUG
18+
builder.Logging.AddDebug();
19+
#endif
20+
21+
return builder.Build();
22+
}
23+
}
24+
}
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+
<uses-sdk android:minSdkVersion="21" android:targetSdkVersion="35" />
4+
<application android:allowBackup="true" android:icon="@mipmap/appicon" android:roundIcon="@mipmap/appicon_round" android:supportsRtl="true"></application>
5+
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
6+
</manifest>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using Android.App;
2+
using Android.Content.PM;
3+
using Android.OS;
4+
5+
namespace HybridWebViewApp
6+
{
7+
[Activity(Theme = "@style/Maui.SplashTheme", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation | ConfigChanges.UiMode | ConfigChanges.ScreenLayout | ConfigChanges.SmallestScreenSize)]
8+
public class MainActivity : MauiAppCompatActivity
9+
{
10+
11+
}
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using Android.App;
2+
using Android.Runtime;
3+
4+
namespace HybridWebViewApp
5+
{
6+
[Application]
7+
public class MainApplication : MauiApplication
8+
{
9+
public MainApplication(IntPtr handle, JniHandleOwnership ownership)
10+
: base(handle, ownership)
11+
{
12+
}
13+
14+
protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp();
15+
}
16+
}
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,10 @@
1+
using Foundation;
2+
3+
namespace HybridWebViewApp
4+
{
5+
[Register(nameof(AppDelegate))]
6+
public class AppDelegate : MauiUIApplicationDelegate
7+
{
8+
protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp();
9+
}
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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+
<key>UIDeviceFamily</key>
6+
<array>
7+
<integer>1</integer>
8+
<integer>2</integer>
9+
</array>
10+
<key>UIRequiredDeviceCapabilities</key>
11+
<array>
12+
<string>arm64</string>
13+
</array>
14+
<key>UISupportedInterfaceOrientations</key>
15+
<array>
16+
<string>UIInterfaceOrientationPortrait</string>
17+
<string>UIInterfaceOrientationLandscapeLeft</string>
18+
<string>UIInterfaceOrientationLandscapeRight</string>
19+
</array>
20+
<key>UISupportedInterfaceOrientations~ipad</key>
21+
<array>
22+
<string>UIInterfaceOrientationPortrait</string>
23+
<string>UIInterfaceOrientationPortraitUpsideDown</string>
24+
<string>UIInterfaceOrientationLandscapeLeft</string>
25+
<string>UIInterfaceOrientationLandscapeRight</string>
26+
</array>
27+
<key>XSAppIconAssets</key>
28+
<string>Assets.xcassets/appicon.appiconset</string>
29+
</dict>
30+
</plist>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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+
<key>NSPrivacyAccessedAPITypes</key>
6+
<array>
7+
<dict>
8+
<key>NSPrivacyAccessedAPIType</key>
9+
<string>NSPrivacyAccessedAPICategoryFileTimestamp</string>
10+
<key>NSPrivacyAccessedAPITypeReasons</key>
11+
<array>
12+
<string>C617.1</string>
13+
</array>
14+
</dict>
15+
<dict>
16+
<key>NSPrivacyAccessedAPIType</key>
17+
<string>NSPrivacyAccessedAPICategorySystemBootTime</string>
18+
<key>NSPrivacyAccessedAPITypeReasons</key>
19+
<array>
20+
<string>35F9.1</string>
21+
</array>
22+
</dict>
23+
<dict>
24+
<key>NSPrivacyAccessedAPIType</key>
25+
<string>NSPrivacyAccessedAPICategoryDiskSpace</string>
26+
<key>NSPrivacyAccessedAPITypeReasons</key>
27+
<array>
28+
<string>E174.1</string>
29+
</array>
30+
</dict>
31+
<!--
32+
The entry below is only needed when you're using the Preferences API in your app.
33+
<dict>
34+
<key>NSPrivacyAccessedAPIType</key>
35+
<string>NSPrivacyAccessedAPICategoryUserDefaults</string>
36+
<key>NSPrivacyAccessedAPITypeReasons</key>
37+
<array>
38+
<string>CA92.1</string>
39+
</array>
40+
</dict> -->
41+
</array>
42+
</dict>
43+
</plist>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using ObjCRuntime;
2+
using UIKit;
3+
4+
namespace HybridWebViewApp
5+
{
6+
public class Program
7+
{
8+
// This is the main entry point of the application.
9+
static void Main(string[] args)
10+
{
11+
// if you want to use a different Application Delegate class from "AppDelegate"
12+
// you can specify it here.
13+
UIApplication.Main(args, null, typeof(AppDelegate));
14+
}
15+
}
16+
}

0 commit comments

Comments
 (0)