how to create new window?

mc 5,426 Reputation points
2023-07-18T00:56:01.34+00:00

var wnd=new LoginWindow();

and then?

Windows development Windows App SDK
{count} votes

Accepted answer
  1. Castorix31 90,521 Reputation points
    2023-07-18T02:02:13.0666667+00:00

    For example, a simple window with a Button :

                    Button btn1 = new Button()
                    {
                        Content = "Click",
                        HorizontalAlignment = HorizontalAlignment.Center
                    };
                    Window wnd1 = new Window()
                    {
                        Content = btn1
                    };
                    btn1.Click += (sender, e) =>
                    {
                        Console.Beep(5000, 10);
                    };               
                    wnd1.Activate();
    
    1 person found this answer helpful.
    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Xiaopo Yang - MSFT 12,731 Reputation points Microsoft External Staff
    2023-07-18T06:15:32.3966667+00:00

    Or you can create a new window in Visual Studio, Right Click solution->Add->New Item...->Blank Window, and then refer it in code. It’s also recommended to read the document, Show multiple views for an app.

    As a side note, it's necessary to modify the new window's IDL for WinUI3 c++.

    // Copyright (c) Microsoft Corporation and Contributors.
    // Licensed under the MIT License.
    
    namespace App1
    {
        [default_interface]
        runtimeclass BlankWindow : Microsoft.UI.Xaml.Window
        {
            BlankWindow();
            Int32 MyProperty;
        }
    }
    
    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.