How to create Agenda view in schedule
Using SFSchedule, you can create agenda view to show the appointments for specific dates by using “ScheduleCellTappedEvent” of SFSchedule Xamarin.iOS.
Create a Xamarin.iOS application and add Schedule and a view which is used to display the details of the selected date Appointments (Table view used in this sample) on it.
C#
// Create Schedule for Agenda view schedule = new SFSchedule(); schedule.ScheduleView = SFScheduleView.SFScheduleViewMonth; // Initializing appointment collection appointmentCollection = new NSMutableArray(); schedule.Frame = new CGRect(0, 0, this.View.Frame.Width, 400); // To display Selected date details dateLabel = new UILabel(); dateLabel.Text = ""; dateLabel.TextColor = UIColor.Black; dateLabel.TextAlignment = UITextAlignment.Center; dateLabel.BackgroundColor = UIColor.FromRGB(247, 247, 247); dateLabel.Frame = new CGRect(0, 400, this.View.Frame.Width, 20); // To display Selected date Appointment details tableView = new UITableView(); tableView.Frame = new CGRect(0, 420, this.View.Frame.Width, 400); tableView.BackgroundColor = UIColor.FromRGB(247, 247, 247); schedulePageView = new UIView(new CGRect(0, 30, this.View.Frame.Width, this.View.Frame.Height)); // Adding views schedulePageView.AddSubview(schedule); schedulePageView.AddSubview(dateLabel); schedulePageView.AddSubview(tableView); UIView contentView = new UIView(new CGRect(0, 0, this.View.Frame.Width, this.View.Frame.Height)); contentView.AddSubview(schedulePageView); View.AddSubview(contentView); //Loads the appointments collection schedule.Appointments = appointmentCollection;
Trigger schedule cell tapped event of schedule to get the details of the selected date and its appointments. Agenda view is a view used to display the details of the appointments based on the selected date. You can get the selected date appointments from the cell tapped event and shows the appointment details in table view by set the appointments as a source of the table view.
C#
schedule.CellTapped += Schedule_CellTapped; void Schedule_CellTapped (object sender, CellTappedEventArgs e) { NSDateFormatter dateformatter = new NSDateFormatter(); dateformatter.DateFormat = "MMMM dd yyyy"; dateLabel.Text = dateformatter.ToString(e.Date); dateLabel.Font = UIFont.BoldSystemFontOfSize(15); tableView.Source = new ScheduleTableSource(e.ScheduleAppointments); tableView.ReloadData(); }
You can pass the appointments of the selected date using cell tapped event to the custom class ScheduleTableSoure and store the appointments in a UITableViewSource TableItems.
C#
public class ScheduleTableSource : UITableViewSource { List<ScheduleAppointment> TableItems; string CellIdentifier = "TableCell"; public ScheduleTableSource(List<ScheduleAppointment> items) { TableItems = items; } public override nint RowsInSection(UITableView tableview, nint section) { int i = TableItems.Count; if (i == 0) return 1; return (nint)i; } public override nfloat GetHeightForRow(UITableView tableView, NSIndexPath indexPath) { return 60.0f; } public override UITableViewCell GetCell(UITableView tableView, NSIndexPath indexPath) { UITableViewCell cell = tableView.DequeueReusableCell(CellIdentifier); if (cell == null) { cell = new UITableViewCell(UITableViewCellStyle.Default, CellIdentifier); } if (TableItems == null || TableItems.Count == 0) { cell.TextLabel.Text = "No Events"; } else { var item = TableItems[indexPath.Row]; cell.TextLabel.Text = item.Subject; } cell.BackgroundColor = UIColor.Clear; return cell; } }
The following screenshot displays the Agenda view in Schedule.
You can download entire source code of this demo of Xamarin.iOS from here
https://www.syncfusion.com/downloads/support/directtrac/general/ze/AgendaView-806770311.zip