From 957999cce5adffbfa14314999880b7773f656571 Mon Sep 17 00:00:00 2001 From: Lucas Evard Date: Sun, 15 Oct 2023 00:29:57 +0200 Subject: [PATCH] =?UTF-8?q?:sparkles:=20s=C3=A9lection=20d'un=20livre=20et?= =?UTF-8?q?=20la=20navigation=20vers=20la=20page=20BookPage=20+=20binding?= =?UTF-8?q?=20principal?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sources/MyToolkitMVVM/ObservableObject.cs | 3 ++ .../PocketBook/Applicative_VM/NavigatorVM.cs | 5 -- .../PocketBook/Applicative_VM/TousPageVM.cs | 33 ++++++++++++ sources/PocketBook/MauiProgram.cs | 5 +- sources/PocketBook/Pages/BookDetail.xaml | 18 +++---- sources/PocketBook/Pages/BookDetail.xaml.cs | 13 +++-- .../ContentView/ContentViewBook.xaml | 3 -- sources/PocketBook/Pages/TousPage.xaml | 11 ++-- sources/PocketBook/Pages/TousPage.xaml.cs | 11 ++-- .../PocketBook/Resources/Styles/Colors.xaml | 4 ++ .../PocketBook/Resources/Styles/Styles.xaml | 19 +++++++ sources/ViewModel/BookVM.cs | 51 ++++++++++++++++--- sources/ViewModel/ManagerVM.cs | 19 ++++++- 13 files changed, 149 insertions(+), 46 deletions(-) create mode 100644 sources/PocketBook/Applicative_VM/TousPageVM.cs diff --git a/sources/MyToolkitMVVM/ObservableObject.cs b/sources/MyToolkitMVVM/ObservableObject.cs index 8799abb..5be73e1 100644 --- a/sources/MyToolkitMVVM/ObservableObject.cs +++ b/sources/MyToolkitMVVM/ObservableObject.cs @@ -1,4 +1,5 @@ using System.ComponentModel; +using System.Diagnostics; using System.Runtime.CompilerServices; namespace MyToolkitMVVM; @@ -17,11 +18,13 @@ public class ObservableObject : INotifyPropertyChanged if (EqualityComparer.Default.Equals(member, value)) return; member = value; OnPropertyChanged(propertyName); + Debug.WriteLine("PropertyChanged "+propertyName); } protected void SetProperty(T member, T value,Action action, [CallerMemberName] string propertyName = null) { if (EqualityComparer.Default.Equals(member, value)) return; action(value); OnPropertyChanged(propertyName); + Debug.WriteLine("PropertyChanged " + propertyName); } } diff --git a/sources/PocketBook/Applicative_VM/NavigatorVM.cs b/sources/PocketBook/Applicative_VM/NavigatorVM.cs index 42dceee..2e9eb9f 100644 --- a/sources/PocketBook/Applicative_VM/NavigatorVM.cs +++ b/sources/PocketBook/Applicative_VM/NavigatorVM.cs @@ -8,17 +8,12 @@ namespace PocketBook.Applicative_VM public class NavigatorVM { public ICommand Navigateto { get; private set; } - public ICommand SeeDetailPage { get; private set; } public NavigatorVM() { Navigateto = new Command( async (string page) => await Shell.Current.GoToAsync(page) ); - - SeeDetailPage = new Command( - async () => await Shell.Current.GoToAsync("BookDetail") - ); } } } diff --git a/sources/PocketBook/Applicative_VM/TousPageVM.cs b/sources/PocketBook/Applicative_VM/TousPageVM.cs new file mode 100644 index 0000000..7e110f4 --- /dev/null +++ b/sources/PocketBook/Applicative_VM/TousPageVM.cs @@ -0,0 +1,33 @@ +using System; +using System.Diagnostics; +using System.Windows.Input; +using MyToolkitMVVM; +using ViewModel; + +namespace PocketBook.Applicative_VM +{ + public class TousPageVM : BaseViewModel + { + public ICommand NavigateDetailPage { get; private set; } + + public NavigatorVM NavigateCommandBooks { get; private set; } + public ScanMenuVM ScanMenuVM { get; private set; } + public ManagerVM Manager { get; private set; } + + public TousPageVM(NavigatorVM navigation,ManagerVM manager, ScanMenuVM scanMenuVM) + { + ScanMenuVM = scanMenuVM; + Manager = manager; + NavigateCommandBooks = navigation; + + NavigateDetailPage = new Command(book => + { + Debug.WriteLine(book.Id); + Manager.LoadBookFromManager(book.Id); + Debug.WriteLine(Manager.SelectedBook.Title); + NavigateCommandBooks.Navigateto.Execute("BookDetail"); + }); + } + } +} + diff --git a/sources/PocketBook/MauiProgram.cs b/sources/PocketBook/MauiProgram.cs index 268316d..455e933 100644 --- a/sources/PocketBook/MauiProgram.cs +++ b/sources/PocketBook/MauiProgram.cs @@ -42,10 +42,11 @@ public static class MauiProgram }); builder.Services - .AddSingleton() - .AddSingleton() + .AddSingleton() + .AddSingleton() .AddSingleton() .AddSingleton() + .AddSingleton() .AddSingleton() .AddSingleton() .AddSingleton() diff --git a/sources/PocketBook/Pages/BookDetail.xaml b/sources/PocketBook/Pages/BookDetail.xaml index 85b0e30..8c02c9e 100644 --- a/sources/PocketBook/Pages/BookDetail.xaml +++ b/sources/PocketBook/Pages/BookDetail.xaml @@ -6,14 +6,14 @@ Title="Détails du livre" Shell.ForegroundColor="{StaticResource Primary}" Shell.BackgroundColor="{StaticResource TopBackgroundGrey}" - xmlns:toolkit="http://schemas.microsoft.com/dotnet/2022/maui/toolkit"> + x:Name="root"> - + - @@ -26,12 +26,12 @@ @@ -44,21 +44,21 @@