microsoft / microsoft/WindowsAppSDK-Samples

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

Open
#436 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
PowerShell
Stars
1k
Forks
335
Avg merge
5d 1h
Merged PRs (30d)
8

Description

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?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the MainWindow constructor and the referenced C++/WinRT InitializeComponent guidance. Determine the appropriate post-initialization point for sourceList().ItemsSource(sourceArray), then verify that the window initializes without the reported error.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
desktop
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.