You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
PocketBook/Sources/BookApp/ViewModel/ViewModelNavigation.cs

54 lines
1.5 KiB

using ToolKit;
using System.Windows.Input;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Diagnostics;
namespace BookApp.ViewModel
{
public class ViewModelNavigation : BaseViewModel
{
private ViewModelMenuItem _selectedItem;
public ViewModelMenuItem SelectedItem
{
get { return _selectedItem; }
set { SetProperty(ref _selectedItem, value); }
}
public ICommand ItemSelectedCommand { get; private set; }
public ViewModelNavigation()
{
ItemSelectedCommand = new Command(async () => await OnItemSelected(SelectedItem));
}
private async Task OnItemSelected(ViewModelMenuItem selectedItem)
{
SelectedItem = selectedItem;
if (string.IsNullOrEmpty(SelectedItem?.Route))
return;
try
{
await Shell.Current.GoToAsync(selectedItem.Route);
selectedItem = null;
}
catch (Exception ex)
{
Debug.WriteLine($"Navigation failed: {ex.Message}");
}
}
async void ButtonTous(object sender, EventArgs args)
{
await Shell.Current.GoToAsync("TousPage");
}
async void ButtonAuteur(object sender, EventArgs args)
{
await Shell.Current.GoToAsync("FiltragePage");
}
}
}