I have AItems and BItems, want to bind to AListBox in a PanoramaItem and BListBox in another PanoramamItem.
I specified ItemsSource in each ListBox
<controls:PanoramaItem>
<ListBox ItemsSource="{Binding AItems}" >
...
</ListBox>
</controls:PanoramaItem>
<controls:PanoramaItem
<ListBox ItemsSource="{Binding BItems}" >
...
</ListBox>
</controls:PanoramaItem>
How do I bind the data to each ListBox from code behind?
I have the Constructor method
public MainPage()
{
InitializeComponent();
}
and page load method
private void MainPage_Loaded(object sender, RoutedEventArgs e)
{
}
Thank you.
To bind the collections to controls in code-behind :
1) Give the listboxes names
2) in code behind, set <listboxName>.ItemsSource = <collection>
(You should make sure your collections are ObservableCollection<myType> to ensure that if the collection changes, this is reflected in the view.)
for example...
and then
Then you can call
BindMyControls()
from the most appropriate place, most likely once the collections have been populated.