diff --git a/README.md b/README.md index 7c96065..3a2ddc1 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,11 @@ Completed samples will be uploaded into this repository so that it is accessible Join me on [**Developer Thoughts**](https://egvijayanand.in/), an exclusive blog for .NET MAUI and Blazor, for articles on working with these samples. -_Note: Samples are in the process of migrating to the latest framework version, so there would be a change in the directory structure, so kindly bear with this._ +_Note: Samples are in the process of migrating to the latest framework version, so there would be a change in the directory structure. Kindly bear with this._ + +Made available in the `src\NET_8\` directory: +* `EmbeddedWindows` - .NET MAUI Page embedded in a Native WinUI 3 App, targeting .NET 8 (`net8.0-windows10.0.19041.0`) + - Refer to this [article](https://egvijayanand.in/2024/02/29/dotnet-maui-native-embedding/) for working with this sample Made available in the `src\NET_9\` directory: * `EmbeddedWindows` - .NET MAUI Page embedded in a Native WinUI 3 App, targeting .NET 9 (`net9.0-windows10.0.19041.0`) diff --git a/src/NET_8/EmbeddedWindows/Directory.Packages.props b/src/NET_8/EmbeddedWindows/Directory.Packages.props new file mode 100644 index 0000000..0af39e6 --- /dev/null +++ b/src/NET_8/EmbeddedWindows/Directory.Packages.props @@ -0,0 +1,5 @@ + + + 8.0.7 + + diff --git a/src/NET_8/EmbeddedWindows/EmbeddedWindows.sln b/src/NET_8/EmbeddedWindows/EmbeddedWindows.sln new file mode 100644 index 0000000..cc6844d --- /dev/null +++ b/src/NET_8/EmbeddedWindows/EmbeddedWindows.sln @@ -0,0 +1,51 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.5.33103.201 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EmbeddedWindows", "EmbeddedWindows\EmbeddedWindows.csproj", "{A96B3752-FF0F-402B-A85A-634E934202F1}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MauiLib", "MauiLib\MauiLib.csproj", "{E93EB175-0FD3-4BFD-B81A-CDAF33998932}" +EndProject +Global + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {33E05B3D-B1D3-476F-9E8D-E1E471B55750} + EndGlobalSection + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Debug|x64 = Debug|x64 + Debug|x86 = Debug|x86 + Release|Any CPU = Release|Any CPU + Release|x64 = Release|x64 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {A96B3752-FF0F-402B-A85A-634E934202F1}.Debug|Any CPU.ActiveCfg = Debug|x86 + {A96B3752-FF0F-402B-A85A-634E934202F1}.Debug|Any CPU.Build.0 = Debug|x86 + {A96B3752-FF0F-402B-A85A-634E934202F1}.Debug|x64.ActiveCfg = Debug|x64 + {A96B3752-FF0F-402B-A85A-634E934202F1}.Debug|x64.Build.0 = Debug|x64 + {A96B3752-FF0F-402B-A85A-634E934202F1}.Debug|x86.ActiveCfg = Debug|x86 + {A96B3752-FF0F-402B-A85A-634E934202F1}.Debug|x86.Build.0 = Debug|x86 + {A96B3752-FF0F-402B-A85A-634E934202F1}.Release|Any CPU.ActiveCfg = Release|x86 + {A96B3752-FF0F-402B-A85A-634E934202F1}.Release|Any CPU.Build.0 = Release|x86 + {A96B3752-FF0F-402B-A85A-634E934202F1}.Release|x64.ActiveCfg = Release|x64 + {A96B3752-FF0F-402B-A85A-634E934202F1}.Release|x64.Build.0 = Release|x64 + {A96B3752-FF0F-402B-A85A-634E934202F1}.Release|x86.ActiveCfg = Release|x86 + {A96B3752-FF0F-402B-A85A-634E934202F1}.Release|x86.Build.0 = Release|x86 + {E93EB175-0FD3-4BFD-B81A-CDAF33998932}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {E93EB175-0FD3-4BFD-B81A-CDAF33998932}.Debug|Any CPU.Build.0 = Debug|Any CPU + {E93EB175-0FD3-4BFD-B81A-CDAF33998932}.Debug|x64.ActiveCfg = Debug|Any CPU + {E93EB175-0FD3-4BFD-B81A-CDAF33998932}.Debug|x64.Build.0 = Debug|Any CPU + {E93EB175-0FD3-4BFD-B81A-CDAF33998932}.Debug|x86.ActiveCfg = Debug|Any CPU + {E93EB175-0FD3-4BFD-B81A-CDAF33998932}.Debug|x86.Build.0 = Debug|Any CPU + {E93EB175-0FD3-4BFD-B81A-CDAF33998932}.Release|Any CPU.ActiveCfg = Release|Any CPU + {E93EB175-0FD3-4BFD-B81A-CDAF33998932}.Release|Any CPU.Build.0 = Release|Any CPU + {E93EB175-0FD3-4BFD-B81A-CDAF33998932}.Release|x64.ActiveCfg = Release|Any CPU + {E93EB175-0FD3-4BFD-B81A-CDAF33998932}.Release|x64.Build.0 = Release|Any CPU + {E93EB175-0FD3-4BFD-B81A-CDAF33998932}.Release|x86.ActiveCfg = Release|Any CPU + {E93EB175-0FD3-4BFD-B81A-CDAF33998932}.Release|x86.Build.0 = Release|Any CPU + EndGlobalSection +EndGlobal diff --git a/src/NET_8/EmbeddedWindows/EmbeddedWindows/App.xaml b/src/NET_8/EmbeddedWindows/EmbeddedWindows/App.xaml new file mode 100644 index 0000000..89ba56a --- /dev/null +++ b/src/NET_8/EmbeddedWindows/EmbeddedWindows/App.xaml @@ -0,0 +1,49 @@ + + + + + + + + + + #512BD4 + + + + + + 14 + + + + + + + + + diff --git a/src/NET_8/EmbeddedWindows/EmbeddedWindows/App.xaml.cs b/src/NET_8/EmbeddedWindows/EmbeddedWindows/App.xaml.cs new file mode 100644 index 0000000..d5d04f2 --- /dev/null +++ b/src/NET_8/EmbeddedWindows/EmbeddedWindows/App.xaml.cs @@ -0,0 +1,30 @@ +namespace EmbeddedWindows +{ + /// + /// Provides application-specific behavior to supplement the default Application class. + /// + public partial class App : Application + { + /// + /// 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(); + } + + /// + /// Invoked when the application is launched normally by the end user. Other entry points + /// will be used such as when the application is launched to open a specific file. + /// + /// Details about the launch request and process. + protected override void OnLaunched(LaunchActivatedEventArgs args) + { + m_window = new MainWindow(); + m_window?.Activate(); + } + + private Window? m_window; + } +} diff --git a/src/NET_8/EmbeddedWindows/EmbeddedWindows/Assets/LockScreenLogo.scale-200.png b/src/NET_8/EmbeddedWindows/EmbeddedWindows/Assets/LockScreenLogo.scale-200.png new file mode 100644 index 0000000..7440f0d Binary files /dev/null and b/src/NET_8/EmbeddedWindows/EmbeddedWindows/Assets/LockScreenLogo.scale-200.png differ diff --git a/src/NET_8/EmbeddedWindows/EmbeddedWindows/Assets/SplashScreen.scale-200.png b/src/NET_8/EmbeddedWindows/EmbeddedWindows/Assets/SplashScreen.scale-200.png new file mode 100644 index 0000000..32f486a Binary files /dev/null and b/src/NET_8/EmbeddedWindows/EmbeddedWindows/Assets/SplashScreen.scale-200.png differ diff --git a/src/NET_8/EmbeddedWindows/EmbeddedWindows/Assets/Square150x150Logo.scale-200.png b/src/NET_8/EmbeddedWindows/EmbeddedWindows/Assets/Square150x150Logo.scale-200.png new file mode 100644 index 0000000..53ee377 Binary files /dev/null and b/src/NET_8/EmbeddedWindows/EmbeddedWindows/Assets/Square150x150Logo.scale-200.png differ diff --git a/src/NET_8/EmbeddedWindows/EmbeddedWindows/Assets/Square44x44Logo.scale-200.png b/src/NET_8/EmbeddedWindows/EmbeddedWindows/Assets/Square44x44Logo.scale-200.png new file mode 100644 index 0000000..f713bba Binary files /dev/null and b/src/NET_8/EmbeddedWindows/EmbeddedWindows/Assets/Square44x44Logo.scale-200.png differ diff --git a/src/NET_8/EmbeddedWindows/EmbeddedWindows/Assets/Square44x44Logo.targetsize-24_altform-unplated.png b/src/NET_8/EmbeddedWindows/EmbeddedWindows/Assets/Square44x44Logo.targetsize-24_altform-unplated.png new file mode 100644 index 0000000..dc9f5be Binary files /dev/null and b/src/NET_8/EmbeddedWindows/EmbeddedWindows/Assets/Square44x44Logo.targetsize-24_altform-unplated.png differ diff --git a/src/NET_8/EmbeddedWindows/EmbeddedWindows/Assets/StoreLogo.png b/src/NET_8/EmbeddedWindows/EmbeddedWindows/Assets/StoreLogo.png new file mode 100644 index 0000000..a4586f2 Binary files /dev/null and b/src/NET_8/EmbeddedWindows/EmbeddedWindows/Assets/StoreLogo.png differ diff --git a/src/NET_8/EmbeddedWindows/EmbeddedWindows/Assets/Wide310x150Logo.scale-200.png b/src/NET_8/EmbeddedWindows/EmbeddedWindows/Assets/Wide310x150Logo.scale-200.png new file mode 100644 index 0000000..8b4a5d0 Binary files /dev/null and b/src/NET_8/EmbeddedWindows/EmbeddedWindows/Assets/Wide310x150Logo.scale-200.png differ diff --git a/src/NET_8/EmbeddedWindows/EmbeddedWindows/EmbeddedWindows.csproj b/src/NET_8/EmbeddedWindows/EmbeddedWindows/EmbeddedWindows.csproj new file mode 100644 index 0000000..d9710bc --- /dev/null +++ b/src/NET_8/EmbeddedWindows/EmbeddedWindows/EmbeddedWindows.csproj @@ -0,0 +1,68 @@ + + + + net8.0-windows10.0.19041.0 + 10.0.17763.0 + WinExe + + + true + true + None + + + enable + + EmbeddedWindows + false + + + true + x86;x64;arm64 + app.manifest + win10-$(Platform).pubxml + win10-x86;win10-x64;win10-arm64 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + true + + diff --git a/src/NET_8/EmbeddedWindows/EmbeddedWindows/Imports.cs b/src/NET_8/EmbeddedWindows/EmbeddedWindows/Imports.cs new file mode 100644 index 0000000..d2ebb32 --- /dev/null +++ b/src/NET_8/EmbeddedWindows/EmbeddedWindows/Imports.cs @@ -0,0 +1,3 @@ +global using Microsoft.UI.Xaml; + +global using MauiLib; diff --git a/src/NET_8/EmbeddedWindows/EmbeddedWindows/Package.appxmanifest b/src/NET_8/EmbeddedWindows/EmbeddedWindows/Package.appxmanifest new file mode 100644 index 0000000..c189ff9 --- /dev/null +++ b/src/NET_8/EmbeddedWindows/EmbeddedWindows/Package.appxmanifest @@ -0,0 +1,48 @@ + + + + + + + + EmbeddedWindows + User Name + Assets\StoreLogo.png + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/NET_8/EmbeddedWindows/EmbeddedWindows/Properties/PublishProfiles/win10-arm64.pubxml b/src/NET_8/EmbeddedWindows/EmbeddedWindows/Properties/PublishProfiles/win10-arm64.pubxml new file mode 100644 index 0000000..6de21bb --- /dev/null +++ b/src/NET_8/EmbeddedWindows/EmbeddedWindows/Properties/PublishProfiles/win10-arm64.pubxml @@ -0,0 +1,20 @@ + + + + + FileSystem + arm64 + win10-arm64 + bin\$(Configuration)\$(TargetFramework)\$(RuntimeIdentifier)\publish\ + true + False + False + True + + + \ No newline at end of file diff --git a/src/NET_8/EmbeddedWindows/EmbeddedWindows/Properties/PublishProfiles/win10-x64.pubxml b/src/NET_8/EmbeddedWindows/EmbeddedWindows/Properties/PublishProfiles/win10-x64.pubxml new file mode 100644 index 0000000..ed11b9d --- /dev/null +++ b/src/NET_8/EmbeddedWindows/EmbeddedWindows/Properties/PublishProfiles/win10-x64.pubxml @@ -0,0 +1,20 @@ + + + + + FileSystem + x64 + win10-x64 + bin\$(Configuration)\$(TargetFramework)\$(RuntimeIdentifier)\publish\ + true + False + False + True + + + \ No newline at end of file diff --git a/src/NET_8/EmbeddedWindows/EmbeddedWindows/Properties/PublishProfiles/win10-x86.pubxml b/src/NET_8/EmbeddedWindows/EmbeddedWindows/Properties/PublishProfiles/win10-x86.pubxml new file mode 100644 index 0000000..e908edd --- /dev/null +++ b/src/NET_8/EmbeddedWindows/EmbeddedWindows/Properties/PublishProfiles/win10-x86.pubxml @@ -0,0 +1,20 @@ + + + + + FileSystem + x86 + win10-x86 + bin\$(Configuration)\$(TargetFramework)\$(RuntimeIdentifier)\publish\ + true + False + False + True + + + \ No newline at end of file diff --git a/src/NET_8/EmbeddedWindows/EmbeddedWindows/Properties/launchSettings.json b/src/NET_8/EmbeddedWindows/EmbeddedWindows/Properties/launchSettings.json new file mode 100644 index 0000000..17e88f8 --- /dev/null +++ b/src/NET_8/EmbeddedWindows/EmbeddedWindows/Properties/launchSettings.json @@ -0,0 +1,10 @@ +{ + "profiles": { + "EmbeddedWindows (Package)": { + "commandName": "MsixPackage" + }, + "EmbeddedWindows (Unpackaged)": { + "commandName": "Project" + } + } +} diff --git a/src/NET_8/EmbeddedWindows/EmbeddedWindows/Resources/Fonts/OpenSans-Regular.ttf b/src/NET_8/EmbeddedWindows/EmbeddedWindows/Resources/Fonts/OpenSans-Regular.ttf new file mode 100644 index 0000000..c9237de Binary files /dev/null and b/src/NET_8/EmbeddedWindows/EmbeddedWindows/Resources/Fonts/OpenSans-Regular.ttf differ diff --git a/src/NET_8/EmbeddedWindows/EmbeddedWindows/Resources/Fonts/OpenSans-SemiBold.ttf b/src/NET_8/EmbeddedWindows/EmbeddedWindows/Resources/Fonts/OpenSans-SemiBold.ttf new file mode 100644 index 0000000..0da9f99 Binary files /dev/null and b/src/NET_8/EmbeddedWindows/EmbeddedWindows/Resources/Fonts/OpenSans-SemiBold.ttf differ diff --git a/src/NET_8/EmbeddedWindows/EmbeddedWindows/Views/MainWindow.xaml b/src/NET_8/EmbeddedWindows/EmbeddedWindows/Views/MainWindow.xaml new file mode 100644 index 0000000..9fb6854 --- /dev/null +++ b/src/NET_8/EmbeddedWindows/EmbeddedWindows/Views/MainWindow.xaml @@ -0,0 +1,10 @@ + + + diff --git a/src/NET_8/EmbeddedWindows/EmbeddedWindows/Views/MainWindow.xaml.cs b/src/NET_8/EmbeddedWindows/EmbeddedWindows/Views/MainWindow.xaml.cs new file mode 100644 index 0000000..428c1e5 --- /dev/null +++ b/src/NET_8/EmbeddedWindows/EmbeddedWindows/Views/MainWindow.xaml.cs @@ -0,0 +1,31 @@ +using Microsoft.Maui.Hosting; +using Microsoft.Maui.Platform; +using Microsoft.Maui; +using Microsoft.Maui.Embedding; +using Microsoft.Extensions.DependencyInjection; + +namespace EmbeddedWindows +{ + /// + /// An empty window that can be used on its own or navigated to within a Frame. + /// + public sealed partial class MainWindow : Window + { + public MainWindow() + { + this.InitializeComponent(); + + var mauiApp = MauiApp.CreateBuilder() + .UseMauiEmbedding() + .ConfigureFonts(fonts => + { + fonts.AddFont("OpenSans-Regular.ttf", "OS400"); + fonts.AddFont("OpenSans-SemiBold.ttf", "OS600"); + }) + .Build(); + // While doing .NET MAUI Embedding, this call is required so that the Application object instance gets resolved. + var _ = mauiApp.Services.GetRequiredService(); + Content = new MauiPage().ToPlatform(new MauiContext(mauiApp.Services)); + } + } +} diff --git a/src/NET_8/EmbeddedWindows/EmbeddedWindows/app.manifest b/src/NET_8/EmbeddedWindows/EmbeddedWindows/app.manifest new file mode 100644 index 0000000..79aef20 --- /dev/null +++ b/src/NET_8/EmbeddedWindows/EmbeddedWindows/app.manifest @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + true/PM + PerMonitorV2, PerMonitor + + + diff --git a/src/NET_8/EmbeddedWindows/MauiLib/Imports.cs b/src/NET_8/EmbeddedWindows/MauiLib/Imports.cs new file mode 100644 index 0000000..c14e5b8 --- /dev/null +++ b/src/NET_8/EmbeddedWindows/MauiLib/Imports.cs @@ -0,0 +1,2 @@ +// Static +global using static Microsoft.Maui.Graphics.Colors; diff --git a/src/NET_8/EmbeddedWindows/MauiLib/MauiLib.csproj b/src/NET_8/EmbeddedWindows/MauiLib/MauiLib.csproj new file mode 100644 index 0000000..f0bce63 --- /dev/null +++ b/src/NET_8/EmbeddedWindows/MauiLib/MauiLib.csproj @@ -0,0 +1,32 @@ + + + + + + net8.0-windows10.0.19041.0 + $(TargetFrameworks);net8.0 + + + true + true + true + + + enable + latest + enable + MauiLib + + + 10.0.17763.0 + + + 10.0.17763.0 + + + + + + + + diff --git a/src/NET_8/EmbeddedWindows/MauiLib/MauiPage.xaml b/src/NET_8/EmbeddedWindows/MauiLib/MauiPage.xaml new file mode 100644 index 0000000..a0261ed --- /dev/null +++ b/src/NET_8/EmbeddedWindows/MauiLib/MauiPage.xaml @@ -0,0 +1,18 @@ + + + + + + + diff --git a/src/NET_8/EmbeddedWindows/MauiLib/MauiPage.xaml.cs b/src/NET_8/EmbeddedWindows/MauiLib/MauiPage.xaml.cs new file mode 100644 index 0000000..f58020b --- /dev/null +++ b/src/NET_8/EmbeddedWindows/MauiLib/MauiPage.xaml.cs @@ -0,0 +1,10 @@ +namespace MauiLib +{ + public partial class MauiPage : ContentPage + { + public MauiPage() + { + InitializeComponent(); + } + } +} diff --git a/src/NET_8/EmbeddedWindows/MauiLib/MyApp.xaml b/src/NET_8/EmbeddedWindows/MauiLib/MyApp.xaml new file mode 100644 index 0000000..ed24f27 --- /dev/null +++ b/src/NET_8/EmbeddedWindows/MauiLib/MyApp.xaml @@ -0,0 +1,20 @@ + + + + OS400 + #512BD4 + + + + diff --git a/src/NET_8/EmbeddedWindows/MauiLib/MyApp.xaml.cs b/src/NET_8/EmbeddedWindows/MauiLib/MyApp.xaml.cs new file mode 100644 index 0000000..56f420b --- /dev/null +++ b/src/NET_8/EmbeddedWindows/MauiLib/MyApp.xaml.cs @@ -0,0 +1,10 @@ +namespace MauiLib +{ + public partial class MyApp : Application + { + public MyApp() + { + InitializeComponent(); + } + } +} diff --git a/src/NET_8/global.json b/src/NET_8/global.json new file mode 100644 index 0000000..14efa8b --- /dev/null +++ b/src/NET_8/global.json @@ -0,0 +1,6 @@ +{ + "sdk": { + "rollForward": "latestMinor", + "version": "8.0.100" + } +}