WindowsAppSDK-Samples icon indicating copy to clipboard operation
WindowsAppSDK-Samples copied to clipboard

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

Open BaiFeng666 opened this issue 9 months ago • 1 comments

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?

BaiFeng666 avatar Apr 06 '25 20:04 BaiFeng666

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

Image

lgztx96 avatar Apr 12 '25 11:04 lgztx96