SyncFusion Scheduler – 难以获取约会详情

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

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:

&lt;scheduler:SfScheduler x:Name=&quot;calendar&quot; View=&quot;Month&quot; FirstDayOfWeek=&quot;Monday&quot; AllowedViews=&quot;Week ,Month&quot;   
                             TodayHighlightBrush=&quot;Gray&quot; AppointmentsSource=&quot; {Binding SchedulerEvents}&quot; Tapped=&quot;calendar_Tapped&quot; &gt;

            &lt;scheduler:SfScheduler.MonthView&gt;
                &lt;scheduler:SchedulerMonthView AppointmentDisplayMode=&quot;Indicator&quot;  /&gt;
            &lt;/scheduler:SfScheduler.MonthView&gt;

            &lt;scheduler:SfScheduler.BindingContext &gt;
                &lt;local:SchedulerControlViewModel&gt;
                    
                &lt;/local:SchedulerControlViewModel&gt;
            &lt;/scheduler:SfScheduler.BindingContext&gt;
&lt;/scheduler:SfScheduler&gt;

Code Behind:

private void calendar_Tapped(object sender, SchedulerTappedEventArgs e)
    {


       

        if (e.Appointments.Count &lt; 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&lt;SchedulerAppointment&gt; SchedulerEvents { get; set; }
        public SchedulerControlViewModel()
        {

            this.SchedulerEvents = new ObservableCollection&lt;SchedulerAppointment&gt;
            {
                new SchedulerAppointment
                {
                    StartTime = new DateTime(2023, 8, 5,00,01,01),
                    EndTime = new DateTime(2023, 8, 5,23,01,01),
                    Subject = &quot;TEST Appointment&quot;,
                    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: &quot;&quot;
    Notes: &quot;&quot;
    RecurrenceId: (null)
    Reminders: (null)
    StartTimeZone: {System.TimeZoneInfo}
    Subject: &quot;TEST Appointment&quot;
    Type: Syncfusion.Maui.Scheduler.SchedulerAppointmentType.Normal

答案1

得分: 0

Appointments 是一个 object 集合

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

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

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

Appointments is a collection of object

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

so you will need to cast it

((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:

确定