I want to instantiate object of a collection in App.xaml.cs dynamically from MainPage.xaml.cs when required so that I can used the object throughout the app pages. I can manually instantiate and keep for current requirement but after my app is published and requirement increases than I don't know how to get it. Can somebody give me any idea?
Thanks in advance.
In your App.xaml.cs, declare your Collection
public ObservableCollection<Person> personsList = new ObservableCollection<Person>();
Then in your MainPage.xaml.cs, assign the collection values to the collection object
(Application.Current as App).personsList = mypersonsList;
After this, you can access the values from anypage in the app
ObservableCollection<Person> mypersonsList = (Application.Current as App).personsList;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.