Uwp custom form works with multiple windows forms?

Pradeep B 21 Reputation points
2022-07-20T07:46:57.973+00:00

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.
222510-winform-uwp.png

Developer technologies | Windows Forms
Developer technologies | Universal Windows Platform (UWP)
0 comments No comments
{count} votes

Answer accepted by question author
  1. Nico Zhu (Shanghai Wicresoft Co,.Ltd.) 12,871 Reputation points
    2022-07-21T03:38:03.737+00:00

    Hello,
    Welcome to Microsoft Q&A!

    when I click on the second button it won't show anything at all in the form.

    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());  
      
    }  
    

    Thank you.


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

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