public EventControlDispatcher(EventViewModelDispatcher masterDispatcher)
        {
            if (masterDispatcher == null)
            {
                throw new NullDispatcherException();
            }
            this.masterDispatcher = masterDispatcher;
            this.attachedWeekGrid = this.masterDispatcher.AttachedWeekGridControl;

            this.eventControls = new List<EventControl>();
        }
 public void DetachControl()
 {
     if (this.attachedWeekGridControl != null)
     {
         UnSubscribeFromAttachedControlEvents();
         this.attachedWeekGridControl = null;
         this.popupDispatcher = null;
         this.eventControlDispatcher = null;
     }
 }
        private void SubscribeToAttachedControlEvents(WeekGridControl weekGrid)
        {
            if (weekGrid == null)
            {
                throw new NullAttachedControlException();
            }

            //Subscribe fort Button.Clicked events for the buttons in the atached WeekGridControl.
            weekGrid.PreviousWeekButton.Click += new RoutedEventHandler(PreviousWeek_Clicked);
            weekGrid.NextWeekButton.Click += new RoutedEventHandler(NextWeek_Clicked);
            weekGrid.TodayButton.Click += new RoutedEventHandler(Today_Clicked);
            weekGrid.AddButton.Click += new RoutedEventHandler(Add_Clicked);

            //Subscribe for OnHourCellClicked event which fires when a cell from the hour grid is clicked.
            weekGrid.HourCellClick += new MouseButtonEventHandler(HourCell_Clicked);
            weekGrid.DayCellClick += new MouseButtonEventHandler(DayCell_Clicked);

            //Subscribe for the change of size.
            weekGrid.SizeChanged += new SizeChangedEventHandler(AttachedControlSize_Changed);
        }
        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);
        }