Bonjour,
Lorsque je clique sur le bouton ADD, j'ai une nouvelle fenêtre apparaît . J'ajoute le nouveau client, le DataGrid refresh mais juste la première fois! Ensuite, chaque fois que je clique sur Button Add, j'ai une nouvelle fenêtre avec les mêmes informations et ainsi de suite ... Je reçois de nombreuses fenêtres ADD !!
ViewModel:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78 private ObservableCollection<Custmor> _loadDataBinding; public ObservableCollection<Custmor> loadDataBinding { get { return _loadDataBinding; } set { _loadDataBinding = value; OnPropertyChanged("loadDataBinding"); } } public ViewModel1() { //Display my DataGrid using (Test1Entities context = new Test1Entities()) { _loadDataBinding = new ObservableCollection<Custmor>(context.Custmor.ToList()); } //To Show the Window ADD from Window MainWindow addCustomerMainWindow = new RelayCommand(add, canexecute); CustomerToAddObject = new Custmor(); addCustomer1 = new RelayCommand(ADDFunction); } //To Show the Window ADD from Window MainWindow private ICommand addCustomerMainWindow; public ICommand AddCustomerMainWindow { get { return addCustomerMainWindow; } } private void add(object obj) { Add addView = new Add(); addView.DataContext = this; addView.Show(); } //The Button ADD from Window ADD private ICommand addCustomer1; public ICommand AddCustomer1 { get { return addCustomer1; } } private void ADDFunction(object obj) { using (Test1Entities context = new Test1Entities()) { context.Custmor.Add(customerToAddObject); context.SaveChanges(); MessageBox.Show("Customer a été ajouté avec succès!"); } _loadDataBinding.Add(CustomerToAddObject); } //textBox for window ADD: CustomerToAddObject.nom ;CustomerToAddObject.prenom and CustomerToAddObject.reference private Custmor customerToAddObject; public Custmor CustomerToAddObject { get { return customerToAddObject; } set { customerToAddObject = value; } }
Comment puis-je le corriger lorsque j'ajoute nouvelle Customer, la fenêtre ADD se ferme, et Mainwindow ne ferme pas? Cliquez sur le bouton ADD et ajouter plusieurs nouveaux Customers autant de fois que je le souhaite?
Le résultat de mon erreur:
Merci,
Partager