英文:
SyncFusion Scheduler - struggling to obtain appointment details
问题
我有一个.Net MAUI应用程序(目标平台为Android、iOS和Windows),我正在尝试首次使用SyncFusion Scheduler。
我已经让一切都工作正常,但我在点击日程安排时难以获取预约详情。
XAML:
<scheduler:SfScheduler x:Name="calendar" View="Month" FirstDayOfWeek="Monday" AllowedViews="Week,Month"
TodayHighlightBrush="Gray" AppointmentsSource="{Binding SchedulerEvents}" Tapped="calendar_Tapped">
<scheduler:SfScheduler.MonthView>
<scheduler:SchedulerMonthView AppointmentDisplayMode="Indicator" />
</scheduler:SfScheduler.MonthView>
<scheduler:SfScheduler.BindingContext>
<local:SchedulerControlViewModel>
</local:SchedulerControlViewModel>
</scheduler:SfScheduler.BindingContext>
</scheduler:SfScheduler>
Code Behind:
private void calendar_Tapped(object sender, SchedulerTappedEventArgs e)
{
if (e.Appointments.Count < 0)
{
//没有预约 - 没问题
}
else
{
//点击的日期上有预约
//// 如何从e.Appointments中获取预约详情(例如预约主题)。
}
}
ViewModel:
namespace MyGolfSocietyApp.ViewModels
{
public class SchedulerControlViewModel
{
public ObservableCollection<SchedulerAppointment> SchedulerEvents { get; set; }
public SchedulerControlViewModel()
{
this.SchedulerEvents = new ObservableCollection<SchedulerAppointment>
{
new SchedulerAppointment
{
StartTime = new DateTime(2023, 8, 5, 00, 01, 01),
EndTime = new DateTime(2023, 8, 5, 23, 01, 01),
Subject = "测试预约",
IsAllDay = true
}
};
}
}
}
Tapped事件处理程序“calendar_Tapped”触发正常,但我难以获取预约内容。
我可以通过调试日志(立即窗口)看到数据从ViewModel返回:
?e.Appointments
Count = 1
[0]: {Syncfusion.Maui.Scheduler.SchedulerAppointment}
?e.Appointments[0]
{Syncfusion.Maui.Scheduler.SchedulerAppointment}
base: {Syncfusion.Maui.Scheduler.SchedulerRegionBase}
ActualEndTime: {System.DateTime}
ActualStartTime: {System.DateTime}
DataItem: (null)
EndTimeZone: {System.TimeZoneInfo}
Id: 311937363
IsAllDay: true
IsReadOnly: false
Location: ""
Notes: ""
RecurrenceId: (null)
Reminders: (null)
StartTimeZone: {System.TimeZoneInfo}
Subject: "测试预约"
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:
<scheduler:SfScheduler x:Name="calendar" View="Month" FirstDayOfWeek="Monday" AllowedViews="Week ,Month"
TodayHighlightBrush="Gray" AppointmentsSource=" {Binding SchedulerEvents}" Tapped="calendar_Tapped" >
<scheduler:SfScheduler.MonthView>
<scheduler:SchedulerMonthView AppointmentDisplayMode="Indicator" />
</scheduler:SfScheduler.MonthView>
<scheduler:SfScheduler.BindingContext >
<local:SchedulerControlViewModel>
</local:SchedulerControlViewModel>
</scheduler:SfScheduler.BindingContext>
</scheduler:SfScheduler>
Code Behind:
private void calendar_Tapped(object sender, SchedulerTappedEventArgs e)
{
if (e.Appointments.Count < 0)
{
//No Appointment - no problem
}
else
{
//Appointment on date tapped
//// HOW DO I GET THE APPOINTMENT DETAILS FROM e.Appointments (such as the appointment subject.
}
}
View Model:
namespace MyGolfSocietyApp.ViewModels
{
public class SchedulerControlViewModel
{
public ObservableCollection<SchedulerAppointment> SchedulerEvents { get; set; }
public SchedulerControlViewModel()
{
this.SchedulerEvents = new ObservableCollection<SchedulerAppointment>
{
new SchedulerAppointment
{
StartTime = new DateTime(2023, 8, 5,00,01,01),
EndTime = new DateTime(2023, 8, 5,23,01,01),
Subject = "TEST Appointment",
IsAllDay = true
}
};
}
}
}
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:
?e.Appointments
Count = 1
[0]: {Syncfusion.Maui.Scheduler.SchedulerAppointment}
?e.Appointments[0]
{Syncfusion.Maui.Scheduler.SchedulerAppointment}
base: {Syncfusion.Maui.Scheduler.SchedulerRegionBase}
ActualEndTime: {System.DateTime}
ActualStartTime: {System.DateTime}
DataItem: (null)
EndTimeZone: {System.TimeZoneInfo}
Id: 311937363
IsAllDay: true
IsReadOnly: false
Location: ""
Notes: ""
RecurrenceId: (null)
Reminders: (null)
StartTimeZone: {System.TimeZoneInfo}
Subject: "TEST Appointment"
Type: Syncfusion.Maui.Scheduler.SchedulerAppointmentType.Normal
答案1
得分: 0
Appointments
是一个 object
集合
public ReadOnlyCollection<object> Appointments { get; }
所以你需要进行强制类型转换
((SchedulerAppointment)e.Appointments[0]).Subject
英文:
Appointments
is a collection of object
public ReadOnlyCollection<object> Appointments { get; }
so you will need to cast it
((SchedulerAppointment)e.Appointments[0]).Subject
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论