예제 #1
0
        /// <summary>
        /// Sync selected value of container control with the SelectedDateTime property.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void OnContainerSelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (container.TemplatedParent == null || e.OriginalSource != container)
            {
                return;
            }

            //Single selection
            if (container.SelectedItems.Count == 1)
            {
                CalendarDay selected = container.SelectedItem as CalendarDay;
                System.Diagnostics.Debug.Assert(selected != null);

                if (!selected.IsOtherMonth && selected.IsSelectable)
                {
                    SelectedDateTime = selected.Date;
                }
            }
            else if (!IsUpdatingSelection)
            {
                if (container.SelectedItems == null || container.SelectedItems.Count <= 0)
                {
                    SelectedDateTime = null;
                }
            }
        }
예제 #2
0
 private void UpdateContainerSelection()
 {
     if (SelectedDateTime.HasValue)
     {
         CalendarDay day = GetCalendarDateByDate(SelectedDateTime.Value);
         if (day != null && container != null)
         {
             container.SelectedValue = day;
         }
     }
 }
예제 #3
0
        public FXMonthViewItem GetContainerFromDate(DateTime date)
        {
            CalendarDay day = GetCalendarDateByDate(date);

            if (day != null && container != null)
            {
                return(container.ItemContainerGenerator.ContainerFromItem(day) as FXMonthViewItem);
            }

            return(null);
        }
예제 #4
0
 internal void InternalUpdate(CalendarDay cdate)
 {
     Date         = cdate.Date;
     IsOtherMonth = cdate.IsOtherMonth;
     IsSelectable = cdate.IsSelectable;
 }
예제 #5
0
        private CalendarDayCollection CreateVisibleDaysCollection()
        {
            CalendarDayCollection collection = new CalendarDayCollection();

            int      NumberOfDays   = CultureHelper.CurrentCalendar.GetDaysInMonth(ViewYear, ViewMonth);
            DateTime dtStartOfMonth = new DateTime(ViewYear, ViewMonth, 1, 0, 0, 0, CultureHelper.CurrentCalendar);

            int TotalDays = 0;
            int FirstDay  = CultureHelper.GetDayOfWeek(dtStartOfMonth, CultureHelper.CurrentCalendar);

            int LastMonth = ViewMonth;
            int LastYear  = ViewYear;

            if (ViewMonth - 1 < 1 && LastYear > 1)
            {
                LastMonth = 12;
                LastYear--;
            }
            else if (ViewMonth - 1 > 0)
            {
                LastMonth--;
            }

            int PrevMonthDays = CultureHelper.CurrentCalendar.GetDaysInMonth(LastYear, LastMonth);
            int LastingDays   = PrevMonthDays - FirstDay;

            //Create Pre-Day paddings
            for (int i = LastingDays; i < PrevMonthDays; i++)
            {
                CalendarDay newDay = new CalendarDay(new DateTime(LastYear, LastMonth, i + 1, 0, 0, 0, CultureHelper.CurrentCalendar));
                newDay.IsOtherMonth = true;
                newDay.IsSelectable = false;
                collection.Add(newDay);

                TotalDays++;
            }

            //Create CurrentMonth Days
            for (int i = 1; i <= NumberOfDays; i++)
            {
                CalendarDay newDay = new CalendarDay(new DateTime(ViewYear, ViewMonth, i, 0, 0, 0, CultureHelper.CurrentCalendar));
                newDay.IsOtherMonth = false;
                newDay.IsSelectable = true;

                collection.Add(newDay);
                TotalDays++;
            }

            int EndDay;

            if (FirstDay != 0)
            {
                EndDay = NumberOfDays + 1;
            }
            else
            {
                EndDay = NumberOfDays;
            }

            //Create Post-Padding Days
            for (int i = EndDay; i < 42; i++)
            {
                if (TotalDays == 42)
                {
                    break;
                }

                CalendarDay newDay = new CalendarDay(new DateTime(ViewYear, ViewMonth, i - EndDay + 1, 0, 0, 0, CultureHelper.CurrentCalendar));
                collection.Add(newDay);
            }

            return(collection);
        }