//Former constructor. /*public App () * { * InitializeComponent(); * * MainPage = new NavigationPage(new MainPage()); * }*/ /// <summary> /// Initializes a new instance of the App Class /// </summary> /// <param name="path"></param> public App(string path) { InitializeComponent(); //Gets the database path send from BooksMVVM.Android.MainActivity.cs DB_PATH = path; //Instansiates the different viewmodels and pages. MainDAL dal = new MainDAL(); IAddProductPageViewModel addProductPageViewModel = new AddProductPageViewModel(dal); AddProductPage addproductPage = new AddProductPage(addProductPageViewModel); IMakeListPageViewModel makeListPageViewModel = new MakeListPageViewModel(dal); MakeListPage makeListPage = new MakeListPage(makeListPageViewModel); //Not sure if this violates MVVM, but it needs them to navigate between pages. //One way to fix this could maybe be to simple have to codebehind handle the navigation //but I am not sure if it violates MVVM. IMainPageViewModel mainPageViewModel = new MainPageViewModel(addproductPage, makeListPage, dal); MainPage mainPage = new MainPage(mainPageViewModel); NavigationPage navigationPage = new NavigationPage(mainPage) { BarBackgroundColor = Color.FromHex("#2199e8"), BarTextColor = Color.White }; MainPage = navigationPage; }
/// <summary> /// Initializes a new instance of the MainPageViewModel class. /// </summary> /// <param name="addBookPage"></param> /// <param name="makeListPage"></param> public MainPageViewModel(AddProductPage addProductPage, MakeListPage makeListPage, MainDAL dal) { this.addProductPage = addProductPage; this.makeListPage = makeListPage; DAL = dal; //Creates the commands bound to from the view. ToolbarItem_ADD_Command = new Command(ToolbarItem_ADD_Command_Execute); ToolbarItem_FILL_Command = new Command(ToolbarItem_FILL_Command_Execute); ClearBtn_Command = new Command(ClearBtn_Command_Execute, ClearBtn_Command_CanExecute); DeleteModeBtn_Command = new Command(DeleteModeBtn_Command_Execute, DeleteModeBtn_Command_CanExecute); }