How to not open the same Popup WPF MVVM?

190 Views Asked by At

In my a list of users I have User1, User 2, User 3:

When I double-click on User1, it displays the information in a Popup which remains open

When I double-click on User2, it displays the information in a Popup which remains open

But when I do another double-click on the same user always User1 in the list of User, another popup opens again when I already open!

How to not open the same Popup WPF MVVM?

   private void Edit(UtilisateurListeViewModel user)
   {
        if (user == null) return;
        if (AuthentifiedUser != null && (user.Asp == AuthentifiedUser.Code_Nego) && (!UtilisateurService.CheckUserRight

(DroitUtilisateur.GeneralUtilisateurModifierPropreCompte_5)))
                PopupNotificationViewModel.ShowPopup(PopupContentType.Avertissement, "Vous n'avez pas les droits requis pour 

ouvrir la fiche.");
            else
            {
                CurrentWindowViewModel = new SaisieUtilisateurViewModel(UtilisateurService, user.Asp.ToString(), 

user.CodeSociete, user.CodeSite, ListeItems, SetCurrentWindow, IsReadOnly);
                SetCurrentWindow(CurrentWindowViewModel);
                ListeWindowViewModels.Add(CurrentWindowViewModel);
                CurrentWindowViewModel.ShowPopup();
            }
        }

        public override void SetCurrentWindow(object currentWindow, bool isClosed = false)
        {
            if (currentWindow == null)
                return; 
            if (isClosed)
            {      this.ListeWindowViewModels.Remove((SaisieUtilisateurViewModel)currentWindow);
                currentWindow = this.ListeWindowViewModels.FirstOrDefault();
            }

            if (this.CurrentWindowViewModel == currentWindow)
                return;
            this.CurrentWindowViewModel = (SaisieUtilisateurViewModel)currentWindow;
            if (currentWindow != null && ((SaisieUtilisateurViewModel)currentWindow).UserVM != null)
                this.ListeItems.SetCurrentItem(((SaisieUtilisateurViewModel)currentWindow).UserVM.Asp);
        }

public IPopupModalWindow Popup { get; set; }

public virtual void ShowPopup()
        {
            if (UserVM == null) return;

            if (!WindowMngt.StoreContains(Popup as Window)) 

         //   if (!WindowMngt.StoreContains(Popup as SaisieUtilisateur))
            {

             if (Popup == null)
                {
                    Popup = new SaisieUtilisateur();

                    ((Window) Popup).DataContext = this;
                }
                Popup.ShowPopup();
            }
            else
                WindowMngt.ActivateWindow(Popup as Window); 
        }




    public void ShowPopup()
        {
            this.Owner = Application.Current.MainWindow;
 this.WindowStartupLocation = System.Windows.WindowStartupLocation.CenterOwner;

            this.Show();
        }

Thanks

1

There are 1 best solutions below

0
On

Dont Reopen them, just bind the popup's DataContext to the current user, for example "CurrentUser" Property that will be changed on button clicks, and raise its property changed event.