create layout

This commit is contained in:
Natlinux
2023-02-18 11:57:10 +01:00
parent 7911aa46de
commit 2e994ab805
23 changed files with 201 additions and 136 deletions

View File

@@ -39,12 +39,8 @@ namespace Apollon.WPF
_tournamentStore = new TournamentsStore(_getAllTournamentQuery, _createTournamentCommand, _updateTournamentCommand, _deleteTournamentCommand);
_selectedTournamentStore = new SelectedTournamentsStore(_tournamentStore);
_navBarPreparationViewModel = new NavBarPreparationViewModel(CreateOverviewNavigationService(),
CreateGroupsNavigationService(),
CreateNamelistNavigationService(),
CreateClassesNavigationService(),
CreateArchersNavigationService());
}
_navBarPreparationViewModel = CreateNavbarViewModel();
}
protected override void OnStartup(StartupEventArgs e)
{
@@ -56,11 +52,11 @@ namespace Apollon.WPF
OverviewViewModel overviewViewModel = OverviewViewModel.LoadViewModel(
_selectedTournamentStore,
_modalNavigationStore,
_tournamentStore,
CreateGroupsNavigationService(),
CreateNamelistNavigationService());
_tournamentStore,
CreateNamelistNavigationService(),
CreateGroupsNavigationService());
NavigationService<OverviewViewModel> overvoewNavigationService = CreateOverviewNavigationService();
INavigationService<OverviewViewModel> overvoewNavigationService = CreateOverviewNavigationService();
overvoewNavigationService.Navigate();
MainWindow = new MainWindow()
@@ -72,34 +68,47 @@ namespace Apollon.WPF
base.OnStartup(e);
}
private NavigationService<OverviewViewModel> CreateOverviewNavigationService()
private INavigationService<OverviewViewModel> CreateOverviewNavigationService()
{
return new NavigationService<OverviewViewModel>(
_navigationStore, () => OverviewViewModel.LoadViewModel(_selectedTournamentStore, _modalNavigationStore, _tournamentStore, CreateGroupsNavigationService(), CreateNamelistNavigationService()));
_navigationStore, () => OverviewViewModel.LoadViewModel(_selectedTournamentStore,
_modalNavigationStore,
_tournamentStore,
CreateNamelistNavigationService(),
CreateGroupsNavigationService()));
}
private NavigationService<GroupsViewModel> CreateGroupsNavigationService()
private NavBarPreparationViewModel CreateNavbarViewModel()
{
return new NavigationService<GroupsViewModel>(
_navigationStore, () => new GroupsViewModel(_navBarPreparationViewModel, _selectedTournamentStore, CreateOverviewNavigationService()));
return new NavBarPreparationViewModel(CreateOverviewNavigationService(),
CreateGroupsNavigationService(),
CreateNamelistNavigationService(),
CreateClassesNavigationService(),
CreateArchersNavigationService());
}
private NavigationService<ClassesViewModel> CreateClassesNavigationService()
private INavigationService<GroupsViewModel> CreateGroupsNavigationService()
{
return new NavigationService<ClassesViewModel>(
_navigationStore, ()=> new ClassesViewModel(_navBarPreparationViewModel, _selectedTournamentStore));
return new LayoutNavigationService<GroupsViewModel>(
_navigationStore, () => new GroupsViewModel(CreateOverviewNavigationService()), CreateNavbarViewModel);
}
private NavigationService<NameListViewModel> CreateNamelistNavigationService()
private INavigationService<ClassesViewModel> CreateClassesNavigationService()
{
return new NavigationService<NameListViewModel>(
_navigationStore, () => new NameListViewModel());
return new LayoutNavigationService<ClassesViewModel>(
_navigationStore, ()=> new ClassesViewModel(), CreateNavbarViewModel);
}
private NavigationService<ArchersViewModel> CreateArchersNavigationService()
private INavigationService<NameListViewModel> CreateNamelistNavigationService()
{
return new NavigationService<ArchersViewModel>(
_navigationStore, () => new ArchersViewModel(_navBarPreparationViewModel, _selectedTournamentStore));
return new LayoutNavigationService<NameListViewModel>(
_navigationStore, () => new NameListViewModel(), CreateNavbarViewModel);
}
private INavigationService<ArchersViewModel> CreateArchersNavigationService()
{
return new LayoutNavigationService<ArchersViewModel>(
_navigationStore, () => new ArchersViewModel(), CreateNavbarViewModel);
}
}
}

View File

