Löschen Knopf

This commit is contained in:
2025-06-02 16:26:06 +02:00
parent 3f2bd74438
commit 5b2b05ed55
3 changed files with 31 additions and 3 deletions

View File

@@ -1,6 +1,7 @@
using FahrzeugDatenBank;
using System.Collections.ObjectModel;
using System.Timers;
using System.Windows.Input;
namespace FahzeugWPF;
@@ -19,11 +20,19 @@ class MainWindowViewModel : ViewModelBase
this._timer.Start();
this._model = modell;
this.InitialisiereDasViewModell();
this.LoeschenKommando = new RelayCommand(LoescheFahrzeug);
}
public string MainWindowTitle { get { return _mainWindowTitle; } set {
public ICommand LoeschenKommando { get; private set; }
public string MainWindowTitle
{
get { return _mainWindowTitle; }
set
{
SetProperty<string>(ref _mainWindowTitle, value);
} }
}
}
public ObservableCollection<Fahrzeug> Fahrzeuge { get; } = new ObservableCollection<Fahrzeug>();
@@ -40,4 +49,11 @@ class MainWindowViewModel : ViewModelBase
{
this.MainWindowTitle = $"Fahrzeuge {DateTime.Now.ToLongTimeString()}";
}
private void LoescheFahrzeug(object? fahrzeug)
{
if (fahrzeug == null) return;
_model.LoescheFahrzeug((Fahrzeug)fahrzeug);
this.Fahrzeuge.Remove((Fahrzeug)fahrzeug);
}
}