Skip to content

(Winui3/C++) How to correctly initialize the data of the window class (e.g., MainWindow). #436

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
BaiFeng666 opened this issue Apr 6, 2025 · 1 comment

Comments

@BaiFeng666
Copy link

C++ WinUI 3 examples are really scarce.
I need to initialize the following code:
sourceList().ItemsSource(sourceArray);

struct MainWindow : MainWindowT<MainWindow>
{
    MainWindow()
    {
        // Xaml objects should not call InitializeComponent during construction.
        // See https://github.com/microsoft/cppwinrt/tree/master/nuget#initializecomponent

       //When I initialize here, an error occurs. I think it's because the component is not fully initialized.
        sourceList().ItemsSource(sourceArray); 
    }
...

Where should I elegantly and right implement the initialization of this code?

@lgztx96
Copy link

lgztx96 commented Apr 12, 2025

// Xaml objects should not call InitializeComponent during construction.
// See https://github.com/microsoft/cppwinrt/tree/master/nuget#initializecomponent
This actually already told you.

Image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants