public partial class MainPage : PhoneApplicationPage { private List<devotion> devotions; // Constructor public MainPage() { InitializeComponent(); // Sample code to localize the ApplicationBar //BuildLocalizedApplicationBar(); // as this will be expensive to populate // you only want to do it once when the app starts devotions = new List<devotion>(); AddDevotions(); } protected override void OnNavigatedTo(NavigationEventArgs e) { DateTime dt = DateTime.Now; int month = dt.Month; int year = dt.Year; int index; if (DateTime.IsLeapYear(year) || (month <= 2)) { index = dt.DayOfYear - 1; // list is indexed from 0 } else { index = dt.DayOfYear; // add a day } textblock.Text = devotions[index].Message; // or some other property } private void AddDevotions() { for (int i = 1; i <= 366; i++) { string filePath = "MyDevotions/Devotions" + i.ToString() + ".json"; Devotion d = ReadJsonFile(filePath); devotions.Add(d); } } public Devotion ReadJsonFile(string JsonfilePath) { Devotion d = null; using (StreamReader r = new StreamReader(JsonfilePath)) { string json = r.ReadToEnd(); d = JsonConvert.DeserializeObject<devotion>(json); } return d; }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)