views:

50

answers:

1

I have a simple ComboBox in my Silverlight 3 application. I want to populate it from an ObservableCollection. The list holds a class that has a Name(string), and a Selected(bool) property. The combo box has as many items as I have in the list, but I cannot seem to get the list data to appear.

Any help would be appreciated.

<ComboBox x:Name="cmbCategory" Grid.Column="3">
<ComboBox.ItemTemplate>
    <DataTemplate>
        <StackPanel Orientation="Horizontal">
            <TextBlock Text="{Binding Name}"/>
            <CheckBox IsChecked="{Binding Selected}"/>
        </StackPanel>
    </DataTemplate>
</ComboBox.ItemTemplate>

...
private class cmbCategoryClass
    {
        public string Name { get; set; }
        public bool Selected { get; set; }
    }
    private ObservableCollection<cmbCategoryClass> _categories;
....
cmbCategory.DataContext = _categories;
cmbCategory.ItemsSource = _categories;
A: 

I can't tell from your code if this is a Codebehind or a ViewModel. I am guessing that you are actually populating the _categories list in code so that it contains at least one cmbCategoryClass object. Try removing the line that sets the DataContext to _categories as your ItemsSource may be looking for a _categories property on the DataContext Check the Output window in Visual Studio when running in debug mode for clues to data binding failures.

DaveB