Creating the ViewModel
Create a MenuViewModel class in the ViewModels folder in the MvxFormsMasterDetailDemo.Core project. Replace the content with the following code:
1
using System.Collections.ObjectModel;
2
using MvvmCross.Navigation;
3
using MvvmCross.ViewModels;
4
5
namespace MvxFormsMasterDetailDemo.Core.ViewModels
6
{
7
public class MenuViewModel : MvxViewModel
8
{
9
readonly IMvxNavigationService _navigationService;
10
11
public MenuViewModel(IMvxNavigationService navigationService)
12
{
13
_navigationService = navigationService;
14
MenuItemList = new MvxObservableCollection<string>()
15
{
16
"Contacts",
17
"Todo"
18
};
19
}
20
21
#region MenuItemList;
22
private ObservableCollection<string> _menuItemList;
23
public ObservableCollection<string> MenuItemList
24
{
25
get => _menuItemList;
26
set => SetProperty(ref _menuItemList, value);
27
}
28
#endregion
29
}
30
}
Copied!
It has a MenuItemList property to store some menu items. For the simplicity, there are only two strings: Contacts and Todo. We also need to inject the instance of IMvxNavigationService in the constructor.
Last modified 2yr ago
Copy link