Exemple #1
0
        public CalendarAppointmentTapped()
        {
            // >> calendar-gettingstarted-appointmentssource-csharp
            var date = new DateTime(2017, 4, 12);

            var calendar = new RadCalendar
            {
                DisplayDate        = date,
                AppointmentsSource = new List <Appointment> {
                    new Appointment {
                        Title     = "Meeting with Tom",
                        Detail    = "Sea Garden",
                        StartDate = date.AddHours(1),
                        EndDate   = date.AddHours(2),
                        Color     = Color.Tomato
                    },
                    new Appointment {
                        Title     = "Lunch with Sara",
                        Detail    = "Restaurant",
                        StartDate = date.AddHours(2).AddMinutes(30),
                        EndDate   = date.AddHours(3),
                        Color     = Color.DarkTurquoise
                    },
                    new Appointment {
                        Title     = "Birthday",
                        StartDate = date.AddHours(2).AddMinutes(30),
                        EndDate   = date.AddHours(3),
                        IsAllDay  = true,
                        Color     = Color.Orange
                    },
                    new Appointment {
                        Title     = "Football Game",
                        StartDate = date.AddDays(1).AddHours(2).AddMinutes(30),
                        EndDate   = date.AddDays(1).AddHours(3),
                        Color     = Color.Green
                    }
                }
            };

            // << calendar-gettingstarted-appointmentssource-csharp

            // >> calendar-features-setviewmode-csharp
            calendar.NativeControlLoaded += (sender, e) =>
            {
                calendar.TrySetViewMode(CalendarViewMode.Day);
            };
            // << calendar-features-setviewmode-csharp

            // >> calendar-features-appointmenttapped-csharp
            calendar.AppointmentTapped += (sender, e) =>
            {
                DisplayAlert(e.Appointment.Title, e.Appointment.Detail, "OK");
            };
            // << calendar-features-appointmenttapped-csharp
            this.Content = calendar;
        }
Exemple #2
0
 protected override void OnSizeAllocated(double width, double height)
 {
     base.OnSizeAllocated(width, height);
     /* There is a bug on the calendar for iOS in landscape orientation */
     if (Device.RuntimePlatform == Device.iOS && (this.width != width || this.height != height))
     {
         this.width  = width;
         this.height = height;
         if (width > height && calendar.ViewMode == CalendarViewMode.Year)
         {
             calendar.TrySetViewMode(CalendarViewMode.YearNumbers);
         }
     }
 }
        public CalendarAppointmentTapped()
        {
            var date = new DateTime(2017, 4, 12);

            var calendar = new RadCalendar
            {
                DisplayDate        = date,
                AppointmentsSource = new List <Appointment> {
                    new Appointment {
                        Title     = "Meeting with Tom",
                        Detail    = "Sea Garden",
                        StartDate = date.AddHours(1),
                        EndDate   = date.AddHours(2),
                        Color     = Color.Tomato
                    },
                    new Appointment {
                        Title     = "Lunch with Sara",
                        Detail    = "Restaurant",
                        StartDate = date.AddHours(2).AddMinutes(30),
                        EndDate   = date.AddHours(3),
                        Color     = Color.DarkTurquoise
                    },
                    new Appointment {
                        Title     = "Birthday",
                        StartDate = date.AddHours(2).AddMinutes(30),
                        EndDate   = date.AddHours(3),
                        IsAllDay  = true
                    }
                }
            };

            calendar.NativeControlLoaded += (sender, e) =>
            {
                calendar.TrySetViewMode(CalendarViewMode.Day);
            };

            calendar.AppointmentTapped += (sender, e) =>
            {
                DisplayAlert(e.Appointment.Title, e.Appointment.Detail, "OK");
            };

            this.Content = calendar;
        }
Exemple #4
0
        private void CalendarLoaded(object sender, EventArgs e)
        {
            RadCalendar calendar = sender as RadCalendar;

            calendar.TrySetViewMode(CalendarViewMode.Day, false);
        }
