Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public sealed partial class VotePage : Page
- {
- public VotePage()
- {
- this.InitializeComponent();
- // This will call the OnLoaded function
- this.Loaded += OnLoaded;
- }
- public async void OnLoaded(object sender, RoutedEventArgs e)
- {
- var response = await start();
- dynamic dynJson = JsonConvert.DeserializeObject(response);
- foreach (var item in dynJson)
- {
- Object votedGame = localSettings.Values[item.slug.ToString()];
- string voted = "Collapsed";
- string btnVoted = "VOTE";
- bool btnEnabled = true;
- if(votedGame != null)
- {
- voted = "Visible";
- btnVoted = "VOTED!";
- btnEnabled = false;
- }
- listofGames.Add(new Games { Title = item.name, Votes = item.votes, Slug = item.slug, Voted = voted, BtnVoted = btnVoted, BtnEnabled = btnEnabled });
- }
- gamesList.ItemsSource = listofGames;
- }
- public class GamesList
- {
- public List<Game> Games { get; set; }
- public String Name { get; set; }
- public GamesList(String databaseName)
- {
- Name = databaseName;
- // This won't work because there is no await.
- Games = DataService.GetGames;
- }
- public async Task<List<Game>> GetGames()
- {
- Debug.WriteLine("GET for games.");
- var response = await start();
- dynamic dynJson = JsonConvert.DeserializeObject(response);
- foreach (var item in dynJson)
- {
- Object votedGame = localSettings.Values[item.slug.ToString()];
- string voted = "Collapsed";
- string btnVoted = "VOTE";
- bool btnEnabled = true;
- if (votedGame != null)
- {
- voted = "Visible";
- btnVoted = "VOTED!";
- btnEnabled = false;
- }
- listofGames.Add(new Game { Title = item.name, Votes = item.votes, Slug = item.slug, Voted = voted, BtnVoted = btnVoted, BtnEnabled = btnEnabled });
- }
- return new List<Game>();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement