-
Notifications
You must be signed in to change notification settings - Fork 0
/
MainPage.xaml.cs
68 lines (60 loc) · 2.15 KB
/
MainPage.xaml.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
using System;
using System.Net;
using System.Collections.Generic;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using NoppaLib.DataModel;
using NoppaClient.ViewModels;
using System.Threading.Tasks;
using NoppaClient.View;
using NoppaClient.Resources;
namespace NoppaClient
{
public partial class MainPage : PhoneApplicationPage
{
Language _loadedLanguage;
MainViewModel _viewModel;
// Constructor
public MainPage()
{
InitializeComponent();
ReloadDataAsync();
_loadedLanguage = App.Settings.Language;
var searchButton = (ApplicationBarIconButton)ApplicationBar.Buttons[0];
var settingsMenu = (ApplicationBarMenuItem)ApplicationBar.MenuItems[0];
var aboutMenu = (ApplicationBarMenuItem)ApplicationBar.MenuItems[1];
searchButton.Text = AppResources.SearchTitle;
settingsMenu.Text = AppResources.SettingsTitle;
aboutMenu.Text = AppResources.AboutTitle;
AppBar.BindCommand(searchButton, _viewModel.ShowSearchCommand);
AppBar.BindCommand(settingsMenu, _viewModel.ShowSettingsCommand);
AppBar.BindCommand(aboutMenu, _viewModel.ShowAboutCommand);
}
private async void ReloadDataAsync()
{
_viewModel = new MainViewModel(new PhoneNavigationController());
DataContext = _viewModel;
await _viewModel.LoadDataAsync(App.PinnedCourses);
}
// Load data for the ViewModel Items
protected override void OnNavigatedTo(NavigationEventArgs e)
{
try
{
if (_loadedLanguage != App.Settings.Language)
{
ReloadDataAsync();
_loadedLanguage = App.Settings.Language;
}
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine("Couldn't load data: {0}", ex.Message);
}
}
}
}