Navigation Service and Cleanup UI

This commit is contained in:
Natlinux
2022-11-27 21:52:18 +01:00
parent 3911dd66e8
commit 56a433876e
14 changed files with 441 additions and 345 deletions

View File

@@ -1,4 +1,5 @@
using Apollon.WPF.Stores;
using Apollon.WPF.Services;
using Apollon.WPF.Stores;
using Apollon.WPF.ViewModels;
using System;
using System.Collections.Generic;
@@ -11,18 +12,16 @@ namespace Apollon.WPF.Commands
public class NavigateCommand<TViewModel> : CommandBase
where TViewModel : ViewModelBase
{
private readonly NavigationStore _navigationStore;
private readonly Func<TViewModel> _createViewModel;
private readonly NavigationService<TViewModel> _navigationService;
public NavigateCommand(NavigationStore navigationStore, Func<TViewModel> createViewModel)
public NavigateCommand(NavigationService<TViewModel> navigationService)
{
_navigationStore = navigationStore;
_createViewModel = createViewModel;
_navigationService = navigationService;
}
public override void Execute(object parameter)
{
_navigationStore.CurrentViewModel = _createViewModel();
_navigationService.Navigate();
}
}
}

View File

@@ -49,6 +49,12 @@
<DataTemplate DataType="{x:Type vms:GroupsViewModel}">
<views:GroupsView/>
</DataTemplate>
<DataTemplate DataType="{x:Type vms:ClassesViewModel}">
<views:ClassesView/>
</DataTemplate>
<DataTemplate DataType="{x:Type vms:ArchersViewModel}">
<views:ArchersView/>
</DataTemplate>
<DataTemplate DataType="{x:Type vms:NameListViewModel}">
<views:RootdatesView/>
</DataTemplate>

View File

@@ -0,0 +1,28 @@
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 NavigationService<TViewModel>
where TViewModel : ViewModelBase
{
private readonly NavigationStore _navigationStore;
private readonly Func<TViewModel> _createViewModel;
public NavigationService(NavigationStore navigationStore, Func<TViewModel> createViewModel)
{
_navigationStore = navigationStore;
_createViewModel = createViewModel;
}
public void Navigate()
{
_navigationStore.CurrentViewModel = _createViewModel();
}
}
}

View File

@@ -8,5 +8,11 @@ namespace Apollon.WPF.ViewModels
{
public class ArchersViewModel : ViewModelBase
{
public NavBarPreparationViewModel NavBarPreparationViewModel { get; }
public ArchersViewModel(NavBarPreparationViewModel navBarPreparationViewModel)
{
NavBarPreparationViewModel = navBarPreparationViewModel;
}
}
}

View File

@@ -8,5 +8,11 @@ namespace Apollon.WPF.ViewModels
{
public class ClassesViewModel : ViewModelBase
{
public NavBarPreparationViewModel NavBarPreparationViewModel { get; }
public ClassesViewModel(NavBarPreparationViewModel navBarPreparationViewModel)
{
NavBarPreparationViewModel = navBarPreparationViewModel;
}
}
}

View File

@@ -1,5 +1,6 @@
using Apollon.Domain.Models;
using Apollon.WPF.Commands;
using Apollon.WPF.Services;
using Apollon.WPF.Stores;
using System;
using System.Collections.Generic;
@@ -14,13 +15,14 @@ namespace Apollon.WPF.ViewModels
{
public TournamentDetailsViewModel TournamentDetailsViewModel { get; }
public NavBarPreparationViewModel NavBarPreparationViewModel { get; }
public ICommand NavigateOverviewCommand { get; }
public GroupsViewModel(SelectedTournamentsStore selectedTournamentStore, NavigationStore navigationStore, ModalNavigationStore modalNavigationStore, TournamentsStore tournamentsStore)
{
TournamentDetailsViewModel = new TournamentDetailsViewModel(selectedTournamentStore);
NavigateOverviewCommand = new NavigateCommand<OverviewViewModel>(navigationStore, () => OverviewViewModel.LoadViewModel(selectedTournamentStore, modalNavigationStore, tournamentsStore, navigationStore));
NavigateOverviewCommand = new NavigateCommand<OverviewViewModel>(new NavigationService<OverviewViewModel>(navigationStore, () => OverviewViewModel.LoadViewModel(selectedTournamentStore, modalNavigationStore, tournamentsStore, navigationStore)));
}
}
}

