Navigation zwischen views Funktioniert
This commit is contained in:
@@ -1,20 +1,8 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DaSaSo.ViewModel
|
||||
namespace DaSaSo.ViewModel
|
||||
{
|
||||
public class BaseViewModel : INotifyPropertyChanged
|
||||
public class BaseViewModel : ObservableObject
|
||||
{
|
||||
public event PropertyChangedEventHandler? PropertyChanged;
|
||||
protected virtual void OnPropertyChanged([CallerMemberName] string? propertyName = null)
|
||||
{
|
||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using DaSaSo.Domain.Model;
|
||||
using DaSaSo.Domain.Services;
|
||||
using DaSaSo.ViewModel.Commands;
|
||||
using DaSaSo.ViewModel.Enums;
|
||||
using DaSaSo.ViewModel.Interface;
|
||||
using Microsoft.Toolkit.Mvvm.Input;
|
||||
using System;
|
||||
@@ -19,11 +20,12 @@ namespace DaSaSo.ViewModel
|
||||
public ObservableCollection<Client> Clients { get; }
|
||||
private Client? _selectedClient;
|
||||
private IDataService<Client> _dataService;
|
||||
private readonly IRenavigator renavigator;
|
||||
IEnumerable<Client>? result;
|
||||
bool _isLoading = true;
|
||||
|
||||
public ICommand SelectCommand { get; set; }
|
||||
public IRelayCommand EditClientCommand { get; set; }
|
||||
public ICommand EditCommand { get; set; }
|
||||
public IRelayCommand AddNewClientCommand { get; set; }
|
||||
|
||||
public Client SelectedClient
|
||||
@@ -54,19 +56,25 @@ namespace DaSaSo.ViewModel
|
||||
}
|
||||
}
|
||||
|
||||
public ClientListViewModel(IDataService<Client> dataService, IActualProject actualProject)
|
||||
public ClientListViewModel(IDataService<Client> dataService, IActualProject actualProject, IRenavigator renavigator)
|
||||
{
|
||||
Clients = new ObservableCollection<Client>();
|
||||
_dataService = dataService;
|
||||
|
||||
|
||||
this.renavigator = renavigator;
|
||||
LoadClient();
|
||||
SelectCommand = new SelectClientCommand(actualProject,this); //= new RelayCommand(SelectClient, () => SelectedClient != null);
|
||||
SelectCommand = new SelectClientCommand(actualProject, this); //= new RelayCommand(SelectClient, () => SelectedClient != null);
|
||||
EditCommand = new EditClientCommand(actualProject,renavigator,this);
|
||||
//EditClientCommand = new RelayCommand(EditClient, () => SelectedClient != null);
|
||||
//AddNewClientCommand = new RelayCommand(AddNewClient);
|
||||
|
||||
}
|
||||
|
||||
private void edit()
|
||||
{
|
||||
|
||||
//_navigator.UpdateViewModelCommand.Execute(EViewType.ClientEdit);
|
||||
}
|
||||
|
||||
private async Task<Client> insertNewClient()
|
||||
{
|
||||
Client newClient = new Client()
|
||||
|
||||
40
DaSaSo.ViewModel/Commands/EditClientCommand.cs
Normal file
40
DaSaSo.ViewModel/Commands/EditClientCommand.cs
Normal file
@@ -0,0 +1,40 @@
|
||||
using DaSaSo.ViewModel.Interface;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Input;
|
||||
|
||||
namespace DaSaSo.ViewModel.Commands
|
||||
{
|
||||
public class EditClientCommand : ICommand
|
||||
{
|
||||
private readonly IActualProject actualProject;
|
||||
private readonly IRenavigator renavigator;
|
||||
private readonly ClientListViewModel clientListViewModel;
|
||||
|
||||
public event EventHandler? CanExecuteChanged;
|
||||
|
||||
|
||||
|
||||
public EditClientCommand(IActualProject actualProject,IRenavigator renavigator, ClientListViewModel clientListViewModel)
|
||||
{
|
||||
this.actualProject = actualProject;
|
||||
this.renavigator = renavigator;
|
||||
this.clientListViewModel = clientListViewModel;
|
||||
}
|
||||
|
||||
public bool CanExecute(object? parameter)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public void Execute(object? parameter)
|
||||
{
|
||||
actualProject.SetClient(clientListViewModel.SelectedClient);
|
||||
renavigator.Renavigate();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -13,15 +13,17 @@ namespace DaSaSo.ViewModel.Factories
|
||||
public class ClientListViewModelFactory : IViewModelFactory<ClientListViewModel>
|
||||
{
|
||||
private readonly IActualProject _actualProject;
|
||||
private readonly IRenavigator renavigator;
|
||||
|
||||
public ClientListViewModelFactory(IActualProject actualProject)
|
||||
public ClientListViewModelFactory(IActualProject actualProject, IRenavigator renavigator)
|
||||
{
|
||||
_actualProject = actualProject;
|
||||
this.renavigator = renavigator;
|
||||
}
|
||||
|
||||
public ClientListViewModel CreateViewModel()
|
||||
{
|
||||
return new ClientListViewModel(new GenericDataService<Client>(new DaSaSoDbContextFactory()),_actualProject);
|
||||
return new ClientListViewModel(new GenericDataService<Client>(new DaSaSoDbContextFactory()),_actualProject, renavigator);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,10 +9,15 @@ namespace DaSaSo.ViewModel.Interface
|
||||
{
|
||||
public interface IActualProject
|
||||
{
|
||||
event EventHandler? ClientChanged;
|
||||
event EventHandler? ProjectChanged;
|
||||
event EventHandler? BuildingSiteChanged;
|
||||
Client AktuellClient { get; }
|
||||
Project AktuellProjekt { get; }
|
||||
Buildingsite AktuellBaustelle { get; }
|
||||
|
||||
void SetClient(Client client);
|
||||
void SetProject(Project project);
|
||||
void SetBuildingSite(Buildingsite buildingsite);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,6 +10,6 @@ namespace DaSaSo.ViewModel.Interface
|
||||
public interface INavigator
|
||||
{
|
||||
BaseViewModel CurrentViewModel { get; set; }
|
||||
ICommand UpdateViewModelCommand { get; }
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
13
DaSaSo.ViewModel/Interface/IRenavigator.cs
Normal file
13
DaSaSo.ViewModel/Interface/IRenavigator.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DaSaSo.ViewModel.Interface
|
||||
{
|
||||
public interface IRenavigator
|
||||
{
|
||||
void Renavigate();
|
||||
}
|
||||
}
|
||||
19
DaSaSo.ViewModel/ObservableObject.cs
Normal file
19
DaSaSo.ViewModel/ObservableObject.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DaSaSo.ViewModel
|
||||
{
|
||||
public class ObservableObject : INotifyPropertyChanged
|
||||
{
|
||||
public event PropertyChangedEventHandler? PropertyChanged;
|
||||
protected virtual void OnPropertyChanged([CallerMemberName] string? propertyName = null)
|
||||
{
|
||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -11,14 +11,42 @@ namespace DaSaSo.ViewModel.State.ActualState
|
||||
public class ActualProject : IActualProject
|
||||
{
|
||||
public Client AktuellClient { get; private set; }
|
||||
|
||||
public Buildingsite AktuellBaustelle { get; private set; }
|
||||
public Project AktuellProjekt { get; private set; }
|
||||
|
||||
public Project AktuellProjekt { get; private set; }
|
||||
|
||||
#region events
|
||||
public event EventHandler? ClientChanged;
|
||||
public event EventHandler? ProjectChanged;
|
||||
public event EventHandler? BuildingSiteChanged;
|
||||
protected void OnClientChanged()
|
||||
{
|
||||
ClientChanged?.Invoke(this, new EventArgs());
|
||||
}
|
||||
protected void OnProjectChanged()
|
||||
{
|
||||
ProjectChanged?.Invoke(this, new EventArgs());
|
||||
}
|
||||
protected void OnBuildingSiteChanged()
|
||||
{
|
||||
BuildingSiteChanged?.Invoke(this, new EventArgs());
|
||||
}
|
||||
#endregion
|
||||
public void SetClient(Client client)
|
||||
{
|
||||
AktuellClient = client;
|
||||
OnClientChanged();
|
||||
}
|
||||
|
||||
public void SetProject(Project project)
|
||||
{
|
||||
AktuellProjekt = project;
|
||||
OnProjectChanged();
|
||||
}
|
||||
|
||||
public void SetBuildingSite(Buildingsite buildingsite)
|
||||
{
|
||||
AktuellBaustelle = buildingsite;
|
||||
OnBuildingSiteChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,9 +6,9 @@ using System.Windows.Input;
|
||||
|
||||
namespace DaSaSo.ViewModel.State.Navigation
|
||||
{
|
||||
public class Navigator : INavigator, INotifyPropertyChanged
|
||||
public class Navigator : ObservableObject, INavigator
|
||||
{
|
||||
public event PropertyChangedEventHandler? PropertyChanged;
|
||||
|
||||
private BaseViewModel _currentViewModel;
|
||||
public BaseViewModel CurrentViewModel
|
||||
{
|
||||
@@ -19,17 +19,5 @@ namespace DaSaSo.ViewModel.State.Navigation
|
||||
OnPropertyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
public ICommand UpdateViewModelCommand { get; set; }
|
||||
|
||||
public Navigator(IViewModelAbstractFactory viewModelFactory)
|
||||
{
|
||||
UpdateViewModelCommand = new UpdateCurrentViewModelCommand(this, viewModelFactory);
|
||||
}
|
||||
|
||||
protected void OnPropertyChanged([CallerMemberName]string propertyName = null)
|
||||
{
|
||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
using DaSaSo.ViewModel.Interface;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DaSaSo.ViewModel.State.Navigation
|
||||
{
|
||||
public class ViewModelFactoryRenavigator<TViewModel> : IRenavigator where TViewModel : BaseViewModel
|
||||
{
|
||||
private readonly INavigator _navigator;
|
||||
private readonly IViewModelFactory<TViewModel> _viewModelFactory;
|
||||
|
||||
public ViewModelFactoryRenavigator(INavigator navigator, IViewModelFactory<TViewModel> viewModelFactory)
|
||||
{
|
||||
_navigator = navigator;
|
||||
_viewModelFactory = viewModelFactory;
|
||||
}
|
||||
|
||||
public void Renavigate()
|
||||
{
|
||||
_navigator.CurrentViewModel = _viewModelFactory.CreateViewModel();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
using DaSaSo.Domain.Model;
|
||||
using DaSaSo.EntityFramework;
|
||||
using DaSaSo.EntityFramework.Services;
|
||||
using DaSaSo.ViewModel.Commands;
|
||||
using DaSaSo.ViewModel.Enums;
|
||||
using DaSaSo.ViewModel.Interface;
|
||||
using DaSaSo.ViewModel.State.Navigation;
|
||||
@@ -17,87 +18,78 @@ namespace DaSaSo.ViewModel
|
||||
{
|
||||
public sealed class MainWindowViewModel : BaseViewModel
|
||||
{
|
||||
|
||||
private Client _selectedClient;
|
||||
private Project _selectedProject;
|
||||
private Buildingsite _selectedBuildingsite;
|
||||
private readonly IViewModelAbstractFactory viewModelFactory;
|
||||
private readonly IActualProject _actualProject;
|
||||
private string _clientname = "";
|
||||
private string _projektname = "";
|
||||
private string _buildingsitename = "";
|
||||
|
||||
public INavigator Navigator { get; set; }
|
||||
public ICommand UpdateCurrentViewModelCommand { get; }
|
||||
|
||||
public Project SelectedProject
|
||||
public string ClientName
|
||||
{
|
||||
get => _selectedProject;
|
||||
get => _clientname;
|
||||
set
|
||||
{
|
||||
if(_selectedProject != value)
|
||||
if(_clientname != value)
|
||||
{
|
||||
_selectedProject = value;
|
||||
OnPropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
public Buildingsite SelectedBuildingsite
|
||||
{
|
||||
get => _selectedBuildingsite;
|
||||
set
|
||||
{
|
||||
if(_selectedBuildingsite != value)
|
||||
{
|
||||
_selectedBuildingsite = value;
|
||||
_clientname = value;
|
||||
OnPropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Client SelectedClient
|
||||
public string Projektname
|
||||
{
|
||||
get => _selectedClient;
|
||||
get => _projektname;
|
||||
set
|
||||
{
|
||||
if(_selectedClient != value)
|
||||
if (_projektname != value)
|
||||
{
|
||||
_selectedClient = value;
|
||||
//SelectedProject = null;
|
||||
_projektname = value;
|
||||
OnPropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
public MainWindowViewModel(INavigator navigator)
|
||||
public string Buildingsitename
|
||||
{
|
||||
get => _buildingsitename;
|
||||
set
|
||||
{
|
||||
if (_buildingsitename != value)
|
||||
{
|
||||
_buildingsitename = value;
|
||||
OnPropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public MainWindowViewModel(INavigator navigator,IViewModelAbstractFactory viewModelFactory, IActualProject actualProject)
|
||||
{
|
||||
this.Navigator = navigator;
|
||||
Navigator.UpdateViewModelCommand.Execute(EViewType.Home);
|
||||
|
||||
|
||||
Mediator.Subscribe(Enums.EMediator.SELECTEDCLIENT, (tt) =>
|
||||
{
|
||||
SelectedClient = (Client)tt;
|
||||
listProjecte();
|
||||
});
|
||||
|
||||
Mediator.Subscribe(Enums.EMediator.EDITCLIENT, (tt) =>
|
||||
{
|
||||
|
||||
});
|
||||
Mediator.Subscribe(Enums.EMediator.SHOWCLIENT, (tt) => {
|
||||
|
||||
});
|
||||
this.viewModelFactory = viewModelFactory;
|
||||
UpdateCurrentViewModelCommand = new UpdateCurrentViewModelCommand(navigator, viewModelFactory);
|
||||
UpdateCurrentViewModelCommand.Execute(EViewType.Home);
|
||||
_actualProject = actualProject;
|
||||
_actualProject.ClientChanged += _actualProject_ClientChanged;
|
||||
_actualProject.ProjectChanged += _actualProject_ProjectChanged;
|
||||
_actualProject.BuildingSiteChanged += _actualProject_BuildingSiteChanged;
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void listSewerObjects()
|
||||
private void _actualProject_BuildingSiteChanged(object? sender, EventArgs e)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
Buildingsitename = _actualProject.AktuellBaustelle.BuildingSiteNumber;
|
||||
}
|
||||
|
||||
private void listBuildingsite()
|
||||
private void _actualProject_ProjectChanged(object? sender, EventArgs e)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
Projektname = _actualProject.AktuellProjekt.Name;
|
||||
}
|
||||
|
||||
private void listProjecte()
|
||||
private void _actualProject_ClientChanged(object? sender, EventArgs e)
|
||||
{
|
||||
|
||||
ClientName = _actualProject.AktuellClient.Firstname;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,8 +37,11 @@ namespace DaSaSo.Wpf
|
||||
|
||||
services.AddSingleton<IViewModelAbstractFactory, ViewModelAbstractFactory>();
|
||||
services.AddSingleton<IViewModelFactory<HomeViewModel>, HomeViewModelFactory>();
|
||||
services.AddSingleton<IRenavigator, ViewModelFactoryRenavigator<ClientEditViewModel>>();
|
||||
services.AddSingleton<IViewModelFactory<ClientListViewModel>, ClientListViewModelFactory>();
|
||||
services.AddSingleton<IViewModelFactory<ClientEditViewModel>, ClientEditViewModelFactory>();
|
||||
|
||||
//services.AddSingleton<INavigator, Navigator>();
|
||||
services.AddScoped<IActualProject, ActualProject>();
|
||||
services.AddScoped<INavigator, Navigator>();
|
||||
|
||||
|
||||
@@ -14,9 +14,9 @@
|
||||
<RowDefinition Height="auto" />
|
||||
<RowDefinition Height="auto" />
|
||||
</Grid.RowDefinitions>
|
||||
<RadioButton Grid.Row="0" Content="Kunden" Style="{StaticResource ToggleButtonList}" Command="{Binding UpdateViewModelCommand}" CommandParameter="{x:Static nav:EViewType.Clients}" />
|
||||
<RadioButton Grid.Row="1" Content="Projekte" Style="{StaticResource ToggleButtonList}" Command="{Binding UpdateViewModelCommand}" CommandParameter="{x:Static nav:EViewType.ClientEdit}" />
|
||||
<RadioButton Grid.Row="2" Content="Baustellen" Style="{StaticResource ToggleButtonList}" Command="{Binding UpdateViewModelCommand}" CommandParameter="{x:Static nav:EViewType.Buildingsites}" />
|
||||
<RadioButton Grid.Row="3" Content="Objekten" Style="{StaticResource ToggleButtonList}" Command="{Binding UpdateViewModelCommand}" CommandParameter="{x:Static nav:EViewType.SewerObjects}" />
|
||||
<RadioButton Grid.Row="0" Content="Kunden" Style="{StaticResource ToggleButtonList}" Command="{Binding UpdateCurrentViewModelCommand}" CommandParameter="{x:Static nav:EViewType.Clients}" />
|
||||
<RadioButton Grid.Row="1" Content="Projekte" Style="{StaticResource ToggleButtonList}" Command="{Binding UpdateCurrentViewModelCommand}" CommandParameter="{x:Static nav:EViewType.ClientEdit}" />
|
||||
<RadioButton Grid.Row="2" Content="Baustellen" Style="{StaticResource ToggleButtonList}" Command="{Binding UpdateCurrentViewModelCommand}" CommandParameter="{x:Static nav:EViewType.Buildingsites}" />
|
||||
<RadioButton Grid.Row="3" Content="Objekten" Style="{StaticResource ToggleButtonList}" Command="{Binding UpdateCurrentViewModelCommand}" CommandParameter="{x:Static nav:EViewType.SewerObjects}" />
|
||||
</Grid>
|
||||
</UserControl>
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
<TextBlock Text="Kundenliste" />
|
||||
<ListView ItemsSource="{Binding Clients}" DisplayMemberPath="Firstname" SelectedItem="{Binding SelectedClient, Mode=TwoWay}"/>
|
||||
<Button Content="Kunde auswählen" Command="{Binding SelectCommand}" />
|
||||
<Button Content="Kunde Editieren" Command="{Binding EditClientCommand}"/>
|
||||
<Button Content="Kunde Editieren" Command="{Binding EditCommand}"/>
|
||||
<Button Content="Kunde Hinzufügen" Command="{Binding AddNewClientCommand}" />
|
||||
</StackPanel>
|
||||
<Border Background="Gray" d:Visibility="Hidden" Visibility="{Binding IsLoading, Converter={StaticResource BooleanToVisibilityConverter}}">
|
||||
|
||||
@@ -33,10 +33,10 @@
|
||||
<RowDefinition />
|
||||
<RowDefinition Height="20" />
|
||||
</Grid.RowDefinitions>
|
||||
<controls:NavigationBar Grid.Column="0" Grid.Row="0" DataContext="{Binding Navigator }" />
|
||||
<controls:NavigationBar Grid.Column="0" Grid.Row="0"/>
|
||||
<ContentControl Grid.Column="1" Grid.Row="0" Content="{Binding Navigator.CurrentViewModel}" />
|
||||
<StatusBar Grid.Row="1" Grid.ColumnSpan="2">
|
||||
<StatusBarItem Content="{Binding SelectedClient.Firstname}" />
|
||||
<StatusBarItem Content="{Binding ClientName}" />
|
||||
</StatusBar>
|
||||
</Grid>
|
||||
</Window>
|
||||
|
||||
Reference in New Issue
Block a user