private void InitMonthGrid() { if (this.PART_MonthView == null) { return; } //1、加载周一到周日标题 for (int i = 0; i < 7; i++) { AduCalendarDayButton calendarDayButton = new AduCalendarDayButton(); 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++) { AduCalendarDayButton calendarDayButton = new AduCalendarDayButton(); ElementBackground.SetSelectedBackground(calendarDayButton, ElementBackground.GetSelectedBackground(this)); ElementBackground.SetMouseOverBackground(calendarDayButton, ElementBackground.GetMouseOverBackground(this)); ElementBackground.SetHighlightBackground(calendarDayButton, ElementBackground.GetHighlightBackground(this)); ElementForeground.SetSelectedForeground(calendarDayButton, ElementForeground.GetSelectedForeground(this)); ElementForeground.SetMouseOverForeground(calendarDayButton, ElementForeground.GetMouseOverForeground(this)); ElementForeground.SetHighlightForeground(calendarDayButton, ElementForeground.GetHighlightForeground(this)); 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; } } }
protected void UpdateVisualState() { Rect clipping = new Rect(0, 0, Width, _panelSize.Height); double opacity = (IsEnabled ? 1 : 0.8); if (ElementRoot != null) { ElementBackground.SetValue(Canvas.TopProperty, _panelSize.Height); ElementBackground.SetValue(Canvas.LeftProperty, 0d); ElementContent.SetValue(Canvas.TopProperty, _panelSize.Height); ElementText.Opacity = opacity; ElementCheckBox.Opacity = opacity; ElementExpand.IsEnabled = IsEnabled; ElementExpand.Cursor = (IsEnabled ? Cursors.Hand : Cursors.Arrow); ElementText.Cursor = ElementExpand.Cursor; ElementBackground.Width = Width; ElementBackground.Height = Height - _panelSize.Height; clipping = new Rect(0, 0, Width, double.IsNaN(Height) ? _panelSize.Height : Height); if (_expanded) { ElementBackground.Visibility = Visibility.Visible; } else if (_expandDirection == 0.0) { ElementBackground.Visibility = Visibility.Collapsed; } ElementClipping.SetValue(RectangleGeometry.RectProperty, clipping); ElementText.Text = _text; if (_enableCheckbox) { ElementCheckBox.IsChecked = _checked; ElementCheckBox.Visibility = Visibility.Visible; } else { ElementCheckBox.Visibility = Visibility.Collapsed; } } }