Transform Syncfusion WASM application to Blazor hybrid to WinForms

Hello,

I have an existing Blazor WASM application. I try convert the app to Blazor Hybrid to execute it in a WinForms application.

I follow this tutorial as starting point:

https://docs.microsoft.com/hu-hu/aspnet/core/blazor/hybrid/tutorials/windows-forms?view=aspnetcore-6.0

Next step I install the Syncfusion.Blazor.Calendars nuget and insert a DatePicker to my component:

@using Syncfusion.Blazor.Calendars


<h1>Counter</h1>


<p>Current count: @currentCount</p>


<button class="btn btn-primary" @onclick="IncrementCount">Click me</button>


@code {

    private int currentCount = 0;


    private void IncrementCount()

    {

        currentCount++;

    }

}


<SfDatePicker TValue="DateTime" Placeholder="Choose a Date" ShowClearButton="true" Value="DateTime.Now"></SfDatePicker>

When I execute the WinForms app, the following error appear:




My question is:

My conception is a working scenario? It is possible to convert my source app with Syncfusion controls to Blazor Hybrid to use it in a Winforms Application?

If yes, do you have any example about this conversion?

Thank you very much!


Best Regrads,

SZL


7 Replies 1 reply marked as answer

SP Sureshkumar P Syncfusion Team June 27, 2022 09:09 AM UTC

Hi SZL,

For our own WinForms platform, default datepicker functionality is available. Would you kindly confirm that you require support for our own WinForms component or hybrid support? We will deliver the precise answer as soon as we have your confirmation.

To know more about our WinForms support. Please refer to the documentation: https://help.syncfusion.com/windowsforms/datetimepicker/getting-started

Regards,

Sureshkumar P



SZ SZL June 27, 2022 10:05 AM UTC

Hi,

Yes, I know that you have native WinForms controls, but I have an existing application in Blazor Webassembly. 

So I dont would like re-develop the full application, I plan move the existing code (the blazor wasm components are compatible with hybrid app) and use it in a Winforms application like in the above link the example shows. 


Thank you!





SP Sureshkumar P Syncfusion Team June 28, 2022 07:09 AM UTC

Hi SZL,

As per your confirmation, we have created the hybrid application for rendering the blazor component into the WinForms application by referring to your mentioned Microsoft documentation.

Please find the code changed here:

[wwwroot/index.html]

<link rel='nofollow' href="https://cdn.syncfusion.com/ej2/bootstrap5.css" rel="stylesheet">

    <script src="https://cdn.syncfusion.com/blazor/20.1.47/syncfusion-blazor.min.js"></script>

 

[Counter.razor]

@using Syncfusion.Blazor.Calendars

 

<SfDatePicker TValue="DateTime" Placeholder="Choose a Date" ShowClearButton="true" Value="DateTime.Now"></SfDatePicker>

 

[Form1.cs]

using Microsoft.AspNetCore.Components.WebView.WindowsForms;

using Microsoft.Extensions.DependencyInjection;

using Syncfusion.Blazor;

 

namespace WinFormsTesting

{

    public partial class Form1 : Form

    {

        public Form1()

        {

            InitializeComponent();

 

            var services = new ServiceCollection();

            services.AddSyncfusionBlazor();

            services.AddWindowsFormsBlazorWebView();

            blazorWebView1.HostPage = "wwwroot\\index.html";

            blazorWebView1.Services = services.BuildServiceProvider();

            blazorWebView1.RootComponents.Add<Counter>("#app");

        }

    }

}

 

Find the sample in the attachment:

Regards,

Sureshkumar P


Attachment: WinFormsTesting_924c33eb.zip

Marked as answer

SZ SZL replied to Sureshkumar P June 28, 2022 07:33 AM UTC

This is amazing! Thank you very much!

What do you think about the performance of this scenario? It will be faster than my original Blazor Webassembly application? Do you have any experience with this?

If I good see, the Winforms version not using Webassembly in Hybrid app:

"In a Blazor Hybrid app, Razor components run natively on the device. Components render to an embedded Web View control through a local interop channel. Components don't run in the browser, and WebAssembly isn't involved. Razor components load and execute code quickly, and components have full access to the native capabilities of the device through the .NET platform."

Right now, it’s hard to decide for me that I should redesign my app for more performance, or not. 

I don't know how much faster it would be in WinForms.

Thanks!




SP Sureshkumar P Syncfusion Team June 29, 2022 06:14 AM UTC

Hi SZL,

We appreciate your update. WASM, server-side, and MAUI apps are supported with our Blazor components. You can utilize our component with your application if this hybrid WinForms is appropriate for it.

Regards,

Sureshkumar P



UH Uwe Hein replied to Sureshkumar P November 30, 2023 09:52 PM UTC

Hi Sureshkumar P,  

  thank you for the sample. That was really helpful. I am planning to integrate components of a Syncfusion Blazor serverside app into a .net 8 winforms app with heavy use of scheduler and sfgrid. How do I integrate localization into your sample ? How and where do I add :


Snippet
			builder.Services.Configure<RequestLocalizationOptions>(options =>
			{
				// Define the list of cultures your app will support
				var supportedCultures = new List<CultureInfo>()
				{
                    // new CultureInfo("en-US"),
                    new CultureInfo("de")
				};
 
				// Set the default culture
				options.DefaultRequestCulture = new RequestCulture("de");
				options.SupportedCultures = supportedCultures;
				options.SupportedUICultures = supportedCultures;
			});

and

Snippet
builder.Services.AddLocalization(options => options.ResourcesPath = "Resources");

from my program.cs of my Blazor app into the winforms app ?

  regards

      Uwe

 






KP Kokila Poovendran Syncfusion Team February 23, 2024 07:19 AM UTC

Hi Uwe Hein,


We have created a new branch forum for your last query. Kindly follow the below forums for further assistance. 


GridLocalization in grid. | Syncfusion Forum Assist

SchedulerLocalization in Scheduler - from 175853 | Syncfusion Forum Assist



Loader.
Up arrow icon