@@ -12,15 +12,14 @@ namespace Apollon.WPF.Commands
private readonly TournamentsStore _tournamentStore;
private readonly ModalNavigationStore _modalNavigationStore;
private AddTournamentViewModel _addTournamentViewModel;
private readonly NavigationService<GroupsViewModel> _navigationService;
public AddTournamentCommand(AddTournamentViewModel addTournamentViewModel, TournamentsStore tournamentStore, ModalNavigationStore modalNavigationStore, NavigationService<GroupsViewModel> navigationService)
public AddTournamentCommand(AddTournamentViewModel addTournamentViewModel, TournamentsStore tournamentStore, ModalNavigationStore modalNavigationStore)
{
_addTournamentViewModel = addTournamentViewModel;
_tournamentStore = tournamentStore;
_modalNavigationStore = modalNavigationStore;
_navigationService = navigationService;
_modalNavigationStore = modalNavigationStore;
}
public override async Task ExecuteAsync(object parameter)
@@ -48,7 +47,7 @@ namespace Apollon.WPF.Commands
await _tournamentStore.Add(tournament);
_modalNavigationStore.Close();
_navigationService.Navigate();
}
catch (Exception)
{

View File

@@ -12,9 +12,9 @@ namespace Apollon.WPF.Commands
public class NavigateCommand<TViewModel> : CommandBase
where TViewModel : ViewModelBase
{
private readonly NavigationService<TViewModel> _navigationService;
private readonly INavigationService<TViewModel> _navigationService;
public NavigateCommand(NavigationService<TViewModel> navigationService)
public NavigateCommand(INavigationService<TViewModel> navigationService)
{
_navigationService = navigationService;
}

View File

@@ -12,19 +12,18 @@ namespace Apollon.WPF.Commands
public class OpenAddTournamentCommand : CommandBase
{
private readonly TournamentsStore _tournamentStore;
private readonly ModalNavigationStore _modalNavigationStore;
private readonly NavigationService<GroupsViewModel> _navigationService;
private readonly ModalNavigationStore _modalNavigationStore;
public OpenAddTournamentCommand(TournamentsStore tournamentStore, ModalNavigationStore modalNavigationStore, NavigationService<GroupsViewModel> navigationService)
public OpenAddTournamentCommand(TournamentsStore tournamentStore, ModalNavigationStore modalNavigationStore)
{
_tournamentStore = tournamentStore;
_modalNavigationStore = modalNavigationStore;
_navigationService = navigationService;
;
}
public override void Execute(object parameter)
{
AddTournamentViewModel addTournamentViewModel = new AddTournamentViewModel(_tournamentStore, _modalNavigationStore, _navigationService);
AddTournamentViewModel addTournamentViewModel = new AddTournamentViewModel(_tournamentStore, _modalNavigationStore);
_modalNavigationStore.CurrentViewModel = addTournamentViewModel;
}
}

View File

@@ -54,6 +54,9 @@
<DataTemplate DataType="{x:Type vms:OverviewViewModel}">
<views:OverviewView/>
</DataTemplate>
<DataTemplate DataType="{x:Type vms:LayoutViewModel}">
<components:Layout/>
</DataTemplate>
<DataTemplate DataType="{x:Type vms:GroupsViewModel}">
<views:GroupsView/>
</DataTemplate>

View File

@@ -0,0 +1,9 @@
using Apollon.WPF.ViewModels;
namespace Apollon.WPF.Services
{
public interface INavigationService<TViewModel> where TViewModel : ViewModelBase
{
void Navigate();
}
}

View File

@@ -0,0 +1,29 @@
using Apollon.WPF.Stores;
using Apollon.WPF.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Apollon.WPF.Services
{
public class LayoutNavigationService<TViewModel> : INavigationService<TViewModel> where TViewModel : ViewModelBase
{
private readonly NavigationStore _navigationStore;
private readonly Func<TViewModel> _createViewModel;
private readonly Func<NavBarPreparationViewModel> _createNavBarPreparationViewModel;
public LayoutNavigationService(NavigationStore navigationStore, Func<TViewModel> createViewModel, Func<NavBarPreparationViewModel> createNavBarPreparationViewModel)
{
_navigationStore = navigationStore;
_createViewModel = createViewModel;
_createNavBarPreparationViewModel = createNavBarPreparationViewModel;
}
public void Navigate()
{
_navigationStore.CurrentViewModel = new LayoutViewModel(_createNavBarPreparationViewModel(), _createViewModel());
}
}
}

View File

@@ -8,8 +8,7 @@ using System.Threading.Tasks;
namespace Apollon.WPF.Services
{
public class NavigationService<TViewModel>
where TViewModel : ViewModelBase
public class NavigationService<TViewModel> : INavigationService<TViewModel> where TViewModel : ViewModelBase
{
private readonly NavigationStore _navigationStore;
private readonly Func<TViewModel> _createViewModel;

View File

@@ -14,9 +14,9 @@ namespace Apollon.WPF.ViewModels
{
public AddEditDetailsViewModel AddEditDetailsViewModel { get; }
public AddTournamentViewModel(TournamentsStore tournamentStore, ModalNavigationStore modalNavigationStore, NavigationService<GroupsViewModel> navigationService)
public AddTournamentViewModel(TournamentsStore tournamentStore, ModalNavigationStore modalNavigationStore)
{
ICommand submitCommand = new AddTournamentCommand(this, tournamentStore,modalNavigationStore, navigationService);
ICommand submitCommand = new AddTournamentCommand(this, tournamentStore,modalNavigationStore);
ICommand cancelCommand = new CloseModalCommand(modalNavigationStore);
AddEditDetailsViewModel = new AddEditDetailsViewModel(submitCommand, cancelCommand);
}

View File

@@ -9,13 +9,6 @@ namespace Apollon.WPF.ViewModels
{
public class ArchersViewModel : ViewModelBase
{
public TournamentDetailsViewModel TournamentDetailsViewModel { get; }
public NavBarPreparationViewModel NavBarPreparationViewModel { get; }
public ArchersViewModel(NavBarPreparationViewModel navBarPreparationViewModel, SelectedTournamentsStore selectedTournamentsStore)
{
TournamentDetailsViewModel = new TournamentDetailsViewModel(selectedTournamentsStore);
NavBarPreparationViewModel = navBarPreparationViewModel;
}
}
}

View File

@@ -9,13 +9,6 @@ namespace Apollon.WPF.ViewModels
{
public class ClassesViewModel : ViewModelBase
{
public TournamentDetailsViewModel TournamentDetailsViewModel { get; }
public NavBarPreparationViewModel NavBarPreparationViewModel { get; }
public ClassesViewModel(NavBarPreparationViewModel navBarPreparationViewModel, SelectedTournamentsStore selectedTournamentsStore)
{
TournamentDetailsViewModel = new TournamentDetailsViewModel(selectedTournamentsStore);
NavBarPreparationViewModel = navBarPreparationViewModel;
}
}
}

View File

@@ -12,19 +12,12 @@ using System.Windows.Input;
namespace Apollon.WPF.ViewModels
{
public class GroupsViewModel : ViewModelBase
{
public TournamentDetailsViewModel TournamentDetailsViewModel { get; }
public NavBarPreparationViewModel NavBarPreparationViewModel { get; }
{
public ICommand NavigateOverviewCommand { get; }
public GroupsViewModel(NavBarPreparationViewModel navBarPreparationViewModel, SelectedTournamentsStore selectedTournamentStore, NavigationService<OverviewViewModel> overviewNavigationService)
{
TournamentDetailsViewModel = new TournamentDetailsViewModel(selectedTournamentStore);
NavBarPreparationViewModel = navBarPreparationViewModel;
NavigateOverviewCommand = new NavigateCommand<OverviewViewModel>(overviewNavigationService);
public GroupsViewModel(INavigationService<OverviewViewModel> overviewNavigationService)
{
//NavigateOverviewCommand = new NavigateCommand<OverviewViewModel>(overviewNavigationService);
}
}
}

View File

@@ -0,0 +1,20 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Apollon.WPF.ViewModels
{
public class LayoutViewModel : ViewModelBase
{
public LayoutViewModel(NavBarPreparationViewModel navBarPreparationViewModel, ViewModelBase contentVieModel)
{
NavBarPreparationViewModel = navBarPreparationViewModel;
ContentVieModel = contentVieModel;
}
public NavBarPreparationViewModel NavBarPreparationViewModel { get;}
public ViewModelBase ContentVieModel { get;}
}
}

View File

@@ -17,11 +17,11 @@ namespace Apollon.WPF.ViewModels
public ICommand NavigateNamelistCommand { get;}
public ICommand NavigateArchersCommand { get;}
public NavBarPreparationViewModel(NavigationService<OverviewViewModel> overviewNavigationService,
NavigationService<GroupsViewModel> groupNavigationService,
NavigationService<NameListViewModel> namelistNavigationService,
NavigationService<ClassesViewModel> classNavigationService,
NavigationService<ArchersViewModel> archersNavigationService)
public NavBarPreparationViewModel(INavigationService<OverviewViewModel> overviewNavigationService,
INavigationService<GroupsViewModel> groupNavigationService,
INavigationService<NameListViewModel> namelistNavigationService,
INavigationService<ClassesViewModel> classNavigationService,
INavigationService<ArchersViewModel> archersNavigationService)
{
NavigateOverviewCommand = new NavigateCommand<OverviewViewModel>(overviewNavigationService);
NavigateGroupsCommand = new NavigateCommand<GroupsViewModel>(groupNavigationService);

View File

@@ -24,15 +24,17 @@ namespace Apollon.WPF.ViewModels
public int Targets => SelectedTournament?.Targets ?? 0;
public ICommand NavigatePreparationCommand { get; }
public SelectedTournamentsStore SelectedTournamentStore { get; }
public OverviewDetailsViewModel(SelectedTournamentsStore selectedTournamentStore, NavigationService<GroupsViewModel> groupNavigationService)
public OverviewDetailsViewModel(SelectedTournamentsStore selectedTournamentStore, INavigationService<GroupsViewModel> groupNavigationService)
{
_selectedTournamentStore = selectedTournamentStore;
_selectedTournamentStore.SelectedTournamentChanged += SelectedTournamentStore_SelectedTournamentChanged;
NavigatePreparationCommand = new NavigateCommand<GroupsViewModel>(groupNavigationService);
}
}
protected override void Dispose()
{

View File

@@ -46,24 +46,24 @@ namespace Apollon.WPF.ViewModels
public ICommand NavigateNameListCommand { get; }
public OverviewViewModel(TournamentsStore tournamentStore, SelectedTournamentsStore selectedTournamentStore,
ModalNavigationStore modalNavigationStore, NavigationService<GroupsViewModel> groupNavigationService, NavigationService<NameListViewModel> NameListNavigationService)
ModalNavigationStore modalNavigationStore, INavigationService<NameListViewModel> NameListNavigationService, INavigationService<GroupsViewModel> groupNavigationService)
{
OverviewListingViewModel = new OverviewListingViewModel(selectedTournamentStore, modalNavigationStore, tournamentStore);
OverviewDetailsViewModel = new OverviewDetailsViewModel(selectedTournamentStore ,groupNavigationService);
OverviewDetailsViewModel = new OverviewDetailsViewModel(selectedTournamentStore, groupNavigationService);
LoadTournamentsCommand = new LoadTournamentsCommand(this, tournamentStore);
OpenAddTournamentCommand = new OpenAddTournamentCommand(tournamentStore, modalNavigationStore, groupNavigationService);
OpenAddTournamentCommand = new OpenAddTournamentCommand(tournamentStore, modalNavigationStore);
NavigateNameListCommand = new NavigateCommand<NameListViewModel>(NameListNavigationService);
}
public static OverviewViewModel LoadViewModel(SelectedTournamentsStore selectedTournamentStore,
ModalNavigationStore modalNavigationStore,
TournamentsStore tournamentStore,
NavigationService<GroupsViewModel> groupNavigationService,
NavigationService<NameListViewModel> NameListNavigationService)
TournamentsStore tournamentStore,
INavigationService<NameListViewModel> NameListNavigationService,
INavigationService<GroupsViewModel> groupNavigationService)
{
OverviewViewModel viewModel = new OverviewViewModel(tournamentStore, selectedTournamentStore, modalNavigationStore,groupNavigationService, NameListNavigationService);
OverviewViewModel viewModel = new OverviewViewModel(tournamentStore, selectedTournamentStore, modalNavigationStore, NameListNavigationService, groupNavigationService);
viewModel.LoadTournamentsCommand.Execute(null);

View File

@@ -6,22 +6,7 @@
xmlns:local="clr-namespace:Apollon.WPF.Views" xmlns:components="clr-namespace:Apollon.WPF.Views.Components"
mc:Ignorable="d"
d:DesignHeight="680" d:DesignWidth="1100">
<Grid Margin="15, 35">
<Grid.RowDefinitions>
<RowDefinition Height="80"/>
<RowDefinition Height="550"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="250"/>
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Border BorderThickness="2" BorderBrush="{StaticResource BrushPrimary1}"
Grid.Row="1" Grid.Column="1"
CornerRadius="5">
<TextBlock Text="Teilnehmer" VerticalAlignment="Center" HorizontalAlignment="Center"/>
</Border>
<components:TournamentDetails Grid.Column="1" HorizontalAlignment="Center" DataContext="{Binding TournamentDetailsViewModel}"/>
<components:NavBarPreparationView Grid.RowSpan="2" DataContext="{Binding NavBarPreparationViewModel}"/>
<Grid>
<TextBlock Text="Teilnehmer" VerticalAlignment="Center" HorizontalAlignment="Center"/>
</Grid>
</UserControl>

View File

@@ -7,23 +7,8 @@
xmlns:components="clr-namespace:Apollon.WPF.Views.Components"
mc:Ignorable="d"
d:DesignHeight="680" d:DesignWidth="1100">
<Grid Margin="15, 35">
<Grid.RowDefinitions>
<RowDefinition Height="80"/>
<RowDefinition Height="550"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="250"/>
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Border BorderThickness="2" BorderBrush="{StaticResource BrushPrimary1}"
Grid.Row="1" Grid.Column="1"
CornerRadius="5">
<TextBlock Text="Klassen" VerticalAlignment="Center" HorizontalAlignment="Center"/>
</Border>
<components:TournamentDetails Grid.Column="1" HorizontalAlignment="Center" DataContext="{Binding TournamentDetailsViewModel}"/>
<components:NavBarPreparationView Grid.RowSpan="2" DataContext="{Binding NavBarPreparationViewModel}"/>
<Grid>
<TextBlock Text="Klassen" VerticalAlignment="Center" HorizontalAlignment="Center"/>
</Grid>
</UserControl>

View File

@@ -0,0 +1,34 @@
<UserControl x:Class="Apollon.WPF.Views.Components.Layout"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:Apollon.WPF.Views.Components"
mc:Ignorable="d"
d:DesignHeight="680" d:DesignWidth="1100">
<Grid>
<Grid Margin="0 35 15 15">
<Grid.RowDefinitions>
<RowDefinition Height="auto"/>
<RowDefinition Height="0"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="250"/>
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<!--<Border BorderThickness="2"
BorderBrush="{StaticResource BrushPrimary1}"
Grid.Row="1" Grid.Column="1"
CornerRadius="5">
</Border>-->
<ContentControl Grid.Row="1"
Grid.Column="1"
Content="{Binding ContentVieModel}"/>
<local:TournamentDetails Height="80" Grid.Column="1" Grid.Row="0" HorizontalAlignment="Center" DataContext="{Binding TournamentDetailsViewModel}"/>
<local:NavBarPreparationView Grid.RowSpan="2" DataContext="{Binding NavBarPreparationViewModel}"/>
</Grid>
</Grid>
</UserControl>

View File

@@ -0,0 +1,28 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace Apollon.WPF.Views.Components
{
/// <summary>
/// Interaction logic for Layout.xaml
/// </summary>
public partial class Layout : UserControl
{
public Layout()
{
InitializeComponent();
}
}
}

View File

@@ -5,8 +5,8 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:Apollon.WPF.Views.Components"
mc:Ignorable="d"
d:DesignHeight="680" d:DesignWidth="1100">
<Grid Height="80">
d:DesignHeight="80" d:DesignWidth="1100">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="auto"/>
<ColumnDefinition Width="600"/>

View File

@@ -5,23 +5,8 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:components="clr-namespace:Apollon.WPF.Views.Components"
mc:Ignorable="d"
d:DesignHeight="680" d:DesignWidth="1100">
<Grid Margin="15,35">
<Grid.RowDefinitions>
<RowDefinition Height="80"/>
<RowDefinition Height="550"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="250"/>
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Border BorderThickness="2" BorderBrush="{StaticResource BrushPrimary1}"
Grid.Row="1" Grid.Column="1"
CornerRadius="5">
<TextBlock Text="Groups" VerticalAlignment="Center" HorizontalAlignment="Center"/>
</Border>
<components:TournamentDetails Grid.Column="1" HorizontalAlignment="Center" DataContext="{Binding TournamentDetailsViewModel}"/>
<components:NavBarPreparationView Grid.RowSpan="2" DataContext="{Binding NavBarPreparationViewModel}"/>
d:DesignHeight="6800" d:DesignWidth="200">
<Grid Background="Red">
<TextBlock Text="Gruppen" VerticalAlignment="Center" HorizontalAlignment="Center"/>
</Grid>
</UserControl>

View File

@@ -49,7 +49,7 @@
<Image Grid.Column="2"
Grid.Row="2"
Source="D:\Projekte\Apollon\Apollon\Apollon.WPF\Images\Archery.png"
Source="\images\Archery.png"
Width="250"
Height="250">
</Image>