Reputation: 3276
net to make a Windows Phone application. I have a listBox on page1 called listBox1 and in page 2 I have a button called btnAdd. I want to be able to add an item into the listbox1 from page1 whenever btnAdd is pressed in page2. I knew how to do this on VB6 but it seems different on vb.Net. Can someone please help? Thanks
Upvotes: 0
Views: 674
Reputation: 302
How about binding the listBox1 to a datasource that is available from both pages (maybe in a separate class) then updating that datasource from the btnAdd click event.
Example:
In Page1 add:
public static List<string> listItems = new List<string>();
In the OnNavigatedTo override add:
listBox1.ItemsSource = null;
listBox1.ItemsSource = listItems;
In Page2 btnAdd_Click handler add:
Page1.listItems.Add(textBox1.Text);
Sorry the above is C# but it shouldn't be difficult to get the VB equivalent.
Using the ViewModel approach and implementing INotifyPropertyChanged would be cleaner and avoid needing to reset the ItemSource in OnNavigatedTo.
Upvotes: 1