예제 #1
0
 private void ItemClick(object sender, RoutedEventArgs e)
 {
     if (_lastItem != null)
     {
         _lastItem.IsSelected = false;
     }
     _lastItem = (sender as CalendarItem);
     if (_lastItem != null)
     {
         if (ShowSelectedDate)
         {
             _lastItem.IsSelected = true;
         }
         SelectedDate = _lastItem.ItemDate;
     }
 }
예제 #2
0
 private void AddDefaultItems()
 {
     if (!_addedItems && _itemsGrid != null)
     {
         for (int rowCount = 1; rowCount <= RowCount; rowCount++)
         {
             for (int columnCount = 1; columnCount < ColumnCount; columnCount++)
             {
                 var item = new CalendarItem(this);
                 item.SetValue(Grid.RowProperty, rowCount);
                 item.SetValue(Grid.ColumnProperty, columnCount);
                 item.Visibility = Visibility.Collapsed;
                 item.Tag        = string.Concat(rowCount.ToString(), ":", columnCount.ToString());
                 item.Click     += ItemClick;
                 if (CalendarItemStyle != null)
                 {
                     item.Style = CalendarItemStyle;
                 }
                 _itemsGrid.Children.Add(item);
             }
             if (WeekNumberDisplay != WeekNumberDisplayOption.None)
             {
                 const int columnCount = 0;
                 var       item        = new CalendarWeekItem();
                 item.SetValue(Grid.RowProperty, rowCount);
                 item.SetValue(Grid.ColumnProperty, columnCount);
                 item.Visibility = Visibility.Collapsed;
                 item.Tag        = string.Concat(rowCount.ToString(), ":", columnCount.ToString());
                 if (CalendarWeekItemStyle != null)
                 {
                     item.Style = CalendarWeekItemStyle;
                 }
                 _itemsGrid.Children.Add(item);
             }
         }
         _addedItems = true;
     }
 }
예제 #3
0
        private void BuildItems()
        {
            if (_itemsGrid != null)
            {
                AddDefaultItems();
                var       startOfMonth   = new DateTime(_year, _month, 1);
                DayOfWeek dayOfWeek      = startOfMonth.DayOfWeek;
                var       daysInMonth    = (int)Math.Floor(startOfMonth.AddMonths(1).Subtract(startOfMonth).TotalDays);
                var       addedDays      = 0;
                int       lastWeekNumber = 0;
                for (int rowCount = 1; rowCount <= RowCount; rowCount++)
                {
                    for (var columnCount = 1; columnCount < ColumnCount; columnCount++)
                    {
                        var item = (CalendarItem)(from oneChild in _itemsGrid.Children
                                                  where oneChild is CalendarItem &&
                                                  ((CalendarItem)oneChild).Tag.ToString() == string.Concat(rowCount.ToString(), ":", columnCount.ToString())
                                                  select oneChild).First();
                        if (rowCount == 1 && columnCount < (int)dayOfWeek + 1)
                        {
                            item.Visibility = Visibility.Collapsed;
                        }
                        else if (addedDays < daysInMonth)
                        {
                            item.Visibility = Visibility.Visible;
                        }
                        else
                        {
                            item.Visibility = Visibility.Collapsed;
                        }

                        var weekItem = (CalendarWeekItem)(from oneChild in _itemsGrid.Children
                                                          where oneChild is CalendarWeekItem &&
                                                          ((CalendarWeekItem)oneChild).Tag.ToString() == string.Concat(rowCount.ToString(), ":0")
                                                          select oneChild).FirstOrDefault();

                        if (item.Visibility == Visibility.Visible)
                        {
                            item.ItemDate = startOfMonth.AddDays(addedDays);
                            if (SelectedDate == DateTime.MinValue && item.ItemDate == DateTime.Today)
                            {
                                SelectedDate = item.ItemDate;
                                if (ShowSelectedDate)
                                {
                                    item.IsSelected = true;
                                }
                                _lastItem = item;
                            }
                            else
                            {
                                if (item.ItemDate == SelectedDate)
                                {
                                    if (ShowSelectedDate)
                                    {
                                        item.IsSelected = true;
                                    }
                                }
                                else
                                {
                                    item.IsSelected = false;
                                }
                            }
                            addedDays     += 1;
                            item.DayNumber = addedDays;
                            item.SetBackcolor();

                            if (WeekNumberDisplay != WeekNumberDisplayOption.None)
                            {
                                int weekNumber;

                                if (WeekNumberDisplay == WeekNumberDisplayOption.WeekOfYear)
                                {
                                    var systemCalendar = System.Threading.Thread.CurrentThread.CurrentCulture.Calendar;
                                    weekNumber = systemCalendar.GetWeekOfYear(
                                        item.ItemDate,
                                        System.Threading.Thread.CurrentThread.CurrentCulture.DateTimeFormat.CalendarWeekRule,
                                        System.Threading.Thread.CurrentThread.CurrentCulture.DateTimeFormat.FirstDayOfWeek);
                                }
                                else
                                {
                                    weekNumber = rowCount;
                                }
                                weekItem.WeekNumber = weekNumber;
                                lastWeekNumber      = weekNumber;
                                weekItem.Visibility = Visibility.Visible;
                            }
                        }
                        else
                        {
                            if (WeekNumberDisplay != WeekNumberDisplayOption.None && weekItem.WeekNumber != lastWeekNumber)
                            {
                                weekItem.Visibility = Visibility.Collapsed;
                            }
                        }
                    }
                }
            }
        }
