Reputation: 161
I have a listview with itemsource="{Binding}" in the MainPage. and with this code i fill it.
viewContacts.ItemsSource = null;
viewContacts.ItemsSource = itemsList;
itemsList is a ObservableCollection and that works.
I also have a functon if i press on a item to Navigate to another page.
private void viewContacts_ItemClick(object sender, ItemClickEventArgs e)
{
var clickedcontact = e.ClickedItem as contact;
this.Frame.Navigate(typeof(contactdetails), clickedcontact);
}
contactdetails is a DetailPage.
if I go back with this code to the DetailPage.
private void App_BackRequested(object sender, BackRequestedEventArgs e)
{
if (Frame.CanGoBack)
{
Frame.GoBack();
e.Handled = true;
}
}
My list is empty and I have to press search another one to find contacts.
Back at WP8.1 my list wasn't empty and got filled with the results from before.
Windows Universal App 10, VS 2015, C#, XAML
Upvotes: 1
Views: 234
Reputation: 2790
You need to set the NavigationCache to required so it keeps the input. Take a look at this msdn page: Page.NavigationCacheMode
So the page doesn't need to reload all the stuff.
Upvotes: 0
Reputation: 3998
first if you do viewContacts.ItemsSource = itemsList;
there is no need to do itemsource="{Binding}
.
Second, do you do any LoadState or SaveState when you leave the page or do you save your data at OnNavigatedFrom or load them OnNavigatedTo??
For you data to continue to exist you must save them somewhere. The easiest and fastest way is to keep them in static like:
public static ObservableCollection<MyClass> itemsList = new ObservableCollection<MyClass>();
Upvotes: 2