Mvvm Pattern erweitert
This commit is contained in:
@@ -23,40 +23,15 @@ namespace KanSan.UI
|
||||
/// </summary>
|
||||
public partial class WindowBaustelleEdit : Window
|
||||
{
|
||||
private UnitOfWork unitOfWork = new UnitOfWork(new KanSanContext());
|
||||
private Baustelle bs = null;
|
||||
|
||||
|
||||
public WindowBaustelleEdit(Baustelle baustelle)
|
||||
public WindowBaustelleEdit()
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
if (baustelle == null) throw new ArgumentNullException("baustelle");
|
||||
|
||||
bs = baustelle;
|
||||
|
||||
BaustelleViewModel model = new BaustelleViewModel(bs);
|
||||
|
||||
|
||||
model.PropertyChanged += Model_PropertyChanged;
|
||||
|
||||
this.DataContext = model;
|
||||
this.DataContext = new BaustelleViewModel();
|
||||
}
|
||||
|
||||
private void Model_PropertyChanged(object sender, PropertyChangedEventArgs e)
|
||||
{
|
||||
BaustelleViewModel baustelleViewModel = (BaustelleViewModel)sender;
|
||||
bs.Ort = baustelleViewModel.Ort;
|
||||
bs.Projektnummer = baustelleViewModel.Projektnummer;
|
||||
bs.Strasse = baustelleViewModel.Strasse;
|
||||
|
||||
unitOfWork.BaustellenRepository.Update(bs);
|
||||
//Debugger.Break();
|
||||
}
|
||||
|
||||
private void Window_Closed(object sender, EventArgs e)
|
||||
{
|
||||
unitOfWork.Commit();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
<RowDefinition />
|
||||
<RowDefinition />
|
||||
<RowDefinition />
|
||||
<RowDefinition />
|
||||
</Grid.RowDefinitions>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition />
|
||||
@@ -25,6 +26,8 @@
|
||||
<Label Grid.Column="0" Grid.Row="3">Plz</Label>
|
||||
<Label Grid.Column="0" Grid.Row="4">Ort</Label>
|
||||
|
||||
<Button Name="Speichern" Content="Speichern" Grid.Row="5" Grid.ColumnSpan="2" Click="Speichern_Click" />
|
||||
|
||||
<TextBox Grid.Column="1" Grid.Row="0" Text="{Binding Vorname}" />
|
||||
<TextBox Grid.Column="1" Grid.Row="1" Text="{Binding Nachname}" />
|
||||
<TextBox Grid.Column="1" Grid.Row="2" Text="{Binding Strasse}" />
|
||||
|
||||
@@ -3,6 +3,7 @@ using KanSan.Base.Models;
|
||||
using KanSan.ViewModel;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Text;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
@@ -21,24 +22,20 @@ namespace KanSan.UI
|
||||
/// </summary>
|
||||
public partial class UCKundeEdit : UserControl
|
||||
{
|
||||
private Kunde kunde = null;
|
||||
private UnitOfWork unitOfWork = null;
|
||||
public UCKundeEdit(Kunde kunde)
|
||||
//private Kunde kunde = null;
|
||||
//private UnitOfWork unitOfWork = null;
|
||||
public UCKundeEdit()
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
this.kunde = kunde;
|
||||
|
||||
unitOfWork = new UnitOfWork(new KanSanContext());
|
||||
|
||||
KundeViewModel kundeViewModel = new KundeViewModel(kunde);
|
||||
kundeViewModel.PropertyChanged += KundeViewModel_PropertyChanged;
|
||||
this.DataContext = kundeViewModel;
|
||||
this.DataContext = new KundeViewModel();
|
||||
}
|
||||
|
||||
private void KundeViewModel_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
|
||||
private void Speichern_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
((KundeViewModel)DataContext).Speichern();
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user