public void AddDocument(DockWindowViewModel document, string title)
 {
     document.Title       = title;
     document.IsClosed    = false;
     document.DockManager = this;
     if (!this.Documents.Contains(document))
     {
         document.PropertyChanged += DockWindowViewModel_PropertyChanged;
         this.Documents.Add(document);
     }
     document.IsSelected = true;
     document.IsActive   = true;
 }
        private void DockWindowViewModel_PropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            DockWindowViewModel document = sender as DockWindowViewModel;

            switch (e.PropertyName)
            {
            case nameof(DockWindowViewModel.IsClosed):
                if (document.IsClosed)
                {
                    this.Documents.Remove(document);
                }
                break;

            case nameof(DockWindowViewModel.IsActive):
                if (document.IsActive && SelectedDocument != document)
                {
                    SelectedDocument = document;
                    RaisePropertyChanged(() => this.SelectedDocument);
                    SelectedItem = null;
                    RaisePropertyChanged(() => this.SelectedItem);
                }
                break;

            case "SelectedItem":
                if (sender is AccountsViewModel)
                {
                    SelectedItem = ((AccountsViewModel)sender).SelectedItem;
                }
                if (sender is PersonsViewModel)
                {
                    SelectedItem = ((PersonsViewModel)sender).SelectedItem;
                }
                if (sender is RatesViewModel)
                {
                    SelectedItem = ((RatesViewModel)sender).SelectedItem;
                }
                if (sender is ServicesViewModel)
                {
                    SelectedItem = ((ServicesViewModel)sender).SelectedItem;
                }
                if (sender is PaymentDetailViewModel)
                {
                    var item = ((PaymentDetailViewModel)sender).SelectedItem;
                    if (null == item)
                    {
                        return;
                    }
                    SelectedItem = item;
                }
                if (sender is PaymentsViewModel)
                {
                    SelectedItem = ((PaymentsViewModel)sender).SelectedItem;
                }
                if (sender is UnpaidPaymentsViewModel)
                {
                    var item = ((UnpaidPaymentsViewModel)sender).SelectedItem;
                    if (null == item)
                    {
                        return;
                    }
                    SelectedItem = item;
                }
                RaisePropertyChanged(() => this.SelectedItem);
                break;
            }
        }