using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.ComponentModel; using System.Linq; using System.Runtime.CompilerServices; using System.Text; using System.Threading.Tasks; using System.Windows.Controls; namespace IHM { public class Navigator : INotifyPropertyChanged { public const string PART_COMPTE = "Compte"; public const string PART_OPERATION = "Opération"; public const string PART_ECHEANCIER = "Echéancier"; public const string PART_PLANNIFICATION = "Plannification"; public const string PART_MAIN = "Main"; public const string PART_CONNEXION = "Connexion"; public const string PART_INSCRIPTION = "Inscription"; public const string PART_MODIFSOLDE = "ModifSolde"; public ReadOnlyDictionary> WindowPart { get; private set; } Dictionary> windowPart { get; set; } = new Dictionary> { [PART_COMPTE] = () => new UCCompte(), [PART_OPERATION] = () => new UCOperation(), [PART_ECHEANCIER] = () => new UCEcheancier(), [PART_PLANNIFICATION] = () => new UCPlannification(), }; public ReadOnlyDictionary> WindowPartMain { get; private set; } Dictionary> windowPartMain { get; set; } = new Dictionary> { [PART_CONNEXION] = () => new UCConnexion(), [PART_INSCRIPTION] = () => new UCInscription(), [PART_MODIFSOLDE] = () => new UCModifSolde(), }; public ReadOnlyDictionary> WindowMain { get; private set; } Dictionary> windowMain { get; set; } = new Dictionary> { [PART_MAIN] = () => new UCBienvenue(), }; public Navigator() { WindowPart = new ReadOnlyDictionary>(windowPart); WindowMain = new ReadOnlyDictionary>(windowMain); WindowPartMain = new ReadOnlyDictionary>(windowPartMain); SelectedUserControlCreator = windowMain.First(); } public KeyValuePair> SelectedUserControlCreator { get => selectedUserControlCreator; set { if (selectedUserControlCreator.Equals(value)) return; selectedUserControlCreator = value; OnPropertyChanged(); } } private KeyValuePair> selectedUserControlCreator; public event PropertyChangedEventHandler? PropertyChanged; void OnPropertyChanged([CallerMemberName] string propertyName = "") => PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); public void NavigateTo(string windowPartName) { if (WindowPart.ContainsKey(windowPartName)) { SelectedUserControlCreator = WindowPart.Single(kvp => kvp.Key == windowPartName); } if (WindowPartMain.ContainsKey(windowPartName)) { SelectedUserControlCreator = WindowPartMain.Single(kvp => kvp.Key == windowPartName); } if (WindowMain.ContainsKey(windowPartName)) { SelectedUserControlCreator = WindowMain.Single(kvp => kvp.Key == windowPartName); } } } }