Skip to content

Commit a9f6ee7

Browse files
authored
Merge pull request #71 from egvijayanand/working
WinUI 3 native embedding of BlazorWebView sample
2 parents 43ea32b + 8fceb1d commit a9f6ee7

Some content is hidden

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

49 files changed

+1430
-7
lines changed

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ publish/
174174
*.azurePubxml
175175
# Note: Comment the next line if you want to checkin your web deploy settings,
176176
# but database connection strings (with potential passwords) will be unencrypted
177-
*.pubxml
177+
#*.pubxml
178178
*.publishproj
179179

180180
# Microsoft Azure Web App publish settings. Comment the next line if you want to

README.md

+9-1
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,16 @@ Available under the `src` directory:
3131
* `PopupDialogs` - Sample project to demonstrate the custom dialogs implemented with [VijayAnand.MauiToolkit.Pro](https://www.nuget.org/packages/VijayAnand.MauiToolkit.Pro) NuGet package.
3232
* `HybridRclApp` - `BlazorWebView` hybrid sample
3333
- A hybrid solution demonstrating the capabilities of `BlazorWebView` control
34-
- Loaded with `.NET MAUI`, `Windows Forms` and `WPF` projects in a single solution
34+
- Loaded with `.NET MAUI`, `Windows Forms`, `WPF`, and `WinUI 3` projects in a single solution
3535
- Razor components abstracted in a shared Razor Class Library (RCL)
36+
- While working with the **WinUI 3** **Unpackaged** model, the below project property needs to be uncommented in the project file otherwise it'll result in the mentioned error message _and for the **Packaged** model, this property needs to stay as commented_:
37+
38+
```xml
39+
<WindowsPackageType>None</WindowsPackageType>
40+
```
41+
42+
**Error message:**
43+
Unable to load DLL 'Microsoft.ui.xaml.dll' or one of its dependencies: The specified module could not be found. (0x8007007E)
3644

3745
* C# Samples - C# version of the [.NET MAUI UI Challenge](https://aka.ms/maui/UIChallenge) - [Awesome UIs](https://github.com/jsuarezruiz/dotnet-maui-showcase) without any XAML usage - Stay tuned for more samples ...
3846
- Made available under the `src/C#-Samples/` folder
Binary file not shown.

src/HybridRclApp/HybridRclApp.WinForms/wwwroot/index.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<html>
33

44
<head>
5-
<meta charset="utf-8" />
5+
<meta charset="UTF-8" />
66
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
77
<title>Blazor app</title>
88
<base href="/" />
+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// To learn more about WinUI, the WinUI project structure,
2+
// and more about our project templates, see: http://aka.ms/winui-project-info.
3+
4+
namespace HybridRclApp.WinUI
5+
{
6+
/// <summary>
7+
/// Provides application-specific behavior to supplement the default Application class.
8+
/// </summary>
9+
public partial class App : Application
10+
{
11+
/// <summary>
12+
/// Initializes the singleton application object. This is the first line of authored code
13+
/// executed, and as such is the logical equivalent of main() or WinMain().
14+
/// </summary>
15+
public App()
16+
{
17+
this.InitializeComponent();
18+
}
19+
20+
/// <summary>
21+
/// Invoked when the application is launched normally by the end user. Other entry points
22+
/// will be used such as when the application is launched to open a specific file.
23+
/// </summary>
24+
/// <param name="args">Details about the launch request and process.</param>
25+
protected override void OnLaunched(LaunchActivatedEventArgs args)
26+
{
27+
new MainWindow().Activate();
28+
}
29+
}
30+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<Project Sdk="Microsoft.NET.Sdk.Razor">
3+
<PropertyGroup>
4+
<TargetFramework>net8.0-windows10.0.19041.0</TargetFramework>
5+
<TargetPlatformMinVersion>10.0.17763.0</TargetPlatformMinVersion>
6+
<OutputType>WinExe</OutputType>
7+
8+
<!-- .NET MAUI -->
9+
<UseMaui>true</UseMaui>
10+
<SingleProject>true</SingleProject>
11+
<EnableDefaultCssItems>false</EnableDefaultCssItems>
12+
13+
<!-- Uncomment the below property if intended to run the project as Unpackaged -->
14+
<!--<WindowsPackageType>None</WindowsPackageType>-->
15+
16+
<!-- Display name -->
17+
<ApplicationTitle>HybridRclApp</ApplicationTitle>
18+
19+
<!-- App Identifier -->
20+
<ApplicationIdGuid>7d3b675d-62d4-427d-a35d-bcf4194ec2a9</ApplicationIdGuid>
21+
22+
<!-- Versions -->
23+
<ApplicationDisplayVersion>1.0</ApplicationDisplayVersion>
24+
<ApplicationVersion>1</ApplicationVersion>
25+
26+
<!-- WinUI 3 -->
27+
<UseWinUI>true</UseWinUI>
28+
<EnableMsixTooling>true</EnableMsixTooling>
29+
30+
<!-- Project Options -->
31+
<Nullable>enable</Nullable>
32+
<LangVersion>latest</LangVersion>
33+
<!--<ImplicitUsings>enable</ImplicitUsings>-->
34+
<RootNamespace>HybridRclApp.WinUI</RootNamespace>
35+
36+
<!-- App Options -->
37+
<Platforms>x86;x64;arm64</Platforms>
38+
<ApplicationManifest>app.manifest</ApplicationManifest>
39+
<PublishProfile>win10-$(Platform).pubxml</PublishProfile>
40+
<RuntimeIdentifiers>win10-x86;win10-x64;win10-arm64</RuntimeIdentifiers>
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+
<PackageReference Include="VijayAnand.MauiBlazor.Markup" Version="3.0.0-preview.*" />
59+
<Manifest Include="$(ApplicationManifest)" />
60+
</ItemGroup>
61+
62+
<!--
63+
Defining the "Msix" ProjectCapability here allows the Single-project MSIX Packaging
64+
Tools extension to be activated for this project even if the Windows App SDK Nuget
65+
package has not yet been restored.
66+
-->
67+
<ItemGroup Condition="'$(DisableMsixProjectCapabilityAddedByProject)'!='true' and '$(EnableMsixTooling)'=='true'">
68+
<ProjectCapability Include="Msix" />
69+
</ItemGroup>
70+
71+
<ItemGroup>
72+
<ProjectReference Include="..\HybridRclApp.RazorLib\HybridRclApp.RazorLib.csproj" />
73+
</ItemGroup>
74+
75+
<!--
76+
Defining the "HasPackageAndPublishMenuAddedByProject" property here allows the Solution
77+
Explorer "Package and Publish" context menu entry to be enabled for this project even if
78+
the Windows App SDK Nuget package has not yet been restored.
79+
-->
80+
<PropertyGroup Condition="'$(DisableHasPackageAndPublishMenuAddedByProject)'!='true' and '$(EnableMsixTooling)'=='true'">
81+
<HasPackageAndPublishMenu>true</HasPackageAndPublishMenu>
82+
</PropertyGroup>
83+
</Project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
global using Microsoft.UI.Xaml;
2+
global using Microsoft.UI.Xaml.Controls;
3+
4+
global using HybridRclApp.RazorLib.Data;
5+
global using HybridRclApp.RazorLib.Pages;
6+
global using HybridRclApp.RazorLib.Shared;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<Router AppAssembly="@GetType().Assembly" AdditionalAssemblies="new[] { typeof(Counter).Assembly }">
2+
<Found Context="routeData">
3+
<RouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)" />
4+
</Found>
5+
<NotFound>
6+
<LayoutView Layout="@typeof(MainLayout)">
7+
<p>Sorry, there's nothing at this address.</p>
8+
</LayoutView>
9+
</NotFound>
10+
</Router>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// To learn more about WinUI, the WinUI project structure,
2+
// and more about our project templates, see: http://aka.ms/winui-project-info.
3+
4+
using Microsoft.AspNetCore.Components.WebView.Maui;
5+
using VijayAnand.MauiBlazor.Markup;
6+
using Microsoft.Maui.Platform;
7+
using Microsoft.Extensions.DependencyInjection;
8+
using Microsoft.Maui;
9+
using static Microsoft.Maui.Dispatching.Dispatcher;
10+
11+
namespace HybridRclApp.WinUI
12+
{
13+
/// <summary>
14+
/// An empty window that can be used on its own or navigated to within a Frame.
15+
/// </summary>
16+
public sealed partial class MainWindow : Window
17+
{
18+
public MainWindow()
19+
{
20+
var services = new ServiceCollection();
21+
services.AddSingleton(GetForCurrentThread()!);
22+
services.AddMauiBlazorWebView();
23+
services.AddSingleton<WeatherForecastService>();
24+
#if DEBUG
25+
services.AddBlazorWebViewDeveloperTools();
26+
#endif
27+
28+
Content = new Grid()
29+
{
30+
Children =
31+
{
32+
new BlazorWebView().Configure("wwwroot/index.html", "/counter", ("#app", typeof(Main), null))
33+
.ToPlatform(new MauiContext(services.BuildServiceProvider()))
34+
}
35+
};
36+
}
37+
}
38+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<Package
4+
xmlns="http://schemas.microsoft.com/appx/manifest/foundation/windows10"
5+
xmlns:uap="http://schemas.microsoft.com/appx/manifest/uap/windows10"
6+
xmlns:rescap="http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities"
7+
IgnorableNamespaces="uap rescap">
8+
9+
<Identity Publisher="CN=User Name" />
10+
11+
<Properties>
12+
<PublisherDisplayName>User Name</PublisherDisplayName>
13+
</Properties>
14+
15+
<Dependencies>
16+
<TargetDeviceFamily Name="Windows.Universal" MinVersion="10.0.17763.0" MaxVersionTested="10.0.19041.0" />
17+
<TargetDeviceFamily Name="Windows.Desktop" MinVersion="10.0.17763.0" MaxVersionTested="10.0.19041.0" />
18+
</Dependencies>
19+
20+
<Resources>
21+
<Resource Language="x-generate"/>
22+
</Resources>
23+
24+
<Applications>
25+
<Application Id="App"
26+
Executable="$targetnametoken$.exe"
27+
EntryPoint="$targetentrypoint$">
28+
<uap:VisualElements />
29+
</Application>
30+
</Applications>
31+
32+
<Capabilities>
33+
<rescap:Capability Name="runFullTrust" />
34+
</Capabilities>
35+
</Package>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
namespace HybridRclApp.WinUI
2+
{
3+
#if !DISABLE_XAML_GENERATED_MAIN
4+
/// <summary>
5+
/// Program class
6+
/// </summary>
7+
public static class Program
8+
{
9+
[global::System.Runtime.InteropServices.DllImport("Microsoft.ui.xaml.dll")]
10+
private static extern void XamlCheckProcessRequirements();
11+
12+
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.UI.Xaml.Markup.Compiler"," 1.0.0.0")]
13+
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
14+
[global::System.STAThreadAttribute]
15+
static void Main(string[] args)
16+
{
17+
XamlCheckProcessRequirements();
18+
19+
global::WinRT.ComWrappersSupport.InitializeComWrappers();
20+
global::Microsoft.UI.Xaml.Application.Start((p) => {
21+
var context = new global::Microsoft.UI.Dispatching.DispatcherQueueSynchronizationContext(global::Microsoft.UI.Dispatching.DispatcherQueue.GetForCurrentThread());
22+
global::System.Threading.SynchronizationContext.SetSynchronizationContext(context);
23+
new App();
24+
});
25+
}
26+
}
27+
#endif
28+
29+
partial class App : global::Microsoft.UI.Xaml.Application
30+
{
31+
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.UI.Xaml.Markup.Compiler"," 1.0.0.0")]
32+
private bool _contentLoaded;
33+
/// <summary>
34+
/// InitializeComponent()
35+
/// </summary>
36+
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.UI.Xaml.Markup.Compiler"," 1.0.0.0")]
37+
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
38+
public void InitializeComponent()
39+
{
40+
if (_contentLoaded)
41+
return;
42+
43+
_contentLoaded = true;
44+
45+
global::System.Uri resourceLocator = new global::System.Uri("ms-appx:///App.xaml");
46+
global::Microsoft.UI.Xaml.Application.LoadComponent(this, resourceLocator);
47+
48+
#if DEBUG && !DISABLE_XAML_GENERATED_BINDING_DEBUG_OUTPUT
49+
DebugSettings.BindingFailed += (sender, args) =>
50+
{
51+
global::System.Diagnostics.Debug.WriteLine(args.Message);
52+
};
53+
#endif
54+
#if DEBUG && !DISABLE_XAML_GENERATED_BREAK_ON_UNHANDLED_EXCEPTION
55+
UnhandledException += (sender, e) =>
56+
{
57+
if (global::System.Diagnostics.Debugger.IsAttached) global::System.Diagnostics.Debugger.Break();
58+
};
59+
#endif
60+
}
61+
}
62+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
https://go.microsoft.com/fwlink/?LinkID=208121.
4+
-->
5+
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
6+
<PropertyGroup>
7+
<PublishProtocol>FileSystem</PublishProtocol>
8+
<Platform>arm64</Platform>
9+
<RuntimeIdentifier>win10-arm64</RuntimeIdentifier>
10+
<PublishDir>bin\$(Configuration)\$(TargetFramework)\$(RuntimeIdentifier)\publish\</PublishDir>
11+
<SelfContained>true</SelfContained>
12+
<PublishSingleFile>False</PublishSingleFile>
13+
<PublishReadyToRun Condition="'$(Configuration)' == 'Debug'">False</PublishReadyToRun>
14+
<PublishReadyToRun Condition="'$(Configuration)' != 'Debug'">True</PublishReadyToRun>
15+
<!--
16+
See https://github.com/microsoft/CsWinRT/issues/373
17+
<PublishTrimmed>True</PublishTrimmed>
18+
-->
19+
</PropertyGroup>
20+
</Project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
https://go.microsoft.com/fwlink/?LinkID=208121.
4+
-->
5+
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
6+
<PropertyGroup>
7+
<PublishProtocol>FileSystem</PublishProtocol>
8+
<Platform>x64</Platform>
9+
<RuntimeIdentifier>win10-x64</RuntimeIdentifier>
10+
<PublishDir>bin\$(Configuration)\$(TargetFramework)\$(RuntimeIdentifier)\publish\</PublishDir>
11+
<SelfContained>true</SelfContained>
12+
<PublishSingleFile>False</PublishSingleFile>
13+
<PublishReadyToRun Condition="'$(Configuration)' == 'Debug'">False</PublishReadyToRun>
14+
<PublishReadyToRun Condition="'$(Configuration)' != 'Debug'">True</PublishReadyToRun>
15+
<!--
16+
See https://github.com/microsoft/CsWinRT/issues/373
17+
<PublishTrimmed>True</PublishTrimmed>
18+
-->
19+
</PropertyGroup>
20+
</Project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
https://go.microsoft.com/fwlink/?LinkID=208121.
4+
-->
5+
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
6+
<PropertyGroup>
7+
<PublishProtocol>FileSystem</PublishProtocol>
8+
<Platform>x86</Platform>
9+
<RuntimeIdentifier>win10-x86</RuntimeIdentifier>
10+
<PublishDir>bin\$(Configuration)\$(TargetFramework)\$(RuntimeIdentifier)\publish\</PublishDir>
11+
<SelfContained>true</SelfContained>
12+
<PublishSingleFile>False</PublishSingleFile>
13+
<PublishReadyToRun Condition="'$(Configuration)' == 'Debug'">False</PublishReadyToRun>
14+
<PublishReadyToRun Condition="'$(Configuration)' != 'Debug'">True</PublishReadyToRun>
15+
<!--
16+
See https://github.com/microsoft/CsWinRT/issues/373
17+
<PublishTrimmed>True</PublishTrimmed>
18+
-->
19+
</PropertyGroup>
20+
</Project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"profiles": {
3+
"HybridRclApp.WinUI (Package)": {
4+
"commandName": "MsixPackage"
5+
},
6+
"HybridRclApp.WinUI (Unpackaged)": {
7+
"commandName": "Project"
8+
}
9+
}
10+
}
Binary file not shown.
Binary file not shown.

0 commit comments

Comments
 (0)