Exemple #5
0
        /* After pushing CalendarPage() into the NavigationPage stack (App.cs:33), constructor is invoked. Here, an instance of a calendar is created, some of its properties and event are
         * set up. All the buttons shown in CalendarPage() are instances of ToolbarItems. The business logic of this page can be found in CalendarViewModel(). */
        public CalendarPage()
        {
            DependencyService.Get <IStatusBar>().ShowStatusBar();

            calendar = new RadCalendar
            {
                WeekNumbersDisplayMode = DisplayMode.Hide,
                DayNamesDisplayMode    = DisplayMode.Show,
                GridLinesWidth         = 0,
            };

            this.BindingContext          = new CalendarViewModel(this, this.Navigation, calendar);
            calendar.ViewChanged        += ((CalendarViewModel)this.BindingContext).calendarViewChanged;
            calendar.DisplayDateChanged += ((CalendarViewModel)this.BindingContext).dateChanged;

            if (Device.RuntimePlatform == Device.iOS)
            {
                calendar.DayNameCellStyle = new CalendarCellStyle {
                    FontSize = 12
                };
                var layout = new RelativeLayout();
                this.changeLayout(calendar, layout);
                layout.SizeChanged += (sender, e) =>
                {
                    this.changeLayout(calendar, layout);
                };
            }
            else
            {
                Content = calendar;
            }

            var addAppointmentButton = new ToolbarItem
            {
                Icon     = Device.RuntimePlatform == Device.Android ? "add_ic" : "",
                Text     = "Add",
                Order    = ToolbarItemOrder.Primary,
                Priority = 1
            };

            addAppointmentButton.SetBinding(MenuItem.CommandProperty, new Binding("AddAppointmentCommand"));

            var changeViewButton = new ToolbarItem
            {
                Icon     = Device.RuntimePlatform == Device.Android ? "day_ic" : "",
                Text     = "BarButton",
                Order    = ToolbarItemOrder.Primary,
                Priority = 0,
                Command  = new Command(() =>
                {
                    var selectedDate = calendar.SelectedDate;
                    if (calendar.ViewMode != CalendarViewMode.Day)
                    {
                        calendar.TrySetViewMode(CalendarViewMode.Day, true);
                        if (selectedDate.HasValue)
                        {
                            calendar.DisplayDate  = selectedDate.Value;
                            calendar.SelectedDate = selectedDate;
                        }
                    }
                    else
                    {
                        calendar.TrySetViewMode(CalendarViewMode.Month, true);
                    }
                })
            };

            ToolbarItems.Add(changeViewButton);
            ToolbarItems.Add(addAppointmentButton);

            string date = string.Empty;

            if (calendar.ViewMode == CalendarViewMode.Month)
            {
                if (Device.RuntimePlatform == Device.iOS)
                {
                    date = calendar.DisplayDate.Date.ToString("MMMM");
                }
                else
                {
                    date = calendar.DisplayDate.Year.ToString();
                }
            }
            else if (calendar.ViewMode == CalendarViewMode.MonthNames)
            {
                date = calendar.DisplayDate.Year.ToString();
            }

            ((CalendarViewModel)this.BindingContext).ChangeViewButton = new ToolbarItem
            {
                Text    = date == string.Empty ? string.Empty : string.Concat("Go to ", date),
                Command = new Command(() =>
                {
                    switch (calendar.ViewMode)
                    {
                    case CalendarViewMode.Month:
                        {
                            if (Device.RuntimePlatform == Device.iOS)
                            {
                                calendar.TrySetViewMode(CalendarViewMode.MonthNames);
                            }
                            else
                            {
                                calendar.TrySetViewMode(CalendarViewMode.Year);
                            }
                            break;
                        }

                    case CalendarViewMode.MonthNames:
                        {
                            if (Height > Width)
                            {
                                calendar.TrySetViewMode(CalendarViewMode.Year);
                            }
                            else
                            {
                                calendar.TrySetViewMode(CalendarViewMode.YearNumbers);
                            }
                            break;
                        }

                    case CalendarViewMode.YearNumbers:
                        break;
                    }
                }),
                Icon     = Device.RuntimePlatform == Device.Android ? "goto_ic" : "",
                Order    = ToolbarItemOrder.Primary,
                Priority = 1
            };
            ToolbarItems.Add(((CalendarViewModel)this.BindingContext).ChangeViewButton);

            string[]      secondaryButtonTitles = new string[] { "Today", "Settings", "Tickets", "Logout" };
            ToolbarItem[] secondaryToolbar      = new ToolbarItem[secondaryButtonTitles.Length];
            for (int i = 0; i < secondaryButtonTitles.Length; i++)
            {
                secondaryToolbar[i] = new ToolbarItem
                {
                    Text  = secondaryButtonTitles[i],
                    Order = ToolbarItemOrder.Secondary
                };
                secondaryToolbar[i].SetBinding(MenuItem.CommandProperty, new Binding(string.Concat(secondaryButtonTitles[i], "Command")));
                ToolbarItems.Add(secondaryToolbar[i]);
            }
        }