예제 #4
0
 private void AddDefaultItems()
 {
     if (!_addedItems && _itemsGrid != null)
     {
         for (int rowCount = 1; rowCount <= RowCount; rowCount++)
         {
             for (int columnCount = 1; columnCount < ColumnCount; columnCount++)
             {
                 var item = new CalendarItem(this);
                 item.SetValue(Grid.RowProperty, rowCount);
                 item.SetValue(Grid.ColumnProperty, columnCount);
                 item.Visibility = Visibility.Collapsed;
                 item.Tag = string.Concat(rowCount.ToString(), ":", columnCount.ToString());
                 item.Click += ItemClick;
                 if (CalendarItemStyle != null)
                 {
                     item.Style = CalendarItemStyle;
                 }
                 _itemsGrid.Children.Add(item);
             }
             if (WeekNumberDisplay != WeekNumberDisplayOption.None)
             {
                 const int columnCount = 0;
                 var item = new CalendarWeekItem();
                 item.SetValue(Grid.RowProperty, rowCount);
                 item.SetValue(Grid.ColumnProperty, columnCount);
                 item.Visibility = Visibility.Collapsed;
                 item.Tag = string.Concat(rowCount.ToString(), ":", columnCount.ToString());
                 if (CalendarWeekItemStyle != null)
                 {
                     item.Style = CalendarWeekItemStyle;
                 }
                 _itemsGrid.Children.Add(item);
             }
         }
         _addedItems = true;
     }
 }
