How can we resolve Blazor library dependencies within razor files referenced using Microsoft's BlazorWebView from within a WPF app?

Owsen, Craig 21 Reputation points
2022-12-13T18:31:53.833+00:00

I am trying to reuse a razor page from a working Blazor Server app in a WPF Blazor Desktop app using BlazorWebVeiw. I am using Blazorize components in my razor file and I reference the Blazorise libraries in my _Imports.razor file. When I call the razor file with the Blazorise components, I get the following error message:

InvalidOperationException: Cannot provide a value for property 'JSUtilitiesModule' on type 'Blazorise.Text'. There is no registered service of type   
Blazorise.Modules.IJSUtilitiesModule'.  

The real strength of Blazor is access to third party component libraries, but how do we reference the libraries?

Developer technologies | Windows Presentation Foundation
Developer technologies | .NET | Blazor
{count} votes

1 answer

Sort by: Most helpful
  1. Owsen, Craig 21 Reputation points
    2022-12-14T22:31:30.717+00:00

    I figured it out. You need to add to each WPF .xaml.cs file that is referencing a Blazor .razor file:

    var serviceCollection = new ServiceCollection();

            serviceCollection.AddWpfBlazorWebView();  
    
            serviceCollection.AddBlazorise(options =>  
            {  
                //options.ChangeTextOnKeyPress = true; // optional  
            })  
                       .AddBootstrapProviders()  
                       .AddFontAwesomeIcons();  
    

    I would hope Microsoft development would enhance BlazorWebView to reference the index.html for services as oppose to copying essentially the same code into each and every WPF .xmal.cs file.

    Thank you so much for pointing me in the right direction!

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.