public ElectricalEquipmentAttachmentsViewModel(ElectricalEquipment electricalEquipment, ElectricalAttachmentsControl view)
        {
            CompositionInitializer.SatisfyImports(this);

            View = view;

            AddAttachmentCommand = new DelegateCommand<object>(AddFileHandler, CanAdd);
            RemoveAttachmentCommand = new DelegateCommand<object>(DeleteButtonHandler, CanDelete);
            ExportButton = new DelegateCommand<object>(ExportButtonHandler, x => true);

            mElectricalEquipment = electricalEquipment;

            Attachments = new ObservableCollection<ElectricalEquipmentAttachment>();

            CmsWebServiceClient cmsWebServiceClient = new CmsWebServiceClient(Utils.WcfBinding, Utils.WcfEndPoint);
            cmsWebServiceClient.GetAttachmentTypesCompleted += cmsWebServiceClient_GetAttachmentTypesCompleted;
            cmsWebServiceClient.GetAttachmentTypesAsync();
        }
        private void ViewModel_DataSourceLoaded(object obj)
        {
            mElectricalEquipment = ViewModel.Equipment;
            DataContext = ViewModel;

            //Components
            mComponentsControl = new ElectricalEquipmentComponentsControl(ViewModel.Equipment);
            mComponentsControl.CollectionChanged += (count) =>
                {
                    mElectricalEquipment.GeneralEquipmentRelatedItemsCount.PropertyOrComponents = count;
                    SetTabHeadersText();
                };

            ComponentsTab.Content = mComponentsControl;
            mComponentsLoaded = true;

            //Issues
            mElectricalRelatedIssuesControl = new ElectricalRelatedIssuesControl(ViewModel.Equipment);
            mElectricalRelatedIssuesControl.CollectionChanged += (count) =>
                {
                    mElectricalEquipment.GeneralEquipmentRelatedItemsCount.Issues = count;
                    SetTabHeadersText();
                };
            RelatedIssuesTab.Content = mElectricalRelatedIssuesControl;
            mIssuesLoaded = true;

            //Attachments
            mElectricalAttachmentsControl = new ElectricalAttachmentsControl(ViewModel.Equipment);
            mElectricalAttachmentsControl.ModelLoaded += () =>
                {
                    mAttachmentsLoaded = true;
                    CheckAllLoaded();
                };
            mElectricalAttachmentsControl.CollectionChanged += (count) =>
                {
                    mElectricalEquipment.GeneralEquipmentRelatedItemsCount.Attachments = count;
                    SetTabHeadersText();
                };
            AttachmentsTab.Content = mElectricalAttachmentsControl;

            //Documents Tab
            mDocumentsControl = new ElectricalEquipmentDocumentsControl(ViewModel.Equipment);

            mDocumentsControl.ControlLoaded += mDocumentsControl_ControlLoaded;
            RoutedEventHandler docsloaded = null;

            docsloaded = (s1, e1) =>
                {
                    //This will hook up change events on all controls
                    Utils.SetUpChangeEvents((UIElement) DocumentsTab.Content, EventAggregator, ViewModel.Equipment);
                    DocumentsTab.Loaded -= docsloaded;
                };

            DocumentsTab.Loaded += docsloaded;

            //This will hook up change events on all controls
            Utils.SetUpChangeEvents(EquipmentControl.Content, EventAggregator, ViewModel.Equipment);
            Utils.SetUpChangeEvents((UIElement) ComponentsTab.Content, EventAggregator, ViewModel.Equipment);
            Utils.SetUpChangeEvents((UIElement) RelatedIssuesTab.Content, EventAggregator, ViewModel.Equipment);
            Utils.SetUpChangeEvents((UIElement) AttachmentsTab.Content, EventAggregator, ViewModel.Equipment);

            RoutedEventHandler loaded = null;
            loaded = (s1, e1) =>
                {
                    //This will hook up change events on all controls
                    Utils.SetUpChangeEvents((UIElement) AttachmentsTab.Content, EventAggregator, ViewModel.Equipment);
                    AttachmentsTab.Loaded -= loaded;
                };

            AttachmentsTab.Loaded += loaded;

            CheckAllLoaded();
        }