public DayInformationWindow(DayControl day)
        {
            InitializeComponent();
            Day = new DayControl(day);

            Refresh();
        }
        public void ClearDayLabels(DateTime date)
        {
            DayControl day = DayControls.FirstOrDefault(x => x.Date == date);

            if (day != null)
            {
                day.DayItems.Clear();
            }
        }
 public void AddDayLabel(DayControl day, Shift shift)
 {
     if (day != null && shift != null)
     {
         Label label = new Label();
         label.Content    = shift.LabelName;
         label.Background = new SolidColorBrush(shift.BackgroundColor);
         label.Foreground = new SolidColorBrush(shift.ForegroundColor);
         day.DayItems.Add(label);
         day.ShiftInfo.Add(shift);
     }
 }
        public void RemoveDayLabel(DateTime date, String text)
        {
            DayControl day = DayControls.FirstOrDefault(x => x.Date == date);

            if (day != null)
            {
                Label label = day.DayItems.FirstOrDefault(x => x.Content == text);
                if (label != null)
                {
                    day.DayItems.Remove(label);
                }
            }
        }
        //// testing stuff
        //private static Int32 backnum = 0;
        //static Brush[] backBrushes = {Brushes.Black,Brushes.Blue,Brushes.Red,Brushes.SlateGray};
        //static Brush[] frontBrushes = {Brushes.White,Brushes.LightGray,Brushes.White,Brushes.Black};
        void day_MouseDown(object sender, MouseButtonEventArgs e)
        {
            // Testing stuff
            DayControl day = sender as DayControl;

            if (day != null)
            {
                if (e.LeftButton == MouseButtonState.Pressed)
                {
                    DayInformationWindow dayInformationWindow = new DayInformationWindow(day);
                    dayInformationWindow.ShowDialog();
                    Refresh();
                }

                // MessageBox.Show(String.Format("Day clicked. Date is: {0}", day.Date));
            }
        }
        public DayControl(DayControl day)
        {
            InitializeComponent();
            Date  = day.Date;
            Title = day.Title;
            foreach (var dayItem in day.DayItems)
            {
                DayItems.Add(new Label()
                {
                    Content = dayItem.Content, Background = dayItem.Background, Foreground = day.Foreground
                });
            }

            ShiftInfo = day.ShiftInfo;

            DataContext = this;

            ItemsGrid.ItemsSource = DayItems;
        }
        public void AddDayLabel(DateTime date, Shift shift, string text, Brush foreground = null, Brush background = null)
        {
            DayControl day = DayControls.FirstOrDefault(x => x.Date.DayOfYear == date.DayOfYear && x.Date.Year == date.Year);

            if (day != null)
            {
                Label label = new Label();
                if (text != null)
                {
                    label.Content = text;
                }
                if (background != null)
                {
                    label.Background = background;
                }
                if (foreground != null)
                {
                    label.Foreground = foreground;
                }
                day.DayItems.Add(label);
                day.ShiftInfo.Add(shift);
            }
        }
        private void AddDayLabel(DateTime date, ShiftTime source, string text, SolidColorBrush foreground, SolidColorBrush background)
        {
            DayControl day = DayControls.FirstOrDefault(x => x.Date.DayOfYear == date.DayOfYear && x.Date.Year == date.Year);

            if (day != null)
            {
                Label label = new Label();
                if (text != null)
                {
                    label.Content = text;
                }
                if (background != null)
                {
                    label.Background = background;
                }
                if (foreground != null)
                {
                    label.Foreground = foreground;
                }
                day.DayItems.Add(label);
                day.ShiftInfo.Add(source);
            }
        }
        private void LoadControls()
        {
            MonthLabel.Content = CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(_month);
            if (DayControls != null)
            {
                foreach (var dayControl in DayControls)
                {
                    dayControl.MouseDown -= day_MouseDown;
                    dayControl.ShiftInfo.Clear();
                    CalendarGrid.Children.Remove(dayControl);
                }
            }
            if (WeekLabels != null)
            {
                foreach (var weekLabel in WeekLabels)
                {
                    CalendarGrid.Children.Remove(weekLabel);
                }
            }


            DayControls = new DayControl[7 * NumWeeks];
            WeekLabels  = new Label[NumWeeks];
            Int32    weekNumber = 0;
            DateTime month      = new DateTime(_year, _month, 1);
            DateTime startDay   = month;

            if (startDay.DayOfWeek < _startOfWeek)
            {
                startDay = startDay.AddDays(-7);
            }

            startDay   = startDay.AddDays(_startOfWeek - startDay.DayOfWeek);
            _startDate = startDay;

            //while (startDay.DayOfWeek != _startOfWeek)
            //  startDay = startDay.AddDays(-1);

            weekNumber = CultureInfo.InvariantCulture.Calendar.GetWeekOfYear(month, CalendarWeekRule.FirstDay,
                                                                             _startOfWeek);

            for (Int32 week = 0; week < NumWeeks; ++week, ++weekNumber)
            {
                Int32 row = CalendarGrid.RowDefinitions.IndexOf(Week1Row) + week;

                Label weekLabel = new Label();
                WeekLabels[week] = weekLabel;
                weekLabel.SetValue(Grid.ColumnProperty, CalendarGrid.ColumnDefinitions.IndexOf(WeekNumberColumn));
                weekLabel.SetValue(Grid.RowProperty, row);

                weekLabel.Content = "Week " + weekNumber;
                CalendarGrid.Children.Add(weekLabel);

                for (Int32 numDay = 0; numDay < 7; ++numDay)
                {
                    DayControl day = new DayControl();
                    day.MouseDown += day_MouseDown;
                    DayControls[7 * week + numDay] = day;
                    day.SetValue(Grid.RowProperty, row);
                    day.SetValue(Grid.ColumnProperty, CalendarGrid.ColumnDefinitions.IndexOf(DayColumn1) + numDay);
                    CalendarGrid.Children.Add(day);
                    day.Date = startDay;
                    _endDate = startDay;
                    startDay = startDay.AddDays(1);
                }
            }
            DayOfWeek _currentDay = _startOfWeek;

            for (Int32 i = 0; i < 7; i++)
            {
                Label dayLabel = new Label();
                dayLabel.Content = _currentDay.ToString();
                dayLabel.SetValue(Grid.RowProperty, CalendarGrid.RowDefinitions.IndexOf(DayTitleRow));
                dayLabel.SetValue(Grid.ColumnProperty, CalendarGrid.ColumnDefinitions.IndexOf(DayColumn1) + i);
                CalendarGrid.Children.Add(dayLabel);
                _currentDay = ((int)_currentDay) < (int)DayOfWeek.Saturday ? _currentDay + 1 : 0;
            }
        }