Exemplo n.º 1
0
        /// <summary>
        /// 高亮选中的日期段
        /// </summary>
        public void SetSelectedDatesHighlight(ObservableCollection <DateTime> selectedDates)
        {
            foreach (object item in this.PART_MonthView.Children)
            {
                ZCalendarDayButton dayButton = item as ZCalendarDayButton;
                if (!(dayButton.DataContext is DateTime) || !dayButton.IsBelongCurrentMonth)
                {
                    continue;
                }

                DateTime dt = (DateTime)dayButton.DataContext;
                if (selectedDates != null && selectedDates.Contains(dt))
                {
                    if (dt == this.Owner.Owner.SelectedDateStart || dt == this.Owner.Owner.SelectedDateEnd)
                    {
                        dayButton.IsSelected = true;
                    }
                    else
                    {
                        dayButton.IsHighlight = true;
                    }
                }
                else
                {
                    dayButton.IsSelected  = false;
                    dayButton.IsHighlight = false;
                }
            }
        }
Exemplo n.º 2
0
        private void InitMonthGrid()
        {
            if (this.PART_MonthView == null)
            {
                return;
            }

            //1、加载周一到周日标题
            for (int i = 0; i < 7; i++)
            {
                ZCalendarDayButton calendarDayButton = new ZCalendarDayButton();
                calendarDayButton.Owner = this.Owner;
                calendarDayButton.SetValue(Button.IsEnabledProperty, false);
                calendarDayButton.SetValue(Grid.RowProperty, 0);
                calendarDayButton.SetValue(Grid.ColumnProperty, i);
                calendarDayButton.SetValue(Button.ContentTemplateProperty, this.Owner.DayTitleTemplate);
                this.PART_MonthView.Children.Add(calendarDayButton);
                this.CalendarDayButtons[0, i] = calendarDayButton;
            }

            //2、加载该月的每一天
            for (int j = 1; j < 7; j++)
            {
                for (int k = 0; k < 7; k++)
                {
                    ZCalendarDayButton calendarDayButton = new ZCalendarDayButton();
                    calendarDayButton.Owner = this.Owner;
                    calendarDayButton.SetValue(Grid.RowProperty, j);
                    calendarDayButton.SetValue(Grid.ColumnProperty, k);
                    calendarDayButton.SetBinding(FrameworkElement.StyleProperty, new Binding("CalendarDayButtonStyle")
                    {
                        Source = this.Owner
                    });
                    calendarDayButton.IsToday      = false;
                    calendarDayButton.IsBlackedOut = false;
                    calendarDayButton.IsSelected   = false;
                    //calendarDayButton.AddHandler(UIElement.MouseLeftButtonDownEvent, new MouseButtonEventHandler(this.Cell_MouseLeftButtonDown), true);
                    //calendarDayButton.AddHandler(UIElement.MouseLeftButtonUpEvent, new MouseButtonEventHandler(this.Cell_MouseLeftButtonUp), true);
                    //calendarDayButton.AddHandler(UIElement.MouseEnterEvent, new MouseEventHandler(this.Cell_MouseEnter), true);
                    calendarDayButton.Click += new RoutedEventHandler(this.DayButton_Clicked);
                    //calendarDayButton.AddHandler(UIElement.PreviewKeyDownEvent, new RoutedEventHandler(this.CellOrMonth_PreviewKeyDown), true);
                    this.PART_MonthView.Children.Add(calendarDayButton);
                    this.CalendarDayButtons[j, k] = calendarDayButton;
                }
            }
        }
Exemplo n.º 3
0
        public void SetSelectedDateHighlight()
        {
            foreach (object item in this.PART_MonthView.Children)
            {
                ZCalendarDayButton dayButton = item as ZCalendarDayButton;
                if (!(dayButton.DataContext is DateTime) || !dayButton.IsBelongCurrentMonth)
                {
                    continue;
                }

                DateTime dt = (DateTime)dayButton.DataContext;
                if (this.Owner.SelectedDate.HasValue && dt == this.Owner.SelectedDate.Value.Date)
                {
                    dayButton.IsSelected = true;
                    break;
                }
            }
        }
Exemplo n.º 4
0
 /// <summary>
 /// 高亮“今日”
 /// </summary>
 private void SetTodayButtonHighlight()
 {
     //只有月模式下才高亮 “今日”
     if (this.Owner.DisplayMode == CalendarMode.Month)
     {
         foreach (object item in this.PART_MonthView.Children)
         {
             ZCalendarDayButton dayButton = item as ZCalendarDayButton;
             if (dayButton.DataContext is DateTime)
             {
                 DateTime dt = (DateTime)dayButton.DataContext;
                 if (dt == DateTime.Today)
                 {
                     dayButton.IsToday = true;
                     break;
                 }
             }
         }
     }
 }
Exemplo n.º 5
0
        private void DayButton_Clicked(object sender, RoutedEventArgs e)
        {
            ZCalendarDayButton calendarDayButton = sender as ZCalendarDayButton;

            if (!(calendarDayButton.DataContext is DateTime))
            {
                return;
            }
            if (!calendarDayButton.IsBlackedOut)
            {
                DateTime dateTime = (DateTime)calendarDayButton.DataContext;
                switch (this.Owner.SelectionMode)
                {
                case CalendarSelectionMode.SingleDate:
                    this.ClearSelectedDate();
                    this.Owner.DisplayDate  = new DateTime(dateTime.Year, dateTime.Month, 1);
                    this.Owner.SelectedDate = new DateTime?(dateTime);
                    break;

                case CalendarSelectionMode.SingleRange:
                    this.Owner.DisplayDate  = new DateTime(dateTime.Year, dateTime.Month, 1);
                    this.Owner.SelectedDate = new DateTime?(dateTime);
                    break;

                case CalendarSelectionMode.MultipleRange:
                    break;

                case CalendarSelectionMode.None:
                    break;

                default:
                    break;
                }

                this.Owner.OnDateClick(new DateTime?(dateTime), new DateTime?(dateTime));
            }
        }