SyncFusion Scheduler – 难以获取约会详情

huangapple go评论130阅读模式
英文:

SyncFusion Scheduler - struggling to obtain appointment details

问题

我有一个.Net MAUI应用程序(目标平台为Android、iOS和Windows),我正在尝试首次使用SyncFusion Scheduler。

我已经让一切都工作正常,但我在点击日程安排时难以获取预约详情。

XAML:

  1. <scheduler:SfScheduler x:Name="calendar" View="Month" FirstDayOfWeek="Monday" AllowedViews="Week,Month"
  2. TodayHighlightBrush="Gray" AppointmentsSource="{Binding SchedulerEvents}" Tapped="calendar_Tapped">
  3. <scheduler:SfScheduler.MonthView>
  4. <scheduler:SchedulerMonthView AppointmentDisplayMode="Indicator" />
  5. </scheduler:SfScheduler.MonthView>
  6. <scheduler:SfScheduler.BindingContext>
  7. <local:SchedulerControlViewModel>
  8. </local:SchedulerControlViewModel>
  9. </scheduler:SfScheduler.BindingContext>
  10. </scheduler:SfScheduler>

Code Behind:

  1. private void calendar_Tapped(object sender, SchedulerTappedEventArgs e)
  2. {
  3. if (e.Appointments.Count < 0)
  4. {
  5. //没有预约 - 没问题
  6. }
  7. else
  8. {
  9. //点击的日期上有预约
  10. //// 如何从e.Appointments中获取预约详情(例如预约主题)。
  11. }
  12. }

ViewModel:

  1. namespace MyGolfSocietyApp.ViewModels
  2. {
  3. public class SchedulerControlViewModel
  4. {
  5. public ObservableCollection<SchedulerAppointment> SchedulerEvents { get; set; }
  6. public SchedulerControlViewModel()
  7. {
  8. this.SchedulerEvents = new ObservableCollection<SchedulerAppointment>
  9. {
  10. new SchedulerAppointment
  11. {
  12. StartTime = new DateTime(2023, 8, 5, 00, 01, 01),
  13. EndTime = new DateTime(2023, 8, 5, 23, 01, 01),
  14. Subject = "测试预约",
  15. IsAllDay = true
  16. }
  17. };
  18. }
  19. }
  20. }

Tapped事件处理程序“calendar_Tapped”触发正常,但我难以获取预约内容。
我可以通过调试日志(立即窗口)看到数据从ViewModel返回:

  1. ?e.Appointments
  2. Count = 1
  3. [0]: {Syncfusion.Maui.Scheduler.SchedulerAppointment}
  4. ?e.Appointments[0]
  5. {Syncfusion.Maui.Scheduler.SchedulerAppointment}
  6. base: {Syncfusion.Maui.Scheduler.SchedulerRegionBase}
  7. ActualEndTime: {System.DateTime}
  8. ActualStartTime: {System.DateTime}
  9. DataItem: (null)
  10. EndTimeZone: {System.TimeZoneInfo}
  11. Id: 311937363
  12. IsAllDay: true
  13. IsReadOnly: false
  14. Location: ""
  15. Notes: ""
  16. RecurrenceId: (null)
  17. Reminders: (null)
  18. StartTimeZone: {System.TimeZoneInfo}
  19. Subject: "测试预约"
  20. Type: Syncfusion.Maui.Scheduler.SchedulerAppointmentType.Normal
英文:

I have a .Net MAUI app (target platform And, iOS & Win)
im trying to use the SyncFusion Scheduler for the first time..

I have everything working but I'm struggling to obtain appointment details when I tap on the scheduler..

XAML:

  1. &lt;scheduler:SfScheduler x:Name=&quot;calendar&quot; View=&quot;Month&quot; FirstDayOfWeek=&quot;Monday&quot; AllowedViews=&quot;Week ,Month&quot;
  2. TodayHighlightBrush=&quot;Gray&quot; AppointmentsSource=&quot; {Binding SchedulerEvents}&quot; Tapped=&quot;calendar_Tapped&quot; &gt;
  3. &lt;scheduler:SfScheduler.MonthView&gt;
  4. &lt;scheduler:SchedulerMonthView AppointmentDisplayMode=&quot;Indicator&quot; /&gt;
  5. &lt;/scheduler:SfScheduler.MonthView&gt;
  6. &lt;scheduler:SfScheduler.BindingContext &gt;
  7. &lt;local:SchedulerControlViewModel&gt;
  8. &lt;/local:SchedulerControlViewModel&gt;
  9. &lt;/scheduler:SfScheduler.BindingContext&gt;
  10. &lt;/scheduler:SfScheduler&gt;

Code Behind:

  1. private void calendar_Tapped(object sender, SchedulerTappedEventArgs e)
  2. {
  3. if (e.Appointments.Count &lt; 0)
  4. {
  5. //No Appointment - no problem
  6. }
  7. else
  8. {
  9. //Appointment on date tapped
  10. //// HOW DO I GET THE APPOINTMENT DETAILS FROM e.Appointments (such as the appointment subject.
  11. }
  12. }

View Model:

  1. namespace MyGolfSocietyApp.ViewModels
  2. {
  3. public class SchedulerControlViewModel
  4. {
  5. public ObservableCollection&lt;SchedulerAppointment&gt; SchedulerEvents { get; set; }
  6. public SchedulerControlViewModel()
  7. {
  8. this.SchedulerEvents = new ObservableCollection&lt;SchedulerAppointment&gt;
  9. {
  10. new SchedulerAppointment
  11. {
  12. StartTime = new DateTime(2023, 8, 5,00,01,01),
  13. EndTime = new DateTime(2023, 8, 5,23,01,01),
  14. Subject = &quot;TEST Appointment&quot;,
  15. IsAllDay = true
  16. }
  17. };
  18. }
  19. }
  20. }

The Tapped event handler "calendar_Tapped" triggers ok but im struggling to get the content of the Appointments..
im sure this is super basic c# but im really struggling - hoping you guys can help me please

I can see through the debug logs (immediate window) data is being retunred from the View Model:

  1. ?e.Appointments
  2. Count = 1
  3. [0]: {Syncfusion.Maui.Scheduler.SchedulerAppointment}
  4. ?e.Appointments[0]
  5. {Syncfusion.Maui.Scheduler.SchedulerAppointment}
  6. base: {Syncfusion.Maui.Scheduler.SchedulerRegionBase}
  7. ActualEndTime: {System.DateTime}
  8. ActualStartTime: {System.DateTime}
  9. DataItem: (null)
  10. EndTimeZone: {System.TimeZoneInfo}
  11. Id: 311937363
  12. IsAllDay: true
  13. IsReadOnly: false
  14. Location: &quot;&quot;
  15. Notes: &quot;&quot;
  16. RecurrenceId: (null)
  17. Reminders: (null)
  18. StartTimeZone: {System.TimeZoneInfo}
  19. Subject: &quot;TEST Appointment&quot;
  20. Type: Syncfusion.Maui.Scheduler.SchedulerAppointmentType.Normal

答案1

得分: 0

Appointments 是一个 object 集合

  1. public ReadOnlyCollection&lt;object&gt; Appointments { get; }

所以你需要进行强制类型转换

  1. ((SchedulerAppointment)e.Appointments[0]).Subject
英文:

Appointments is a collection of object

  1. public ReadOnlyCollection&lt;object&gt; Appointments { get; }

so you will need to cast it

  1. ((SchedulerAppointment)e.Appointments[0]).Subject

huangapple
  • 本文由 发表于 2023年8月4日 21:36:02
  • 转载请务必保留本文链接:https://go.coder-hub.com/76836450.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定