private void DetachHandlers(WorkingFolderViewModel model)
 {
     foreach (KeyValuePair <PropertyChangedEventHandler, WorkingFolderViewModel> handler in eventHandlers.Where(pair => pair.Value == model).ToList())
     {
         handler.Value.PropertyChanged -= handler.Key;
         eventHandlers.Remove(handler.Key);
     }
 }
        public void UpdateCollection(IEnumerable <WorkingFolderViewModel> folders)
        {
            //WorkingFolders.UpdateCollection(folders);
            IEnumerable <WorkingFolderViewModel> workingFolderViewModels = folders as WorkingFolderViewModel[] ?? folders.ToArray();

            if (WorkingFolders != null && WorkingFolders.Any())
            {
                foreach (var model in WorkingFolders)
                {
                    DetachHandlers(model);
                }
            }

            WorkingFolders = new ObservableCollection <WorkingFolderViewModel>(workingFolderViewModels);
            foreach (var folderViewModel in workingFolderViewModels)
            {
                WorkingFolderViewModel model = folderViewModel;
                eventHandlers.Add(folderViewModel?.OnChange(() => model.Projects, RaiseContainedProjectsChanged), model);
            }
            RaisePropertiesChanged(() => ProjectCount, () => HasProjects);
        }
        public ProjectViewModel(string projectFilePath, IServiceProvider serviveProvider, WorkingFolderViewModel parentWorkingFolder)
            : base(serviveProvider)
        {
            ShowErrorContentCommand     = new Common.Commands.DelegateCommand <object>(ShowErrorContent, CanShowErrorContent);
            ShowOptionsPopupCommand     = new Common.Commands.DelegateCommand <Popup>(TogglePopup, CanTogglePopup);
            ShowBuildPropertiesCommand  = new Common.Commands.DelegateCommand <object>(EditBuildProperties);
            ShowBuildTargetsCommand     = new Common.Commands.DelegateCommand <object>(EditBuildTargets);
            SlideToOptionsCommand       = new Common.Commands.DelegateCommand <PageTransition>(ExecuteSlideToOptions);
            RemoveCustomSolutionCommand = new Common.Commands.DelegateCommand <object>(RemoveCustomSolution, CanRemoveCustomSolution);
            CancelCommand = new Common.Commands.DelegateCommand <IOperationService>(CancelOperation, CanCancelOperation);

            ItemPath            = projectFilePath;
            ParentWorkingFolder = parentWorkingFolder;
            SetDefaultImageValues();
            var settings = Settings;

            if (settings != null)
            {
                isIncluded    = settings.Get(this.IsIncludedKey(), GetIsProjectDefaultIncluded());
                buildPriority = settings.Get(this.BuildPriorityKey(), GetDefaultBuildPriority());
            }
            BeginLoadPendingChanges();
        }