예제 #5
0
        private void BuildItems()
        {
            if (_itemsGrid != null)
            {
                AddDefaultItems();
                var startOfMonth = new DateTime(_year, _month, 1);
                DayOfWeek dayOfWeek = startOfMonth.DayOfWeek;
                var daysInMonth = (int)Math.Floor(startOfMonth.AddMonths(1).Subtract(startOfMonth).TotalDays);
                var addedDays = 0;
                int lastWeekNumber = 0;
                for (int rowCount = 1; rowCount <= RowCount; rowCount++)
                {
                    for (var columnCount = 1; columnCount < ColumnCount; columnCount++)
                    {
                        var item = (CalendarItem)(from oneChild in _itemsGrid.Children
                                                  where oneChild is CalendarItem &&
                                                  ((CalendarItem)oneChild).Tag.ToString() == string.Concat(rowCount.ToString(), ":", columnCount.ToString())
                                                  select oneChild).First();
                        if (rowCount == 1 && columnCount < (int)dayOfWeek + 1)
                        {
                            item.Visibility = Visibility.Collapsed;
                        }
                        else if (addedDays < daysInMonth)
                        {
                            item.Visibility = Visibility.Visible;
                        }
                        else
                        {
                            item.Visibility = Visibility.Collapsed;
                        }

                        var weekItem = (CalendarWeekItem)(from oneChild in _itemsGrid.Children
                                                          where oneChild is CalendarWeekItem &&
                                                          ((CalendarWeekItem)oneChild).Tag.ToString() == string.Concat(rowCount.ToString(), ":0")
                                                          select oneChild).FirstOrDefault();

                        if (item.Visibility == Visibility.Visible)
                        {
                            item.ItemDate = startOfMonth.AddDays(addedDays);
                            if (SelectedDate == DateTime.MinValue && item.ItemDate == DateTime.Today)
                            {
                                SelectedDate = item.ItemDate;
                                if (ShowSelectedDate)
                                    item.IsSelected = true;
                                _lastItem = item;
                            }
                            else
                            {
                                if (item.ItemDate == SelectedDate)
                                {
                                    if (ShowSelectedDate)
                                        item.IsSelected = true;
                                }
                                else
                                {
                                    item.IsSelected = false;
                                }
                            }
                            addedDays += 1;
                            item.DayNumber = addedDays;
                            item.SetBackcolor();

                            if (WeekNumberDisplay != WeekNumberDisplayOption.None)
                            {
                                int weekNumber;

                                if (WeekNumberDisplay == WeekNumberDisplayOption.WeekOfYear)
                                {
                                    var systemCalendar = System.Threading.Thread.CurrentThread.CurrentCulture.Calendar;
                                    weekNumber = systemCalendar.GetWeekOfYear(
                                        item.ItemDate,
                                        System.Threading.Thread.CurrentThread.CurrentCulture.DateTimeFormat.CalendarWeekRule,
                                        System.Threading.Thread.CurrentThread.CurrentCulture.DateTimeFormat.FirstDayOfWeek);
                                }
                                else
                                {
                                    weekNumber = rowCount;
                                }
                                if (weekItem != null)
                                {
                                    weekItem.WeekNumber = weekNumber;
                                    lastWeekNumber = weekNumber;
                                    weekItem.Visibility = Visibility.Visible;
                                }
                            }
                        }
                        else
                        {
                            if (WeekNumberDisplay != WeekNumberDisplayOption.None && weekItem != null && weekItem.WeekNumber != lastWeekNumber)
                            {
                                weekItem.Visibility = Visibility.Collapsed;
                            }
                        }
                    }
                }
            }
        }
예제 #6
0
 private void ItemClick(object sender, RoutedEventArgs e)
 {
     if (_lastItem != null)
     {
         _lastItem.IsSelected = false;
     }
     _lastItem = (sender as CalendarItem);
     if (_lastItem != null)
     {
         if (ShowSelectedDate)
             _lastItem.IsSelected = true;
         SelectedDate = _lastItem.ItemDate;
         OnDateClicked(_lastItem.ItemDate);
     }
 }
