Search code examples
c#winforms.net-coreuwp-xamlwinui

Uwp App can continues work with multiple forms?


I have created a Uwp App that is directly referenced in the NetCore3.1 Winforms application. I used XamlHost to show custom control in Winforms. When I run the application it shows particular control only one time (When I press the first button to show some custom control and when I click on the second button it won't show anything at all in the form, it is simply blank form and the same way if we go back to previous control it won't work.).It only works one time in the XamlHost.

Are there any possibilities to work these multiple forms with multiple custom control from the UWP app?

For More info please find the project from link => winform uwp application.

For more info please find the attached screenshot.screenshot


Solution

  • it is simply blank form and the same way if we go back to previous control it won't work.).It only works one time in the XamlHost.

    During checked your code, I found you have not initialized UWPApplication.App in Winform Main method. Please replace the contents of Program.cs with the following

    [System.STAThreadAttribute()]
    static void Main()
    {
        Application.SetHighDpiMode(HighDpiMode.SystemAware);
        Application.EnableVisualStyles();
        Application.SetCompatibleTextRenderingDefault(false);
        using (new UWPApplication.App())
        {
           
        }
        Application.Run(new Form1());
    
    }