123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Net;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Documents;
- using System.Windows.Input;
- using System.Windows.Media;
- using System.Windows.Media.Animation;
- using System.Windows.Shapes;
- using Microsoft.Phone.Controls;
- using Microsoft.Phone.Shell;
- using VocabManager.View;
- using VocabManager.ViewModel;
- namespace VocabManager
- {
- public partial class MainPage : PhoneApplicationPage
- {
-
- internal ApplicationBarIconButton _addNewButton;
- internal ApplicationBarIconButton _deleteCurrentButton;
- internal ApplicationBarIconButton _editButton;
- internal ApplicationBarIconButton _selectButton;
- //one time views which are created just one time, stored and used
- AppListView _deckListView;
- AppListViewModel _viewModel;
- WelcomeView _welcomeView;
- HelpView _helpView;
- AboutView _aboutView;
-
- public MainPage()
- {
- InitializeComponent();
- InitApplicationButtons();
- LoadWelcomeView();
- }
- //// initialize the application buttons (ones are shared)
- private void InitApplicationButtons()
- {
- _addNewButton = new ApplicationBarIconButton(new Uri(IconUrls.Add, UriKind.Relative));
- _addNewButton.Text = "add a new deck";
- _addNewButton.Click += new EventHandler(_addNewButton_Click);
- _deleteCurrentButton = new ApplicationBarIconButton(new Uri(IconUrls.Delete, UriKind.Relative));
- _deleteCurrentButton.Click += new EventHandler(_deleteCurrent_Click);
- _deleteCurrentButton.Text = "delect selcted deck";
-
- _editButton = new ApplicationBarIconButton(new Uri(IconUrls.Edit, UriKind.Relative));
- _editButton.Click += new EventHandler(_editButton_Click);
- _editButton.Text = "edit deck";
-
- _selectButton = new ApplicationBarIconButton(new Uri(IconUrls.Select, UriKind.Relative));
- _selectButton.Text = "review deck";
- _selectButton.Click += new EventHandler(_selectButton_Click);
-
- this.ApplicationBar.Buttons.Add(_addNewButton);
- this.ApplicationBar.Buttons.Add(_selectButton);
- this.ApplicationBar.Buttons.Add(_editButton);
- this.ApplicationBar.Buttons.Add(_deleteCurrentButton);
- }
- void mnu_Click(object sender, EventArgs e)
- {
- LoadWelcomeView();
- }
- void _selectButton_Click(object sender, EventArgs e)
- {
- _viewModel.ViewSelectedDeckCommand.Execute(null);
- }
- void _editButton_Click(object sender, EventArgs e)
- {
- if (_viewModel.CurrentDeck != null)
- _viewModel.CurrentDeck.EditCommand.Execute(null);
- }
- void _deleteCurrent_Click(object sender, EventArgs e)
- {
- if (_viewModel.CurrentDeck != null)
- _viewModel.RemoveCurrentDeckCommand.Execute(null);
- }
- void _addNewButton_Click(object sender, EventArgs e)
- {
- _viewModel.AddNewCommand.Execute(null);
- }
- //The whole application is just one page and each different view is a usercontrol which is hosted in this page
- // based on the need
- public void LoadView( UserControlBase newChild)
- {
- this.LayoutRoot.Children.Clear();
- this.LayoutRoot.Children.Add(newChild);
- }
- public void LoadDeckListView()
- {
- if (_deckListView == null)
- {
- // initialize database and also create AppListViewModel
- this.DataContext = _viewModel = new AppListViewModel(
- new DataLayer.DeckRepository(VocabManager.DataLayer.DatabaseManager.Insatance.DataContext),
- new DataLayer.ItemRepository(VocabManager.DataLayer.DatabaseManager.Insatance.DataContext));
- _deckListView = new AppListView();
- _deckListView.DataContext = _viewModel;
- }
- LoadView(_deckListView);
- }
- public void LoadHelpView()
- {
- if (_helpView == null)
- {
- _helpView = new HelpView();
- }
- LoadView(_helpView);
- }
- public void LoadWelcomeView()
- {
- if (_welcomeView == null)
- {
- _welcomeView = new WelcomeView();
- }
- LoadView(_welcomeView);
- }
- internal void LoadAboutView()
- {
- if (_aboutView == null)
- {
- _aboutView = new AboutView();
- }
- LoadView(_aboutView);
- }
-
-
- }
- }
|