IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Windows Presentation Foundation Discussion :

Des nombreuses fenêtres apparaissent en cliquant sur le bouton ADD -MVVM WPF


Sujet :

Windows Presentation Foundation

  1. #1
    Nouveau membre du Club
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Décembre 2015
    Messages
    23
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 37
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Décembre 2015
    Messages : 23
    Points : 28
    Points
    28
    Par défaut Des nombreuses fenêtres apparaissent en cliquant sur le bouton ADD -MVVM WPF
    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:
    Nom : addalways.PNG
Affichages : 178
Taille : 96,6 Ko

    Merci,

  2. #2
    Nouveau membre du Club
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Décembre 2015
    Messages
    23
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 37
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Décembre 2015
    Messages : 23
    Points : 28
    Points
    28
    Par défaut
    Bonjour,
    j'ai trouvé la solution,

    il faut modifier les fonctions add et ADDFunction situé dans ViewModel

    alors:

    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
    private Add addView;
    private void add(object obj)
     
        if (addView != null)
            addView.Close();
     
        addView = new Add();
        addView.DataContext = this;
        addView.Show();
    }
     
    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);
     
        if (addView != null)
            addView.Close();
        CustomerToAddObject = new Custmor();
    }

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. [Python 3.X] Changer le contenu de la fenêtre Tk() en cliquant sur un bouton
    Par psychozz dans le forum Tkinter
    Réponses: 4
    Dernier message: 07/08/2022, 10h38
  2. Ouvrir une fenêtre en cliquant sur un bouton
    Par Versace31 dans le forum Interfaces Graphiques en Java
    Réponses: 6
    Dernier message: 10/02/2009, 21h43
  3. Réponses: 1
    Dernier message: 18/11/2008, 09h24
  4. Réponses: 1
    Dernier message: 14/08/2006, 09h41
  5. [PHP-JS] ajouter des champ en cliquant sur un bouton?
    Par einsteineuzzz dans le forum Langage
    Réponses: 3
    Dernier message: 29/06/2006, 17h36

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo