Open/Close AddTournamentModal

This commit is contained in:
Natlinux81
2022-08-14 03:55:20 +02:00
parent ab742103de
commit 61f06a6b5d
12 changed files with 116 additions and 13 deletions

View File

@@ -25,7 +25,7 @@ namespace Apollon.WPF
}
protected override void OnStartup(StartupEventArgs e)
{
OverviewViewModel overviewViewModel = new OverviewViewModel(_selectedTournamentStore);
OverviewViewModel overviewViewModel = new OverviewViewModel(_selectedTournamentStore, _modalNavigationStore);
MainWindow = new MainWindow()
{

View File

@@ -0,0 +1,24 @@
using Apollon.WPF.Stores;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Apollon.WPF.Commands
{
public class CloseModalCommand : CommandBase
{
private readonly ModalNavigationStore _modalNavigationStore;
public CloseModalCommand(ModalNavigationStore modalNavigationStore)
{
_modalNavigationStore = modalNavigationStore;
}
public override void Execute(object parameter)
{
_modalNavigationStore.Close();
}
}
}

View File

@@ -0,0 +1,26 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;
namespace Apollon.WPF.Commands
{
public abstract class CommandBase : ICommand
{
public event EventHandler CanExecuteChanged;
public virtual bool CanExecute(object parameter)
{
return true;
}
public abstract void Execute(object parameter);
protected virtual void OnCanExecutedChanged()
{
CanExecuteChanged?.Invoke(this, new EventArgs());
}
}
}

View File

@@ -0,0 +1,26 @@
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
{
internal class OpenAddTournamentCommand : CommandBase
{
private readonly ModalNavigationStore _modalNavigationStore;
public OpenAddTournamentCommand(ModalNavigationStore modalNavigationStore)
{
_modalNavigationStore = modalNavigationStore;
}
public override void Execute(object parameter)
{
AddTournametViewModel addTournametViewModel = new AddTournametViewModel(_modalNavigationStore);
_modalNavigationStore.CurrentViewModel = addTournametViewModel;
}
}
}

View File

@@ -27,5 +27,10 @@ namespace Apollon.WPF.Stores
public bool IsOpen => CurrentViewModel != null;
public event Action CurrentViewModelChanged;
}
internal void Close()
{
CurrentViewModel = null;
}
}
}

View File

@@ -95,8 +95,15 @@ namespace Apollon.WPF.ViewModels
}
public bool CanSubmit => !string.IsNullOrEmpty(Tournamentname);
public ICommand SubmitCommand { get; }
public ICommand CancelCommand { get; }
public AddEditDetailsViewModel(ICommand submitCommand, ICommand cancelCommand)
{
SubmitCommand = submitCommand;
CancelCommand = cancelCommand;
}
}

View File

@@ -1,8 +1,11 @@
using System;
using Apollon.WPF.Commands;
using Apollon.WPF.Stores;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;
namespace Apollon.WPF.ViewModels
{
@@ -10,9 +13,10 @@ namespace Apollon.WPF.ViewModels
{
public AddEditDetailsViewModel AddEditDetailsViewModel { get; }
public AddTournametViewModel()
public AddTournametViewModel(ModalNavigationStore modalNavigationStore)
{
AddEditDetailsViewModel = new AddEditDetailsViewModel();
ICommand cancelCommand = new CloseModalCommand(modalNavigationStore);
AddEditDetailsViewModel = new AddEditDetailsViewModel(null, cancelCommand);
}
}

View File

@@ -1,17 +1,22 @@
using System;
using Apollon.WPF.Commands;
using Apollon.WPF.Stores;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;
namespace Apollon.WPF.ViewModels
{
public class EditTournamentViewModel : ViewModelBase
{
public AddEditDetailsViewModel AddEditDetailsViewModel { get; }
public EditTournamentViewModel()
public EditTournamentViewModel(ModalNavigationStore modalNavigationStore)
{
AddEditDetailsViewModel = new AddEditDetailsViewModel();
ICommand cancelCommand = new CloseModalCommand(modalNavigationStore);
AddEditDetailsViewModel = new AddEditDetailsViewModel(null, cancelCommand); ;
}
}
}

View File

@@ -1,4 +1,5 @@
using Apollon.WPF.Stores;
using Apollon.WPF.Commands;
using Apollon.WPF.Stores;
using System;
using System.Collections.Generic;
using System.Linq;
@@ -12,12 +13,15 @@ namespace Apollon.WPF.ViewModels
{
public OverviewListingViewModel OverviewListingViewModel { get; }
public OverviewDetailsViewModel OverviewDetailsViewModel{ get; }
public ICommand AddTournamentCommand { get; }
public OverviewViewModel(SelectedTournamentStore _selectedTournamentStore)
public OverviewViewModel(SelectedTournamentStore _selectedTournamentStore, ModalNavigationStore modalNavigationStore)
{
OverviewListingViewModel = new OverviewListingViewModel(_selectedTournamentStore);
OverviewDetailsViewModel = new OverviewDetailsViewModel(_selectedTournamentStore);
AddTournamentCommand = new OpenAddTournamentCommand(modalNavigationStore);
}
}
}

View File

@@ -13,6 +13,7 @@
FontWeight="Bold"
FontSize="25"
Foreground="#0000a0"/>
<components:AddEditDetails Margin="0 50 0 0"/>
<components:AddEditDetails Margin="0 50 0 0"
DataContext="{Binding AddEditDetailsViewModel}"/>
</Grid>
</UserControl>

View File

@@ -47,7 +47,7 @@
VerticalContentAlignment="Center"/>
<TextBox Grid.Row="1"
Grid.Column="1"
Text="{Binding Tournamentname}"
Text="{Binding Tournamentname, UpdateSourceTrigger=PropertyChanged}"
FontFamily="Arial"
FontSize="16"
Height="30"

View File

@@ -13,6 +13,7 @@
FontWeight="Bold"
FontSize="25"
Foreground="#0000a0"/>
<components:AddEditDetails Margin="0 50 0 0"/>
<components:AddEditDetails Margin="0 50 0 0"
DataContext="{Binding AddEditDetailsViewModel}"/>
</Grid>
</UserControl>