I am using a Static List to store some values, the idea is declare the list, then a button in page 1 adds some values, then a button in page 2 adds some more values, to do this I am triying declare it in each page but the list is newly created:
public static List _songlist = new List(); in each page.
Can you help me?, how I can declare the static list then have the same list with the values in all the pages?
public static List<Song> _songlist = new List<Song>();
public class Song
{
private string _name;
public string name
{
get { return _name; }
set { SetProperty(ref _name, value); }
}
private string _artist;
public string artist
{
get { return _artist; }
set { SetProperty(ref _artist, value); }
}
}
Any help is appreciated.
If I understand you, you want an Application wide static list.
Why not create a new file called ApplicationServices.cs
and put a static class inside of it with a static List<Song>
public static class ApplicationServices{
public static List<Song> Songs {get; set;}
}
This way you can access it everywhere by calling ApplicationServices.Songs
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.