implement NavigateCommand
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
<ResourceDictionary.MergedDictionaries>
|
||||
<ResourceDictionary Source="Themes/ButtonTheme.xaml"/>
|
||||
<ResourceDictionary Source="Themes/ModalTextblockTheme.xaml"/>
|
||||
<ResourceDictionary Source="Themes/Common.xaml"/>
|
||||
</ResourceDictionary.MergedDictionaries>
|
||||
</ResourceDictionary>
|
||||
</Application.Resources>
|
||||
|
||||
@@ -22,6 +22,7 @@ namespace Apollon.WPF
|
||||
/// </summary>
|
||||
public partial class App : Application
|
||||
{
|
||||
private readonly NavigationStore _navigationStore;
|
||||
private readonly ModalNavigationStore _modalNavigationStore;
|
||||
private readonly TournamentsDbContextFactory _tournamentsDbContextFactory;
|
||||
private readonly IGetAllTournamentsQuery _getAllTournamentQuery;
|
||||
@@ -36,6 +37,7 @@ namespace Apollon.WPF
|
||||
{
|
||||
string connectionString = "Server=NATHALIE-PC\\NATLINUXDB;Database=Apollon;Trusted_Connection=True;MultipleActiveResultSets=true";
|
||||
|
||||
_navigationStore = new NavigationStore();
|
||||
_modalNavigationStore = new ModalNavigationStore();
|
||||
_tournamentsDbContextFactory = new TournamentsDbContextFactory(
|
||||
new DbContextOptionsBuilder().UseSqlServer(connectionString).Options);
|
||||
@@ -56,11 +58,18 @@ namespace Apollon.WPF
|
||||
OverviewViewModel overviewViewModel = new OverviewViewModel(
|
||||
_tournamentStore,
|
||||
_selectedTournamentStore,
|
||||
_modalNavigationStore);
|
||||
_modalNavigationStore,
|
||||
_navigationStore);
|
||||
|
||||
_navigationStore.CurrentViewModel = new OverviewViewModel(
|
||||
_tournamentStore,
|
||||
_selectedTournamentStore,
|
||||
_modalNavigationStore,
|
||||
_navigationStore);
|
||||
|
||||
MainWindow = new MainWindow()
|
||||
{
|
||||
DataContext = new MainViewModel(_modalNavigationStore, overviewViewModel)
|
||||
DataContext = new MainViewModel(_modalNavigationStore, overviewViewModel,_navigationStore)
|
||||
};
|
||||
MainWindow.Show();
|
||||
|
||||
|
||||
29
Apollon.WPF/Commands/NavigatCommand.cs
Normal file
29
Apollon.WPF/Commands/NavigatCommand.cs
Normal 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -15,7 +15,8 @@
|
||||
Background="Transparent"
|
||||
AllowsTransparency="True"
|
||||
WindowStyle="None"
|
||||
ResizeMode="NoResize">
|
||||
ResizeMode="NoResize"
|
||||
MouseDown="Window_MouseDown">
|
||||
<Window.Resources>
|
||||
<DataTemplate DataType="{x:Type vms:AddTournamentViewModel}">
|
||||
<views:AddTournamentView/>
|
||||
@@ -26,6 +27,12 @@
|
||||
<DataTemplate DataType="{x:Type vms:WarningDeleteViewModel}">
|
||||
<views:WarningDeleteView/>
|
||||
</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>
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
@@ -38,11 +45,20 @@
|
||||
<ContentControl Margin="30" Content="{Binding CurrentModalViewModel}"/>
|
||||
</custom:Modal>
|
||||
|
||||
<views:OverviewView Grid.RowSpan="2"
|
||||
DataContext="{Binding OverviewViewModel}"
|
||||
MouseDown="Window_MouseDown"/>
|
||||
<views:Layout Grid.RowSpan="2"/>
|
||||
|
||||
<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">
|
||||
|
||||
<Button Width="35"
|
||||
|
||||
@@ -9,8 +9,7 @@ namespace Apollon.WPF.Stores
|
||||
{
|
||||
public class ModalNavigationStore
|
||||
{
|
||||
private ViewModelBase _currentViewModel
|
||||
;
|
||||
private ViewModelBase _currentViewModel;
|
||||
public ViewModelBase CurrentViewModel
|
||||
{
|
||||
get
|
||||
|
||||
28
Apollon.WPF/Stores/NavigationStore.cs
Normal file
28
Apollon.WPF/Stores/NavigationStore.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
17
Apollon.WPF/Themes/Common.xaml
Normal file
17
Apollon.WPF/Themes/Common.xaml
Normal 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>
|
||||
@@ -9,25 +9,38 @@ namespace Apollon.WPF.ViewModels
|
||||
{
|
||||
public class MainViewModel : ViewModelBase
|
||||
{
|
||||
private readonly NavigationStore _navigationStore;
|
||||
private readonly ModalNavigationStore _modalNavigationStore;
|
||||
|
||||
public ViewModelBase CurrentModalViewModel => _modalNavigationStore.CurrentViewModel;
|
||||
public ViewModelBase CurrentViewModel => _navigationStore.CurrentViewModel;
|
||||
public bool IsModalOpen => _modalNavigationStore.IsOpen;
|
||||
public OverviewViewModel OverviewViewModel { get; }
|
||||
|
||||
public MainViewModel(ModalNavigationStore modalNavigationStore, OverviewViewModel overviewViewModel)
|
||||
|
||||
public MainViewModel(ModalNavigationStore modalNavigationStore, OverviewViewModel overviewViewModel, NavigationStore navigationStore)
|
||||
{
|
||||
_navigationStore = navigationStore;
|
||||
_modalNavigationStore = modalNavigationStore;
|
||||
OverviewViewModel = overviewViewModel;
|
||||
|
||||
|
||||
_navigationStore.CurrentViewModelChanged += NavigationStore_CurrentViewModelChanged;
|
||||
_modalNavigationStore.CurrentViewModelChanged += ModalNavigationStore_CurrentViewModelChanged;
|
||||
|
||||
}
|
||||
|
||||
protected override void Dispose()
|
||||
{
|
||||
_navigationStore.CurrentViewModelChanged -= NavigationStore_CurrentViewModelChanged;
|
||||
_modalNavigationStore.CurrentViewModelChanged -= ModalNavigationStore_CurrentViewModelChanged;
|
||||
base.Dispose();
|
||||
}
|
||||
|
||||
private void NavigationStore_CurrentViewModelChanged()
|
||||
{
|
||||
OnPropertyChanged(nameof(CurrentViewModel));
|
||||
}
|
||||
private void ModalNavigationStore_CurrentViewModelChanged()
|
||||
{
|
||||
OnPropertyChanged(nameof(CurrentModalViewModel));
|
||||
|
||||
16
Apollon.WPF/ViewModels/NavBarViewModel.cs
Normal file
16
Apollon.WPF/ViewModels/NavBarViewModel.cs
Normal 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)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -16,13 +16,16 @@ namespace Apollon.WPF.ViewModels
|
||||
public OverviewDetailsViewModel OverviewDetailsViewModel{ 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);
|
||||
OverviewDetailsViewModel = new OverviewDetailsViewModel(selectedTournamentStore);
|
||||
|
||||
AddTournamentCommand = new OpenAddTournamentCommand(tournamentStore, modalNavigationStore);
|
||||
NavigateNavBarCommand = new NavigatCommand<NavBarViewModel>(navigationStore, () => new NavBarViewModel(navigationStore));
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
23
Apollon.WPF/Views/Layout.xaml
Normal file
23
Apollon.WPF/Views/Layout.xaml
Normal 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>
|
||||
28
Apollon.WPF/Views/Layout.xaml.cs
Normal file
28
Apollon.WPF/Views/Layout.xaml.cs
Normal 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
14
Apollon.WPF/Views/NavBarView.xaml
Normal file
14
Apollon.WPF/Views/NavBarView.xaml
Normal 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>
|
||||
28
Apollon.WPF/Views/NavBarView.xaml.cs
Normal file
28
Apollon.WPF/Views/NavBarView.xaml.cs
Normal 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -20,18 +20,18 @@
|
||||
<ColumnDefinition/>
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
<Border BorderThickness="4"
|
||||
<!--<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="#d7e8fd" Offset="0.2"/>
|
||||
<GradientStop Color="#81a9e2" Offset="0.8"/>
|
||||
<GradientStop Color="{StaticResource ColorPrimary4}" Offset="0.2"/>
|
||||
<GradientStop Color="{StaticResource ColorPrimary5}" Offset="0.8"/>
|
||||
</LinearGradientBrush>
|
||||
</Border.Background>
|
||||
</Border>
|
||||
</Border>-->
|
||||
|
||||
<StackPanel Grid.ColumnSpan="3">
|
||||
<TextBlock
|
||||
@@ -39,7 +39,7 @@
|
||||
FontSize="50"
|
||||
TextAlignment="Center"
|
||||
Margin="0,35"
|
||||
Foreground="#ff8000"
|
||||
Foreground="{StaticResource BrushPrimary2}"
|
||||
FontFamily="Arial Black">
|
||||
<TextBlock.Effect>
|
||||
<DropShadowEffect Color="#808080"></DropShadowEffect>
|
||||
@@ -52,7 +52,7 @@
|
||||
FontFamily="Arial"
|
||||
FontWeight="Bold"
|
||||
FontSize="20"
|
||||
Foreground="#0000a0">
|
||||
Foreground="{StaticResource BrushPrimary1}">
|
||||
</TextBlock>
|
||||
</StackPanel>
|
||||
|
||||
@@ -86,7 +86,7 @@
|
||||
FontFamily="Arial"
|
||||
FontWeight="Bold"
|
||||
FontSize="16"
|
||||
Foreground="#0000a0"/>
|
||||
Foreground="{StaticResource BrushPrimary1}"/>
|
||||
|
||||
<components:OverViewListing Height="400"
|
||||
Width="400"
|
||||
@@ -103,7 +103,7 @@
|
||||
FontFamily="Arial"
|
||||
FontWeight="Bold"
|
||||
FontSize="16"
|
||||
Foreground="#0000a0"/>
|
||||
Foreground="{StaticResource BrushPrimary1}"/>
|
||||
<components:OverviewDetails Width="320"
|
||||
DataContext="{Binding OverviewDetailsViewModel}"/>
|
||||
|
||||
@@ -113,7 +113,8 @@
|
||||
Height="40"
|
||||
Width="210"
|
||||
Margin="40"
|
||||
Cursor="Hand"/>
|
||||
Cursor="Hand"
|
||||
Command="{Binding NavigateNavBarCommand}"/>
|
||||
</StackPanel>
|
||||
|
||||
</Grid>
|
||||
|
||||
Reference in New Issue
Block a user