On the Internet is difficult to find the simplest case, are a large, looking at all headaches;
Try extrapolate, if the result is assigned to DataContext this property, then the foreground needs to bind itemssource= "{Binding}", please note. The direct assignment to the ITEMSSOURC is not bound;
Background code:
list<string> list =Newlist<string>(); for(inti =0; I < -; i++) {list. ADD ("SAS"+i); } This. MB. DataContext =list; List<string> MB2 =Newlist<string>(); for(inti =0; I < -; i++) {MB2. ADD ("MB2"+i); } This. mb2. ItemsSource = MB2;
Front Code:
<listbox itemssource="{Binding}"X:name="MB"height=" -"> <ListBox.ItemTemplate> <DataTemplate> <label content="{Binding}"></Label> </DataTemplate> </ListBox.ItemTemplate> </LISTBOX>&L T ListBox x:name="MB2"height=" -"> <ListBox.ItemTemplate> <DataTemplate> <label content="{Binding}"></Label> </DataTemplate> </ListBox.ItemTemplate> </ListBox>
The simplest way to bind data to data controls such as a WPF ListBox or ListView