lauffähige Grundversion erstellt
This commit is contained in:
45
SewerStammGen/Commands/AsyncCommandBase.cs
Normal file
45
SewerStammGen/Commands/AsyncCommandBase.cs
Normal file
@@ -0,0 +1,45 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Input;
|
||||
|
||||
namespace SewerStammGen.Commands
|
||||
{
|
||||
internal abstract class AsyncCommandBase : ICommand
|
||||
{
|
||||
bool _isExecuting = false;
|
||||
public event EventHandler? CanExecuteChanged;
|
||||
|
||||
public bool IsExecuting
|
||||
{
|
||||
get => _isExecuting;
|
||||
set
|
||||
{
|
||||
_isExecuting = value;
|
||||
CanExecuteChanged?.Invoke(this, new EventArgs());
|
||||
}
|
||||
}
|
||||
|
||||
protected void OnCanExecuteChanged()
|
||||
{
|
||||
CanExecuteChanged?.Invoke(this, new EventArgs());
|
||||
}
|
||||
|
||||
|
||||
public virtual bool CanExecute(object? parameter)
|
||||
{
|
||||
return !IsExecuting;
|
||||
}
|
||||
|
||||
public async void Execute(object? parameter)
|
||||
{
|
||||
IsExecuting = true;
|
||||
await ExecuteAsync(parameter);
|
||||
IsExecuting = false;
|
||||
}
|
||||
|
||||
public abstract Task ExecuteAsync(object? parameter);
|
||||
}
|
||||
}
|
||||
32
SewerStammGen/Commands/UpdateCurrentViewModelCommand.cs
Normal file
32
SewerStammGen/Commands/UpdateCurrentViewModelCommand.cs
Normal file
@@ -0,0 +1,32 @@
|
||||
using SewerStammGen.Enum;
|
||||
using SewerStammGen.Interface;
|
||||
using SewerStammGen.Interface.Navigator;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SewerStammGen.Commands
|
||||
{
|
||||
internal class UpdateCurrentViewModelCommand : AsyncCommandBase
|
||||
{
|
||||
private INavigator _navigator;
|
||||
private readonly IViewModelAbstractFactory _viewModelFactory;
|
||||
|
||||
public UpdateCurrentViewModelCommand(INavigator navigator, IViewModelAbstractFactory viewModelFactory)
|
||||
{
|
||||
_navigator = navigator;
|
||||
_viewModelFactory = viewModelFactory;
|
||||
}
|
||||
|
||||
public override async Task ExecuteAsync(object? parameter)
|
||||
{
|
||||
if(parameter is EMainWindowViewType)
|
||||
{
|
||||
EMainWindowViewType viewType = (EMainWindowViewType)parameter;
|
||||
_navigator.CurrentViewModel = _viewModelFactory.CreateViewModel(viewType);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user