Esempio n. 1
0
        private void PopulateGrids()
        {
            if (MonthView != null)
            {
                var childCount = Calendar.RowsPerMonth + Calendar.RowsPerMonth * Calendar.ColumnsPerMonth;
                var children   = new List <IControl>(childCount);

                for (int i = 0; i < Calendar.RowsPerMonth; i++)
                {
                    if (_dayTitleTemplate != null)
                    {
                        var cell = _dayTitleTemplate.Build();
                        cell.DataContext = string.Empty;
                        cell.SetValue(Grid.RowProperty, 0);
                        cell.SetValue(Grid.ColumnProperty, i);
                        children.Add(cell);
                    }
                }

                for (int i = 1; i < Calendar.RowsPerMonth; i++)
                {
                    for (int j = 0; j < Calendar.ColumnsPerMonth; j++)
                    {
                        CalendarDayButton cell = new CalendarDayButton();

                        if (Owner != null)
                        {
                            cell.Owner = Owner;
                        }
                        cell.SetValue(Grid.RowProperty, i);
                        cell.SetValue(Grid.ColumnProperty, j);
                        cell.CalendarDayButtonMouseDown += Cell_MouseLeftButtonDown;
                        cell.CalendarDayButtonMouseUp   += Cell_MouseLeftButtonUp;
                        cell.PointerEnter += Cell_MouseEnter;
                        cell.PointerLeave += Cell_MouseLeave;
                        cell.Click        += Cell_Click;
                        children.Add(cell);
                    }
                }

                MonthView.Children.AddRange(children);
            }

            if (YearView != null)
            {
                var childCount = Calendar.RowsPerYear * Calendar.ColumnsPerYear;
                var children   = new List <IControl>(childCount);

                CalendarButton month;
                for (int i = 0; i < Calendar.RowsPerYear; i++)
                {
                    for (int j = 0; j < Calendar.ColumnsPerYear; j++)
                    {
                        month = new CalendarButton();

                        if (Owner != null)
                        {
                            month.Owner = Owner;
                        }
                        month.SetValue(Grid.RowProperty, i);
                        month.SetValue(Grid.ColumnProperty, j);
                        month.CalendarLeftMouseButtonDown += Month_CalendarButtonMouseDown;
                        month.CalendarLeftMouseButtonUp   += Month_CalendarButtonMouseUp;
                        month.PointerEnter += Month_MouseEnter;
                        month.PointerLeave += Month_MouseLeave;
                        children.Add(month);
                    }
                }

                YearView.Children.AddRange(children);
            }
        }
Esempio n. 2
0
        private void PopulateGrids()
        {
            if (MonthView != null)
            {
                var childCount = Calendar.RowsPerMonth + Calendar.RowsPerMonth * Calendar.ColumnsPerMonth;
                using var children = new PooledList <IControl>(childCount);

                for (int i = 0; i < Calendar.RowsPerMonth; i++)
                {
                    if (_dayTitleTemplate != null)
                    {
                        var cell = (Control)_dayTitleTemplate.Build();
                        cell.DataContext = string.Empty;
                        cell.SetValue(Grid.RowProperty, 0);
                        cell.SetValue(Grid.ColumnProperty, i);
                        children.Add(cell);
                    }
                }

                EventHandler <PointerPressedEventArgs>  cellMouseLeftButtonDown = Cell_MouseLeftButtonDown;
                EventHandler <PointerReleasedEventArgs> cellMouseLeftButtonUp   = Cell_MouseLeftButtonUp;
                EventHandler <PointerEventArgs>         cellMouseEnter          = Cell_MouseEnter;
                EventHandler <RoutedEventArgs>          cellClick = Cell_Click;

                for (int i = 1; i < Calendar.RowsPerMonth; i++)
                {
                    for (int j = 0; j < Calendar.ColumnsPerMonth; j++)
                    {
                        var cell = new CalendarDayButton();

                        if (Owner != null)
                        {
                            cell.Owner = Owner;
                        }
                        cell.SetValue(Grid.RowProperty, i);
                        cell.SetValue(Grid.ColumnProperty, j);
                        cell.CalendarDayButtonMouseDown += cellMouseLeftButtonDown;
                        cell.CalendarDayButtonMouseUp   += cellMouseLeftButtonUp;
                        cell.PointerEnter += cellMouseEnter;
                        cell.Click        += cellClick;
                        children.Add(cell);
                    }
                }

                MonthView.Children.AddRange(children);
            }

            if (YearView != null)
            {
                var childCount = Calendar.RowsPerYear * Calendar.ColumnsPerYear;
                var children   = new List <IControl>(childCount);

                EventHandler <PointerPressedEventArgs>  monthCalendarButtonMouseDown = Month_CalendarButtonMouseDown;
                EventHandler <PointerReleasedEventArgs> monthCalendarButtonMouseUp   = Month_CalendarButtonMouseUp;
                EventHandler <PointerEventArgs>         monthMouseEnter = Month_MouseEnter;

                for (int i = 0; i < Calendar.RowsPerYear; i++)
                {
                    for (int j = 0; j < Calendar.ColumnsPerYear; j++)
                    {
                        var month = new CalendarButton();

                        if (Owner != null)
                        {
                            month.Owner = Owner;
                        }
                        month.SetValue(Grid.RowProperty, i);
                        month.SetValue(Grid.ColumnProperty, j);
                        month.CalendarLeftMouseButtonDown += monthCalendarButtonMouseDown;
                        month.CalendarLeftMouseButtonUp   += monthCalendarButtonMouseUp;
                        month.PointerEnter += monthMouseEnter;
                        children.Add(month);
                    }
                }

                YearView.Children.AddRange(children);
            }
        }