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.