public void DetachControl()
 {
     if (this.attachedWeekGridControl != null)
     {
         UnSubscribeFromAttachedControlEvents();
         this.attachedWeekGridControl = null;
         this.popupDispatcher = null;
         this.eventControlDispatcher = null;
     }
 }
        public void AttachControl(WeekGridControl weekGrid)
        {
            if (weekGrid == null)
            {
                throw new NullAttachedControlException();
            }

            //Throw exception if there is already an attached WeekGridControl and the control to be attached is not the same.
            if (this.attachedWeekGridControl != null
                && this.attachedWeekGridControl != weekGrid)
            {
                throw new AttachedControlException();
            }

            this.attachedWeekGridControl = weekGrid;

            popupDispatcher = new PopupDispatcher(this);

            eventControlDispatcher = new EventControlDispatcher(this);
            eventControlDispatcher.EventControlClick += new EventHandler(EventControl_Clicked);

            this.SubscribeToAttachedControlEvents(weekGrid);
            this.SetViewModelStateToShow(DateTime.Now);
        }