/// <summary>
        /// Refreshes the <see cref="TimelineSegmentProvidingViewModelBase.SegmentViewModels"/> collection
        /// so that each model in the <see cref="TimelineSegmentProvidingViewModelBase.SegmentModels"/> collection
        /// has a corresponding view model for interacting with the timeline and video overlay views.
        /// </summary>
        protected virtual void RefreshSegmentViewModels()
        {
            SegmentViewModels.CollectionChanged -= OnSegmentViewModelsCollectionChanged;

            if (SegmentModels != null)
            {
                SegmentModels.CollectionChanged -= OnSegmentModelsCollectionChanged;

                // Remove excess items
                if (SegmentViewModels.Count > SegmentModels.Count)
                {
                    for (int i = SegmentViewModels.Count - 1; i >= SegmentModels.Count; i--)
                    {
                        SegmentViewModels.RemoveAt(i);
                    }
                    Debug.Assert(SegmentViewModels.Count == SegmentModels.Count);
                }

                for (int i = 0; i < SegmentModels.Count; i++)
                {
                    if (i < SegmentViewModels.Count)
                    {
                        if (!SegmentViewModels[i].Model.Equals(SegmentModels[i]))
                        {
                            SegmentViewModels[i] = SegmentViewModelFactory.CreateSegmentViewModel(SegmentModels[i]);
                        }
                    }
                    else
                    {
                        SegmentViewModels.Add(SegmentViewModelFactory.CreateSegmentViewModel(SegmentModels[i]));
                    }
                }

                SegmentModels.CollectionChanged += OnSegmentModelsCollectionChanged;
            }
            else
            {
                SegmentViewModels.Clear();
            }

            SegmentViewModels.CollectionChanged += OnSegmentViewModelsCollectionChanged;
        }
        /// <summary>
        /// Handles the <see cref="IProjectService.ProjectClosing"/> event for the <see cref="_projectService"/> instance.
        /// </summary>
        /// <inheritdoc cref="EventHandler"/>
        protected virtual void OnProjectClosing(object sender, EventArgs e)
        {
            _scriptVideoService.FrameChanged    -= OnScriptVideoFrameNumberChanged;
            SegmentModels.CollectionChanged     -= OnSegmentModelsCollectionChanged;
            SegmentViewModels.CollectionChanged -= OnSegmentViewModelsCollectionChanged;

            if (SelectedSegment != null)
            {
                SelectedSegment.PropertyChanged -= OnSelectedSegmentInstancePropertyChanged;
                SelectedSegment = null;
            }

            _undoRoot.Clear();
            _activeSegmentDictionary.Clear();
            SegmentViewModels.Clear();

            RaisePropertyChanged(nameof(ActiveSegments));
            RaisePropertyChanged(nameof(SegmentViewModels));
            RaisePropertyChanged(nameof(UndoStack));
            RaisePropertyChanged(nameof(RedoStack));
        }