View File

@@ -1,4 +1,5 @@
using Apollon.WPF.Commands;
using Apollon.WPF.Services;
using System;
using System.Collections.Generic;
using System.Linq;
@@ -14,5 +15,14 @@ namespace Apollon.WPF.ViewModels
public ICommand NavigateGroupsCommand { get;}
public ICommand NavigateClassesCommand { get;}
public ICommand NavigateArchersCommand { get;}
public NavBarPreparationViewModel(NavigationService<OverviewViewModel> overviewNavigationService, NavigationService<GroupsViewModel> groupNavigationService,
NavigationService<ClassesViewModel> classNavigationService, NavigationService<ArchersViewModel> archersNavigationService)
{
NavigateOverviewCommand = new NavigateCommand<OverviewViewModel>(overviewNavigationService);
NavigateGroupsCommand = new NavigateCommand<GroupsViewModel>(groupNavigationService);
NavigateClassesCommand = new NavigateCommand<ClassesViewModel>(classNavigationService);
NavigateArchersCommand = new NavigateCommand<ArchersViewModel>(archersNavigationService);
}
}
}

View File

@@ -1,5 +1,6 @@
using Apollon.Domain.Models;
using Apollon.WPF.Commands;
using Apollon.WPF.Services;
using Apollon.WPF.Stores;
using System;
using System.Collections.Generic;
@@ -35,7 +36,8 @@ namespace Apollon.WPF.ViewModels
_selectedTournamentStore.SelectedTournamentChanged += SelectedTournamentStore_SelectedTournamentChanged;
NavigatePreparationCommand = new NavigateCommand<GroupsViewModel>(navigationStore, () => new GroupsViewModel(selectedTournamentStore, navigationStore, modalNavigationStore, tournamentsStore));
NavigatePreparationCommand = new NavigateCommand<GroupsViewModel>(new NavigationService<GroupsViewModel> (
navigationStore, () => new GroupsViewModel( _selectedTournamentStore, navigationStore, modalNavigationStore, tournamentsStore)));
}
protected override void Dispose()

View File

@@ -1,12 +1,7 @@
using Apollon.WPF.Commands;
using Apollon.Domain.Models;
using Apollon.WPF.Stores;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;
using Apollon.WPF.Services;
namespace Apollon.WPF.ViewModels
{
@@ -58,7 +53,8 @@ namespace Apollon.WPF.ViewModels
LoadTournamentsCommand = new LoadTournamentsCommand(this, tournamentStore);
OpenAddTournamentCommand = new OpenAddTournamentCommand(tournamentStore, modalNavigationStore, navigationStore, selectedTournamentStore);
NavigateNameListCommand = new NavigateCommand<NameListViewModel>(navigationStore, () => new NameListViewModel());
NavigateNameListCommand = new NavigateCommand<NameListViewModel>(new NavigationService<NameListViewModel>(
navigationStore, () => new NameListViewModel()));
}

View File

@@ -3,10 +3,25 @@
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"
xmlns:local="clr-namespace:Apollon.WPF.Views" xmlns:components="clr-namespace:Apollon.WPF.Views.Components"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<Grid>
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>
</UserControl>

View File

@@ -4,9 +4,26 @@
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"
xmlns:components="clr-namespace:Apollon.WPF.Views.Components"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<Grid>
d:DesignHeight="680" d:DesignWidth="1100">
<Grid Margin="1535">
<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>
</UserControl>

View File

