'Binding a WPF ComboBox to a List in new Window

I am new to WPF...

I am trying to bind a List to a combobox in a new Window.

The List is in the following class:

public class TestClass
{
    public List<string> ComboBoxItems = new List<string>
    {
        "Item 1", "Item2"
    };
}

From MainWindow a new TestWindow is created:

private void TestWindow_Click(object sender, RoutedEventArgs e)
{
    var test = new TestClass();
        
    var win = new TestWindow { DataContext = test };
    win.Show();
}

In XAML I tried to bind the ComboBoxItems to the ComboBox like:

<Window ...
        Title="TestWindow" Height="200" Width="300">
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition />
            <RowDefinition />
        </Grid.RowDefinitions>
        <ComboBox Name="combo" ItemsSource="{Binding ComboBoxItems}"/>
    </Grid>
</Window>

I thought when I set the DataContext of this new window to an instance of my TestClass, then I have access to its members (including the list ComboBoxItems) and can bind them.

But the ComboBox is empty:

Empty ComboBox

Can you tell me what I am doing wrong?

By the way: In XAML Editor there is no IntelliSense?

Visual Studio XAML Editor

Any tips for that?

Thanks!



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source