jimmy
jimmy

Reputation: 15

check if data is already loaded in windows phone app

I am coding for a basic windows phone app. First time when the application is getting launched, data is getting loaded properly in listbox. Now after clicking on any item in list box, I am navigating to another page. But when I press back button to come back to main page. a new set of similar data is getting appended to list box items. how do I check whether data was already loaded or not.

InitializeComponent();

this.Loaded += new RoutedEventHandler(MainPage_Loaded);

In my call back MainPage_Loaded I am binding my data.

Upvotes: 0

Views: 392

Answers (1)

Igor Ralic
Igor Ralic

Reputation: 15006

You should see how navigation works in Windows Phone. When you go back, the Loaded event gets raised every tmie.

The constructor, however, gets called only when the page is created the first time. When you go back, you actually don't call the constructor again, the page is cached. So, in order to stop the data from loading again, you might want to try loading it in the constructor. That's the simplest way.

The other way includes some form of a bool flag which keeps track of that.

Upvotes: 2

Related Questions