@@ -6,8 +6,12 @@
xmlns:local="clr-namespace:Apollon.WPF.Views.Components"
xmlns:iconPacks="http://metro.mahapps.com/winfx/xaml/iconpacks"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
d:DesignHeight="680" d:DesignWidth="1100">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="80"/>
<RowDefinition Height="auto"/>
</Grid.RowDefinitions>
<StackPanel>
<Button Width="35"
Height="35"
@@ -19,9 +23,19 @@
Width="35"
Foreground="#0000a0"/>
</Button>
<Menu Height="450"
<TextBlock Text="Vorbereitung"
Foreground="#0000a0"
FontFamily="Arial"
FontWeight="Bold"
FontSize="24"
HorizontalAlignment="Center"
Margin="0 15"/>
</StackPanel>
<Menu Height="350"
Background="Transparent"
Margin="0,20,0,0">
Grid.Row="1"
Margin=" 0 40">
<Menu.ItemsPanel>
<ItemsPanelTemplate>
<VirtualizingStackPanel Orientation="Vertical"/>
@@ -35,7 +49,7 @@
FontSize="16"
VerticalAlignment="Center"
HorizontalAlignment="Center"
Margin="0 40">
Margin="0 20">
<MenuItem.Icon>
<iconPacks:PackIconMaterial Kind="BowArrow"
Height="20"
@@ -45,7 +59,8 @@
VerticalAlignment="Center"/>
</MenuItem.Icon>
<MenuItem Header="Gruppen"
Template="{StaticResource Item_Template}">
Template="{StaticResource Item_Template}"
Command="{Binding NavigateGroupsCommand}">
<MenuItem.Icon>
<iconPacks:PackIconMaterial Kind="AccountMultiple"
Height="20"
@@ -56,7 +71,8 @@
</MenuItem.Icon>
</MenuItem>
<MenuItem Header="Klassen"
Template="{StaticResource Item_Template}">
Template="{StaticResource Item_Template}"
Command="{Binding NavigateClassesCommand}">
<MenuItem.Icon>
<iconPacks:PackIconMaterial Kind="ArrowProjectileMultiple"
Height="20"
@@ -78,7 +94,8 @@
</MenuItem.Icon>
</MenuItem>
<MenuItem Header="Teilnehmer setzen"
Template="{StaticResource Item_Template}">
Template="{StaticResource Item_Template}"
Command="{Binding NavigateArchersCommand}">
<MenuItem.Icon>
<iconPacks:PackIconMaterial Kind="ArrowProjectile"
Height="20"
@@ -374,6 +391,5 @@
</MenuItem>
</MenuItem>
</Menu>
</StackPanel>
</Grid>
</UserControl>

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="100" d:DesignWidth="800">
<Grid>
d:DesignHeight="680" d:DesignWidth="1100">
<Grid Height="80">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="auto"/>
<ColumnDefinition Width="600"/>
@@ -14,7 +14,8 @@
</Grid.ColumnDefinitions>
<Image Grid.Column="0"
Source="{Binding Logo}"
Width="80"
Width="70"
Height="70"
VerticalAlignment="Center"/>
<StackPanel Grid.Column="1">
<WrapPanel HorizontalAlignment="Center">
@@ -81,6 +82,7 @@
<Image Grid.Column="2"
Source="{Binding CompetitionImage}"
Width="70"
Height="70"
VerticalAlignment="Center"/>
</Grid>
</UserControl>

View File

@@ -4,33 +4,24 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:components="clr-namespace:Apollon.WPF.Views.Components"
xmlns:iconPacks="http://metro.mahapps.com/winfx/xaml/iconpacks"
xmlns:local="clr-namespace:Apollon.WPF.Views"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<Grid Margin="20" >
d:DesignHeight="680" d:DesignWidth="1100">
<Grid Margin="15,35">
<Grid.RowDefinitions>
<RowDefinition Height="120"/>
<RowDefinition Height="*"/>
<RowDefinition Height="80"/>
<RowDefinition Height="550"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="250"/>
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Border Grid.Column="2" Grid.Row="2"
BorderBrush="#0000a0"
BorderThickness="1"
CornerRadius="2">
<StackPanel VerticalAlignment="Center" HorizontalAlignment="Center">
<TextBlock Text="Gruppen" />
<!--<TextBlock Text="{Binding Groups}"/>-->
</StackPanel>
<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" Margin="0,35,0,10" HorizontalAlignment="Center" DataContext="{Binding TournamentDetailsViewModel}"/>
<components:NavBarPreparationView Grid.Row="1" Margin="0 ,0 ,2, 30"/>
<components:TournamentDetails Grid.Column="1" HorizontalAlignment="Center" DataContext="{Binding TournamentDetailsViewModel}"/>
<components:NavBarPreparationView Grid.RowSpan="2" DataContext="{Binding NavBarPreparationViewModel}"/>
</Grid>
</UserControl>