implement NavigateCommand

This commit is contained in:
Natlinux81
2022-08-27 02:23:07 +02:00
parent 694b932f24
commit fa278fc245
15 changed files with 250 additions and 25 deletions

View File

@@ -7,6 +7,7 @@
<ResourceDictionary.MergedDictionaries> <ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Themes/ButtonTheme.xaml"/> <ResourceDictionary Source="Themes/ButtonTheme.xaml"/>
<ResourceDictionary Source="Themes/ModalTextblockTheme.xaml"/> <ResourceDictionary Source="Themes/ModalTextblockTheme.xaml"/>
<ResourceDictionary Source="Themes/Common.xaml"/>
</ResourceDictionary.MergedDictionaries> </ResourceDictionary.MergedDictionaries>
</ResourceDictionary> </ResourceDictionary>
</Application.Resources> </Application.Resources>

View File

@@ -22,6 +22,7 @@ namespace Apollon.WPF
/// </summary> /// </summary>
public partial class App : Application public partial class App : Application
{ {
private readonly NavigationStore _navigationStore;
private readonly ModalNavigationStore _modalNavigationStore; private readonly ModalNavigationStore _modalNavigationStore;
private readonly TournamentsDbContextFactory _tournamentsDbContextFactory; private readonly TournamentsDbContextFactory _tournamentsDbContextFactory;
private readonly IGetAllTournamentsQuery _getAllTournamentQuery; private readonly IGetAllTournamentsQuery _getAllTournamentQuery;
@@ -36,6 +37,7 @@ namespace Apollon.WPF
{ {
string connectionString = "Server=NATHALIE-PC\\NATLINUXDB;Database=Apollon;Trusted_Connection=True;MultipleActiveResultSets=true"; string connectionString = "Server=NATHALIE-PC\\NATLINUXDB;Database=Apollon;Trusted_Connection=True;MultipleActiveResultSets=true";
_navigationStore = new NavigationStore();
_modalNavigationStore = new ModalNavigationStore(); _modalNavigationStore = new ModalNavigationStore();
_tournamentsDbContextFactory = new TournamentsDbContextFactory( _tournamentsDbContextFactory = new TournamentsDbContextFactory(
new DbContextOptionsBuilder().UseSqlServer(connectionString).Options); new DbContextOptionsBuilder().UseSqlServer(connectionString).Options);
@@ -56,11 +58,18 @@ namespace Apollon.WPF
OverviewViewModel overviewViewModel = new OverviewViewModel( OverviewViewModel overviewViewModel = new OverviewViewModel(
_tournamentStore, _tournamentStore,
_selectedTournamentStore, _selectedTournamentStore,
_modalNavigationStore); _modalNavigationStore,
_navigationStore);
_navigationStore.CurrentViewModel = new OverviewViewModel(
_tournamentStore,
_selectedTournamentStore,
_modalNavigationStore,
_navigationStore);
MainWindow = new MainWindow() MainWindow = new MainWindow()
{ {
DataContext = new MainViewModel(_modalNavigationStore, overviewViewModel) DataContext = new MainViewModel(_modalNavigationStore, overviewViewModel,_navigationStore)
}; };
MainWindow.Show(); MainWindow.Show();

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.Commands
{
public class NavigatCommand<TViewModel> : CommandBase
where TViewModel : ViewModelBase
{
private readonly NavigationStore _navigationStore;
private readonly Func<TViewModel> _createViewModel;
public NavigatCommand(NavigationStore navigationStore, Func<TViewModel> createViewModel)
{
_navigationStore = navigationStore;
_createViewModel = createViewModel;
}
public override void Execute(object parameter)
{
_navigationStore.CurrentViewModel = _createViewModel();
}
}
}

View File

@@ -15,7 +15,8 @@
Background="Transparent" Background="Transparent"
AllowsTransparency="True" AllowsTransparency="True"
WindowStyle="None" WindowStyle="None"
ResizeMode="NoResize"> ResizeMode="NoResize"
MouseDown="Window_MouseDown">
<Window.Resources> <Window.Resources>
<DataTemplate DataType="{x:Type vms:AddTournamentViewModel}"> <DataTemplate DataType="{x:Type vms:AddTournamentViewModel}">
<views:AddTournamentView/> <views:AddTournamentView/>
@@ -26,6 +27,12 @@
<DataTemplate DataType="{x:Type vms:WarningDeleteViewModel}"> <DataTemplate DataType="{x:Type vms:WarningDeleteViewModel}">
<views:WarningDeleteView/> <views:WarningDeleteView/>
</DataTemplate> </DataTemplate>
<DataTemplate DataType="{x:Type vms:NavBarViewModel}">
<views:NavBarView Content="{Binding CurrentViewModel}" DataContext="{Binding NavBarViewModel}"/>
</DataTemplate>
<DataTemplate DataType="{x:Type vms:OverviewViewModel}">
<views:OverviewView Content="{Binding CurrentViewModel}" DataContext="{Binding OverviewViewModel}"/>
</DataTemplate>
</Window.Resources> </Window.Resources>
<Grid> <Grid>
<Grid.RowDefinitions> <Grid.RowDefinitions>
@@ -38,11 +45,20 @@
<ContentControl Margin="30" Content="{Binding CurrentModalViewModel}"/> <ContentControl Margin="30" Content="{Binding CurrentModalViewModel}"/>
</custom:Modal> </custom:Modal>
<views:OverviewView Grid.RowSpan="2" <views:Layout Grid.RowSpan="2"/>
DataContext="{Binding OverviewViewModel}"
MouseDown="Window_MouseDown"/>
<WrapPanel HorizontalAlignment="Right" <ContentControl Content="{Binding CurrentViewModel}">
<ContentControl.Resources>
<DataTemplate DataType="{x:Type vms:OverviewViewModel}">
<views:OverviewView/>
</DataTemplate>
<DataTemplate DataType="{x:Type vms:NavBarViewModel}">
<views:NavBarView/>
</DataTemplate>
</ContentControl.Resources>
</ContentControl>
<WrapPanel HorizontalAlignment="Right"
Margin="0 0 5 0"> Margin="0 0 5 0">
<Button Width="35" <Button Width="35"

View File

@@ -9,8 +9,7 @@ namespace Apollon.WPF.Stores
{ {
public class ModalNavigationStore public class ModalNavigationStore
{ {
private ViewModelBase _currentViewModel private ViewModelBase _currentViewModel;
;
public ViewModelBase CurrentViewModel public ViewModelBase CurrentViewModel
{ {
get get

View File

@@ -0,0 +1,28 @@
using Apollon.WPF.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Apollon.WPF.Stores
{
public class NavigationStore
{
private ViewModelBase _currentViewModel;
public ViewModelBase CurrentViewModel
{
get
{
return _currentViewModel;
}
set
{
_currentViewModel = value;
CurrentViewModelChanged?.Invoke();
}
}
public event Action CurrentViewModelChanged;
}
}

View File

@@ -0,0 +1,17 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<!--Color-->
<Color x:Key="ColorPrimary1">#0000a0</Color>
<Color x:Key="ColorPrimary2">#ff8000</Color>
<Color x:Key="ColorPrimary3">#808080</Color>
<Color x:Key="ColorPrimary4">#d7e8fd</Color>
<Color x:Key="ColorPrimary5">#81a9e2</Color>
<!--Brushes-->
<SolidColorBrush x:Key="BrushPrimary1" Color="{StaticResource ColorPrimary1}"/>
<SolidColorBrush x:Key="BrushPrimary2" Color="{StaticResource ColorPrimary2}"/>
<SolidColorBrush x:Key="BrushPrimary3" Color="{StaticResource ColorPrimary3}"/>
<SolidColorBrush x:Key="BrushPrimary4" Color="{StaticResource ColorPrimary4}"/>
<SolidColorBrush x:Key="BrushPrimary5" Color="{StaticResource ColorPrimary5}"/>
</ResourceDictionary>

View File

@@ -9,25 +9,38 @@ namespace Apollon.WPF.ViewModels
{ {
public class MainViewModel : ViewModelBase public class MainViewModel : ViewModelBase
{ {
private readonly NavigationStore _navigationStore;
private readonly ModalNavigationStore _modalNavigationStore; private readonly ModalNavigationStore _modalNavigationStore;
public ViewModelBase CurrentModalViewModel => _modalNavigationStore.CurrentViewModel; public ViewModelBase CurrentModalViewModel => _modalNavigationStore.CurrentViewModel;
public ViewModelBase CurrentViewModel => _navigationStore.CurrentViewModel;
public bool IsModalOpen => _modalNavigationStore.IsOpen; public bool IsModalOpen => _modalNavigationStore.IsOpen;
public OverviewViewModel OverviewViewModel { get; } public OverviewViewModel OverviewViewModel { get; }
public MainViewModel(ModalNavigationStore modalNavigationStore, OverviewViewModel overviewViewModel)
public MainViewModel(ModalNavigationStore modalNavigationStore, OverviewViewModel overviewViewModel, NavigationStore navigationStore)
{ {
_navigationStore = navigationStore;
_modalNavigationStore = modalNavigationStore; _modalNavigationStore = modalNavigationStore;
OverviewViewModel = overviewViewModel; OverviewViewModel = overviewViewModel;
_navigationStore.CurrentViewModelChanged += NavigationStore_CurrentViewModelChanged;
_modalNavigationStore.CurrentViewModelChanged += ModalNavigationStore_CurrentViewModelChanged; _modalNavigationStore.CurrentViewModelChanged += ModalNavigationStore_CurrentViewModelChanged;
} }
protected override void Dispose() protected override void Dispose()
{ {
_navigationStore.CurrentViewModelChanged -= NavigationStore_CurrentViewModelChanged;
_modalNavigationStore.CurrentViewModelChanged -= ModalNavigationStore_CurrentViewModelChanged; _modalNavigationStore.CurrentViewModelChanged -= ModalNavigationStore_CurrentViewModelChanged;
base.Dispose(); base.Dispose();
} }
private void NavigationStore_CurrentViewModelChanged()
{
OnPropertyChanged(nameof(CurrentViewModel));
}
private void ModalNavigationStore_CurrentViewModelChanged() private void ModalNavigationStore_CurrentViewModelChanged()
{ {
OnPropertyChanged(nameof(CurrentModalViewModel)); OnPropertyChanged(nameof(CurrentModalViewModel));

View File

@@ -0,0 +1,16 @@
using Apollon.WPF.Stores;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Apollon.WPF.ViewModels
{
public class NavBarViewModel : ViewModelBase
{
public NavBarViewModel(NavigationStore navigationStore)
{
}
}
}

View File

@@ -16,13 +16,16 @@ namespace Apollon.WPF.ViewModels
public OverviewDetailsViewModel OverviewDetailsViewModel{ get; } public OverviewDetailsViewModel OverviewDetailsViewModel{ get; }
public ICommand AddTournamentCommand { get; } public ICommand AddTournamentCommand { get; }
public ICommand NavigateNavBarCommand { get; }
public OverviewViewModel(TournamentsStore tournamentStore, SelectedTournamentsStore selectedTournamentStore, ModalNavigationStore modalNavigationStore) public OverviewViewModel(TournamentsStore tournamentStore, SelectedTournamentsStore selectedTournamentStore, ModalNavigationStore modalNavigationStore, NavigationStore navigationStore)
{ {
OverviewListingViewModel = OverviewListingViewModel.LoadViewModel(selectedTournamentStore, modalNavigationStore, tournamentStore); OverviewListingViewModel = OverviewListingViewModel.LoadViewModel(selectedTournamentStore, modalNavigationStore, tournamentStore);
OverviewDetailsViewModel = new OverviewDetailsViewModel(selectedTournamentStore); OverviewDetailsViewModel = new OverviewDetailsViewModel(selectedTournamentStore);
AddTournamentCommand = new OpenAddTournamentCommand(tournamentStore, modalNavigationStore); AddTournamentCommand = new OpenAddTournamentCommand(tournamentStore, modalNavigationStore);
NavigateNavBarCommand = new NavigatCommand<NavBarViewModel>(navigationStore, () => new NavBarViewModel(navigationStore));
} }
} }
} }

View File

@@ -0,0 +1,23 @@
<UserControl x:Class="Apollon.WPF.Views.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"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<Grid>
<Border BorderThickness="4"
BorderBrush="#0000a0"
CornerRadius="5"
Grid.RowSpan="2"
Grid.ColumnSpan="3">
<Border.Background>
<LinearGradientBrush StartPoint="0.5,0" EndPoint="0.5,1">
<GradientStop Color="{StaticResource ColorPrimary4}" Offset="0.2"/>
<GradientStop Color="{StaticResource ColorPrimary5}" Offset="0.8"/>
</LinearGradientBrush>
</Border.Background>
</Border>
</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
{
/// <summary>
/// Interaction logic for Layout.xaml
/// </summary>
public partial class Layout : UserControl
{
public Layout()
{
InitializeComponent();
}
}
}

View File

@@ -0,0 +1,14 @@
<UserControl x:Class="Apollon.WPF.Views.NavBarView"
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"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<Grid>
<TextBlock Text="Navbar"
FontSize="35"
Padding="100"/>
</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
{
/// <summary>
/// Interaction logic for NavBarView.xaml
/// </summary>
public partial class NavBarView : UserControl
{
public NavBarView()
{
InitializeComponent();
}
}
}

View File

@@ -20,18 +20,18 @@
<ColumnDefinition/> <ColumnDefinition/>
</Grid.ColumnDefinitions> </Grid.ColumnDefinitions>
<Border BorderThickness="4" <!--<Border BorderThickness="4"
BorderBrush="#0000a0" BorderBrush="#0000a0"
CornerRadius="5" CornerRadius="5"
Grid.RowSpan="2" Grid.RowSpan="2"
Grid.ColumnSpan="3"> Grid.ColumnSpan="3">
<Border.Background> <Border.Background>
<LinearGradientBrush StartPoint="0.5,0" EndPoint="0.5,1"> <LinearGradientBrush StartPoint="0.5,0" EndPoint="0.5,1">
<GradientStop Color="#d7e8fd" Offset="0.2"/> <GradientStop Color="{StaticResource ColorPrimary4}" Offset="0.2"/>
<GradientStop Color="#81a9e2" Offset="0.8"/> <GradientStop Color="{StaticResource ColorPrimary5}" Offset="0.8"/>
</LinearGradientBrush> </LinearGradientBrush>
</Border.Background> </Border.Background>
</Border> </Border>-->
<StackPanel Grid.ColumnSpan="3"> <StackPanel Grid.ColumnSpan="3">
<TextBlock <TextBlock
@@ -39,7 +39,7 @@
FontSize="50" FontSize="50"
TextAlignment="Center" TextAlignment="Center"
Margin="0,35" Margin="0,35"
Foreground="#ff8000" Foreground="{StaticResource BrushPrimary2}"
FontFamily="Arial Black"> FontFamily="Arial Black">
<TextBlock.Effect> <TextBlock.Effect>
<DropShadowEffect Color="#808080"></DropShadowEffect> <DropShadowEffect Color="#808080"></DropShadowEffect>
@@ -52,7 +52,7 @@
FontFamily="Arial" FontFamily="Arial"
FontWeight="Bold" FontWeight="Bold"
FontSize="20" FontSize="20"
Foreground="#0000a0"> Foreground="{StaticResource BrushPrimary1}">
</TextBlock> </TextBlock>
</StackPanel> </StackPanel>
@@ -86,7 +86,7 @@
FontFamily="Arial" FontFamily="Arial"
FontWeight="Bold" FontWeight="Bold"
FontSize="16" FontSize="16"
Foreground="#0000a0"/> Foreground="{StaticResource BrushPrimary1}"/>
<components:OverViewListing Height="400" <components:OverViewListing Height="400"
Width="400" Width="400"
@@ -103,7 +103,7 @@
FontFamily="Arial" FontFamily="Arial"
FontWeight="Bold" FontWeight="Bold"
FontSize="16" FontSize="16"
Foreground="#0000a0"/> Foreground="{StaticResource BrushPrimary1}"/>
<components:OverviewDetails Width="320" <components:OverviewDetails Width="320"
DataContext="{Binding OverviewDetailsViewModel}"/> DataContext="{Binding OverviewDetailsViewModel}"/>
@@ -113,7 +113,8 @@
Height="40" Height="40"
Width="210" Width="210"
Margin="40" Margin="40"
Cursor="Hand"/> Cursor="Hand"
Command="{Binding NavigateNavBarCommand}"/>
</StackPanel> </StackPanel>
</Grid> </Grid>