Refresh combobox list from other window, MVVM

前端 未结 6 1917
长情又很酷
长情又很酷 2021-01-21 10:53

I\'m working on some application and I have one problem. I have two windows (Bookings - parent and Guests - child). In the parent window, I have one combo box with list of guest

6条回答
  •  太阳男子
    2021-01-21 11:15

    OK, I added this lines in my "GuestsViewModel.cs":

        private BookingsViewModel _BookingsViewModel;
        public BookingsViewModel BookViewModel    // Property
        {
            get
            {
                return _BookingsViewModel;
            }
            set
            {
                _BookingsViewModel = value;
                OnPropertyChanged("BookViewModel");
            }
        }
    
        public GuestsViewModel(BookingsViewModel bvm)    // Constructor with one parameter
        {
            BookViewModel = bvm;
        }
    
        public ICommand _btnAddGuest;
        public ICommand btnAddGuest 
        {
            get
            {
                if (_btnAddGuest == null)
                {
                    _btnAddGuest = new DelegateCommand(delegate()
                    {
                        try
                        {
                            Service1Client wcf = new Service1Client();                           
    
                            wcf.AddGuest(Guest);
                            BookingsViewModel.OnPropertyChanged("Guests");    // You said to add this
                            wcf.Close();
                        }
                        catch
                        {
                            Trace.WriteLine("working...", "MyApp");
                        }
                    });
                }
                return _btnAddGuest;
            }
        }
    

    Did you mean something like this above? This don't work... I suppose I should add one more thing? Sorry, maybe this questions are stupid but I don't have idea how to solve this problem...

    Regards, Vladimir

提交回复
热议问题