Wpf.Extensions.Hosting icon indicating copy to clipboard operation
Wpf.Extensions.Hosting copied to clipboard

Can not work on Blazor Hybrid Wpf.

Open neko3cs opened this issue 1 year ago • 1 comments

Environment

dotnet --version

  • 8.0.205

dotnet --list-runtimes | where { $_.Contains("8.") }

  • Microsoft.AspNetCore.App 8.0.5 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  • Microsoft.NETCore.App 8.0.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  • Microsoft.WindowsDesktop.App 8.0.5 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

Steps to reproduce

  1. Create a Blazor Hybird Wpf project based on the following this site.
  2. Apply Wpf.Extensions.Hosting with reference to the following site.

Sample code

This is sample code I made.

SampleBlazorHybridWpf.zip

Expected

This screen displayed.

image

Actural

This screen displayed.

image

Additional context

I know the following this:

  1. If the following code is enabled in Program.cs, it will not work.
builder.Services.AddWpfBlazorWebView();
  1. It works if the following code is enabled in MainWindow.xaml.cs.
var serviceCollection = new ServiceCollection();
serviceCollection.AddWpfBlazorWebView();
Resources.Add(“services”, serviceCollection.BuildServiceProvider());

neko3cs avatar May 20 '24 02:05 neko3cs

@neko3cs Change the MainWindow class in MainWindow.xaml.cs to the following code to make it work properly.

public partial class MainWindow : Window
{
    public MainWindow(IServiceProvider serviceProvider)
    {
        InitializeComponent();
        Resources.Add("services", serviceProvider);
    }
}

image

Summpot avatar Jan 10 '25 07:01 Summpot