0

When I bind my ListBox to an ObservableCollection<Items> it dynamically, at the press of a Button, appends itself ListBoxItem children which have the result of Items.toString() in its content property. Although I don't understand why its children have Items.toString() as its content property, that's not my problem (I think it's related, though).

My problem is, when I add a Template to it, it doesn't show anything. I'll divide my code in two scenarios.

Scenario 1:

C Sharp

myListBox.DataContext(myObservableCollection);
myListBox.setBinding(ItemsControl.ItemsSourceProperty, new Binding());

XAML

<ListBox x:Name="myListBox" Height="200" Width="425" Margin="312,94,113,256">         

The ListBox shows:

-The returned result from item1.toString();
-The returned result from item2.toString();
...

Scenario 2:

C Sharp

myListBox.DataContext(myObservableCollection);
myListBox.setBinding(ItemsControl.ItemsSourceProperty, new Binding());

XAML

<ListBox x:Name="myListBox" Height="200" Width="425" Margin="312,94,113,256">                        
    <ListBox.ItemTemplate>
        <DataTemplate>
            <StackPanel Orientation="Horizontal">
                <!--property1 to property4 are properties of the type Items-->
                <TextBox Text="{Binding property1}"/>
                <Label Content="{Binding property2}"/>
                <Label Content="{Binding property3}"/>
                <Label Content="{Binding property4}"/>
            </StackPanel>
         </DataTemplate>
     </ListBox.ItemTemplate>
</ListBox>

The ListBox shows:

nothing at all!!!

Thanks in advance, the resources I've already checked that have somewhat helped me but not completely are: DataContext, DataTemplate and many MSDN articles.

Community
  • 1
  • 1
Edd
  • 1,948
  • 4
  • 21
  • 29
  • 2
    are you sure all the `property1`, `property2`, ... are ***actually*** properties (with a getter and a setter)? Anyway the issue is related to binding here, so try viewing the ***Output*** window to see if there is any error notified there. – King King Nov 08 '14 at 13:37
  • You, sir, saved my life and made my day. Thank you very much. I feel really dumb, though. – Edd Nov 08 '14 at 13:50

0 Answers0