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.
ConsEco/Code/IHM/Navigator.cs

96 lines
3.6 KiB

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<string, Func<UserControl>> WindowPart { get; private set; }
Dictionary<string, Func<UserControl>> windowPart { get; set; } = new Dictionary<string, Func<UserControl>>
{
[PART_COMPTE] = () => new UCCompte(),
[PART_OPERATION] = () => new UCOperation(),
[PART_ECHEANCIER] = () => new UCEcheancier(),
[PART_PLANNIFICATION] = () => new UCPlannification(),
};
public ReadOnlyDictionary<string, Func<UserControl>> WindowPartMain { get; private set; }
Dictionary<string, Func<UserControl>> windowPartMain { get; set; } = new Dictionary<string, Func<UserControl>>
{
[PART_CONNEXION] = () => new UCConnexion(),
[PART_INSCRIPTION] = () => new UCInscription(),
[PART_MODIFSOLDE] = () => new UCModifSolde(),
};
public ReadOnlyDictionary<string, Func<UserControl>> WindowMain { get; private set; }
Dictionary<string, Func<UserControl>> windowMain { get; set; } = new Dictionary<string, Func<UserControl>>
{
[PART_MAIN] = () => new UCBienvenue(),
};
public Navigator()
{
WindowPart = new ReadOnlyDictionary<string, Func<UserControl>>(windowPart);
WindowMain = new ReadOnlyDictionary<string, Func<UserControl>>(windowMain);
WindowPartMain = new ReadOnlyDictionary<string, Func<UserControl>>(windowPartMain);
SelectedUserControlCreator = windowMain.First();
}
public KeyValuePair<string, Func<UserControl>> SelectedUserControlCreator
{
get => selectedUserControlCreator;
set
{
if (selectedUserControlCreator.Equals(value)) return;
selectedUserControlCreator = value;
OnPropertyChanged();
}
}
private KeyValuePair<string, Func<UserControl>> 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);
}
}
}
}