Refresh combobox list from other window, MVVM

前端 未结 6 1913
长情又很酷
长情又很酷 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:21

    Just use your already existent connection to your GuestViewModel from your BookingsViewModel.

    The following suggestion is not tested but you will get the idea

    public ICommand btnAddGuest    // Command for opening child window
        {
            get
            {
                if (_btnAddGuest == null)
                {
                    _btnAddGuest = new DelegateCommand(delegate()
                    {
                        try
                        {
                            Guests guest = new Guests();
                            guest.ShowDialog();
    
                            // Add some Logic here and an is save check property to your GuestVM
                            // sample solution
                            // var vm = guest.DataContext as GuestViewModel;
                            // if(vm != null)
                            //     if(vm.IsSaved)
                            //     {
                            //         var model = vm.Guest as tblGuest;
                            //         Guests.Add(model);                // will add him to your list
                            //         Guest = model                     // will add him at your selected Guest
                            //     }
                        }
                        catch
                        {
                            Trace.WriteLine("working...", "MyApp");
                        }
                    });
                }
                return _btnAddGuest;
            }
        }
    

提交回复
热议问题