ADD : Use Command for OnSelectionChanged in TousView

commands-19-09
Lou BRODA 1 year ago
parent 47176188dd
commit cdd4a4aa86

@ -39,7 +39,8 @@
<CollectionView ItemsSource="{Binding TousVM.Manager.AllBooks}"
SelectedItem="{Binding TousVM.Manager.SelectedBook}"
SelectionMode="Single"
SelectionChanged="OnSelectionChanged"
SelectionChangedCommand="{Binding TousVM.OnSelectionChangedCommand}"
SelectionChangedCommandParameter="{Binding TousVM.Manager.SelectedBook}"
Grid.Row="2">
<CollectionView.GroupHeaderTemplate>
<DataTemplate x:DataType="viewModel:BookVM">

@ -26,14 +26,5 @@ public partial class TousView : ContentPage
#region Methods
void OnSelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (e.CurrentSelection.FirstOrDefault() is BookVM)
{
var result = new DetailsLivreVM(TousVM.Manager, TousVM.Navigator, e.CurrentSelection.FirstOrDefault() as BookVM);
App.Current.MainPage.Navigation.PushAsync(new DetailsLivreView(result));
}
}
#endregion
}

@ -1,9 +1,11 @@
using PersonalMVVMToolkit;
using LivreLand.View;
using PersonalMVVMToolkit;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;
using ViewModels;
namespace LivreLand.ViewModel
@ -16,6 +18,7 @@ namespace LivreLand.ViewModel
public ManagerVM Manager { get; private set; }
public ICommand OnSelectionChangedCommand { get; private set; }
#endregion
#region Constructor
@ -24,6 +27,17 @@ namespace LivreLand.ViewModel
{
Navigator = navigatorVM;
Manager = managerVM;
OnSelectionChangedCommand = new RelayCommand<BookVM>((bookVM) => OnSelectionChanged(bookVM));
}
#endregion
#region Methods
private void OnSelectionChanged(BookVM bookVM)
{
var result = new DetailsLivreVM(Manager, Navigator, bookVM);
App.Current.MainPage.Navigation.PushAsync(new DetailsLivreView(result));
}
#endregion

@ -27,6 +27,7 @@ namespace ViewModels
private int index;
private long nbBooks;
private BookVM selectedBook;
private AuthorVM selectedAuthor;
private PublishDateVM selectedDate;
private RatingsVM selectedRating;
@ -99,7 +100,18 @@ namespace ViewModels
get => status;
}
public BookVM SelectedBook { get; set; }
public BookVM SelectedBook
{
get { return selectedBook; }
set
{
if (selectedBook != value)
{
selectedBook = value;
OnPropertyChanged(nameof(SelectedBook));
}
}
}
public AuthorVM SelectedAuthor
{

Loading…
Cancel
Save