简体   繁体   中英

How to not open the same Popup WPF MVVM?

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

不要重新打开它们,只需将弹出窗口的 DataContext 绑定到当前用户,例如将在按钮点击时更改的“CurrentUser”属性,并引发其属性更改事件。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM