Introduction:
FreshMVVM:
Kindly refer my previous article on Fresh MVVM to know the basics & rules of Fresh MVVM.
Coding Part:
Steps:
- Creating new Xamarin.Forms Projects.
- Setting up the plugin for Xamarin.Forms Application.
- Implementing Fresh MVVM.
Step 1: Creating new Xamarin.Forms Projects
Then Select Android and iOS Platforms as shown below with Code Sharing Strategy as PCL or .Net Standard and Click OK.
Step 2: Setting up the plugin for Xamarin.Forms Application
Install-Package FreshMvvm -Version 2.2.3
Step 3: Implementing Fresh MVVM.
- Create your XAML page (view) with name ended up with “Page”.
- Create PageModel by create Class name ended with “PageModel” and inherited with “FreshBasePageModel” as shown below screenshot.
- In the same way, I have created two pages “Detail1Page” and “Detail2Page” with two respective page models “Detail1PageModel” and “Detail2PageModel”.
Set MainPage:
To create Fresh MVVM Master Detail Page as MainPage, we should use Fresh Master Detail Navigation Container with the following code. Open App.xaml.cs or App.cs and set MainPage.var masterNavigation = new FreshMasterDetailNavigationContainer();
masterNavigation.Init("Menu");
masterNavigation.AddPage("First Page", null);
masterNavigation.AddPage("Second Page", null);
MainPage = masterNavigation;
- Here, we will not discuss about navigation between pages. If you want to know, you can see my previous article on Fresh MVVM.
Full Code for App.xaml.cs:
You can find the code for App.xaml.cs belowpublic partial class App : Application
{
public App()
{
try
{
InitializeComponent();
var masterNavigation = new FreshMasterDetailNavigationContainer();
masterNavigation.Init("Menu");
masterNavigation.AddPage("First Page", null);
masterNavigation.AddPage("Second Page", null);
MainPage = masterNavigation;
}
catch (Exception ex)
{
}
}
protected override void OnStart()
{
// Handle when your app starts
}
protected override void OnSleep()
{
// Handle when your app sleeps
}
protected override void OnResume()
{
// Handle when your app resumes
}
}
Follow Us
Were this world an endless plain, and by sailing eastward we could for ever reach new distances