예제 #7
0
        private void BuildItems()
        {
            if (_itemsGrid != null)
            {
                var markedDatesDictionary = new Dictionary<DateTime, int>();

                if (MarkDatesRetriever != null)
                {
                    markedDatesDictionary = MarkDatesRetriever.Retrieve(DateTime.Today.Date);
                }

                AddDefaultItems();
                var startOfMonth = new DateTime(_year, _month, 1);
                DayOfWeek dayOfWeek = startOfMonth.DayOfWeek;
                int startColumn = DefaultDayColumnIndex(dayOfWeek);
                if (StartingDayOfWeek != DayOfWeek.Sunday)
                {
                    startColumn = startColumn + DayColumnOffsetFromSunday();
                    if (startColumn <= 0)
                    {
                        startColumn += 7;
                    }
                }
                var daysInMonth = (int)Math.Floor(startOfMonth.AddMonths(1).Subtract(startOfMonth).TotalDays);
                var addedDays = 0;
                int lastWeekNumber = 0;
                for (int rowCount = 1; rowCount <= RowCount; rowCount++)
                {
                    for (var columnCount = 1; columnCount < ColumnCount; columnCount++)
                    {
                        var item = (CalendarItem)(from oneChild in _itemsGrid.Children
                                                  where oneChild is CalendarItem &&
                                                  ((CalendarItem)oneChild).Tag.ToString() == string.Concat(rowCount.ToString(CultureInfo.InvariantCulture), ":", columnCount.ToString(CultureInfo.InvariantCulture))
                                                  select oneChild).First();
                        if (rowCount == 1 && columnCount < startColumn)
                        {
                            item.Visibility = Visibility.Collapsed;
                        }
                        else if (addedDays < daysInMonth)
                        {
                            item.Visibility = Visibility.Visible;
                        }
                        else
                        {
                            item.Visibility = Visibility.Collapsed;
                        }

                        var weekItem = (CalendarWeekItem)(from oneChild in _itemsGrid.Children
                                                          where oneChild is CalendarWeekItem &&
                                                          ((CalendarWeekItem)oneChild).Tag.ToString() == string.Concat(rowCount.ToString(CultureInfo.InvariantCulture), ":0")
                                                          select oneChild).FirstOrDefault();

                        if (item.Visibility == Visibility.Visible)
                        {
                            item.ItemDate = startOfMonth.AddDays(addedDays);
                            if (SelectedDate == DateTime.MinValue && item.ItemDate == DateTime.Today)
                            {
                                SelectedDate = item.ItemDate;
                                if (ShowSelectedDate)
                                    item.IsSelected = true;
                                _lastItem = item;
                            }
                            else
                            {
                                if (item.ItemDate == SelectedDate)
                                {
                                    if (ShowSelectedDate)
                                        item.IsSelected = true;
                                }
                                else
                                {
                                    item.IsSelected = false;
                                }
                            }
                            addedDays += 1;
                            item.DayNumber = addedDays;

                            // my important customization
                            item.IsMarked = markedDatesDictionary.ContainsKey(item.ItemDate);
                            item.NumberOfEvents = item.IsMarked
                                ? markedDatesDictionary[item.ItemDate]
                                : 0;
                            item.IsToday = DateTime.Now.Date == item.ItemDate;

                            item.SetBackcolor();
                            item.SetForecolor();

                            if (WeekNumberDisplay != WeekNumberDisplayOption.None)
                            {
                                int weekNumber;

                                if (WeekNumberDisplay == WeekNumberDisplayOption.WeekOfYear)
                                {
                                    var systemCalendar = System.Threading.Thread.CurrentThread.CurrentCulture.Calendar;
                                    weekNumber = systemCalendar.GetWeekOfYear(
                                        item.ItemDate,
                                        System.Threading.Thread.CurrentThread.CurrentCulture.DateTimeFormat.CalendarWeekRule,
                                        System.Threading.Thread.CurrentThread.CurrentCulture.DateTimeFormat.FirstDayOfWeek);
                                }
                                else
                                {
                                    weekNumber = rowCount;
                                }
                                if (weekItem != null)
                                {
                                    weekItem.WeekNumber = weekNumber;
                                    lastWeekNumber = weekNumber;
                                    weekItem.Visibility = Visibility.Visible;
                                }
                            }
                        }
                        else
                        {
                            if (WeekNumberDisplay != WeekNumberDisplayOption.None && weekItem != null && weekItem.WeekNumber != lastWeekNumber)
                            {
                                weekItem.Visibility = Visibility.Collapsed;
                            }
                        }
                    }
                }
            }
        }
예제 #8
0
 private void ItemHold(object sender, GestureEventArgs e)
 {
     if (_lastItem != null)
     {
         _lastItem.IsSelected = false;
     }
     _lastItem = (sender as CalendarItem);
     if (_lastItem != null)
     {
         if (ShowSelectedDate)
             _lastItem.IsSelected = true;
         SelectedDate = _lastItem.ItemDate;
         OnDateHold(_lastItem.ItemDate);
     }
 }