Accessing Tapped event args using MVVM

Hi there,


I was wondering how you'd go about accessing the details of a tapped appointment in the scheduler when using MVVM?  I'm using EventToArgs from the CommunityToolkit but not sure what the parameter is?  Is the command parameter the selected appointments?  Is this even possible?


Regards

Shaun


12 Replies 1 reply marked as answer

VO Vishal Omprasad Syncfusion Team July 17, 2023 01:53 PM UTC

Hi Shaun,

Currently we are analysig your query. We will validate and update you with further details shortly. We appreciate your patience till then.

Regards,

Vishal O.



SH Shaun July 19, 2023 07:40 PM UTC

Hi folks,


So I'm able to access the view model and pass on the event using the following in the code behind of the view, passing the events to the view model.

void Scheduler_Tapped(System.Object sender, Syncfusion.Maui.Scheduler.SchedulerTappedEventArgs e)

{

var vm = (ViewModels.MainViewModel)BindingContext;

vm.AppointmentTapped(e);

}


A problem that I've come across now is when the Scheduler View is set to Month and there is a QueryAppointments event attached to it, the AppointmentDisplayMode doesn't work. If I remove the QueryAppointments event then the Indicator shows in the Month view.

I've set it as below as per the docs but it won't show.


AppointmentDisplayMode="Indicator"/>


This also occurs if you set the QueryAppointmentsCommand on the scheduler when using MVVM, the AppointmentDisplayMode is set to none or maybe the AppointmentSource is cleared?  Which would be weird because it's called when the Scheduler first loads.

Do you have any idea why it doesn't show under these circumstances?


Regards

Shaun



SS SaiGanesh Sakthivel Syncfusion Team July 20, 2023 01:35 PM UTC

Hi Shaun,


#Query 1: Regarding EventToCommands behavior in MAUI SfScheduler

Your requirement can be achieved with the help of CommunityToolKit.Maui. Please refer to the following code snippet for your reference.


ViewModel

private ICommand tappedCommand;

 

public ICommand TappedCommand

{

    get { return tappedCommand; }

    set { tappedCommand = value; }

}

 

public SchedulerViewModel()

{

    this.GenerateAppointments();

    this.DisplayDate = DateTime.Now.Date.AddHours(8).AddMinutes(50);

    this.tappedCommand = new Command<SchedulerTappedEventArgs>(OnTapped);

}

 

private void OnTapped(SchedulerTappedEventArgs obj)

{

           

}


MAUIProgram

public static MauiApp CreateMauiApp()

{

            var builder = MauiApp.CreateBuilder();

    builder.ConfigureSyncfusionCore();

    builder.UseMauiApp<App>().UseMauiCommunityToolkit();

    builder

                        .UseMauiApp<App>()

                        .ConfigureFonts(fonts =>

                        {

                                    fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");

                                    fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold");

                        });

 

            return builder.Build();

}


Xaml

<scheduler:SfScheduler x:Name="Scheduler"

                        View="Week"

                        DisplayDate="{Binding DisplayDate}"

                        AppointmentsSource="{Binding Events}"

                        AllowedViews="Day,Week,WorkWeek,Month,TimelineDay,TimelineWeek,TimelineWorkWeek,TimelineMonth">

    <scheduler:SfScheduler.BindingContext>

        <local:SchedulerViewModel/>

    </scheduler:SfScheduler.BindingContext>

    <scheduler:SfScheduler.Behaviors>

        <toolkit:EventToCommandBehavior

            EventName="Tapped"

            Command="{Binding TappedCommand}" />

    </scheduler:SfScheduler.Behaviors>

</scheduler:SfScheduler>


Please refer to the demo sample in the attachment. Please let us know if you have any concerns.


#Query 2: Appointment is not display when using the QueryAppointment event

As per the implementation, the appointment in the view will be reset when the query appointment event or command is triggered. We suggest you set the item source inside the Query Appointments event/command or remove the event if it is not needed.


Regards,
SaiGanesh Sakthivel


Attachment: GettingStarted_a026e90d.zip


SH Shaun July 20, 2023 06:50 PM UTC

Ah, ok thanks, just tested and works all fine, many thanks.



SP Sangavi Periyannan Syncfusion Team July 21, 2023 08:41 AM UTC

Shaun,


We are glad that the provided response meets your requirement. Please let us know if you need further assistance. As always, we are happy to help you out. 


Marked as answer

EV Enzo Varenna March 15, 2024 02:01 PM UTC

Hi Sangavi Periyannan,

I updated your example to net8 and I found that it doesn't work if you update CommunityToolkit.Maui to a version greater than 1.0, the current stable version is 7.0.1...


private void OnTapped(SchedulerTappedEventArgs obj)

{


}

obj return null


Syncfusion.Maui.Core v. 25.1.35

Syncfusion.Maui.Schedule v. 25.1.35


Is there a fix or alternative method with MVVM?


Attached you will find the solution to the error.


Regards


Attachment: GettingStarted_eba2fe1f.zip


VO Vishal Omprasad Syncfusion Team March 18, 2024 01:13 PM UTC

Hi Enzo,

Regarding “updated to net8.0 and your sample doesn’t work”:

Based on the shared details we have checked the reported query with your shared sample, but we are unable to replicate the reported scenario from our end. The sample updated fine without any errors. We have also update the CommunityToolkit.Maui to the version 7.0.0 and ensured. We have attached the tested sample below for your reference.

Please check our sample and let us know whether you are still facing the same issue. If the problem persists, kindly modify our sample, and revert to us with the following details which would help us to check on it and provide you a better solution as soon as possible.

  • Platform (Android, Windows, iOS, or macOS) in the issue is reproduced.

  • A video demonstrating the issue being replicated.

  • A sample that can reproduce the issue.

Regards,
Vishal O.


Attachment: GettingStarted_a4f853f7.zip


EV Enzo Varenna replied to Vishal Omprasad March 18, 2024 04:56 PM UTC

Hi,

Enable debugging on "private void OnTapped(SchedulerTappedEventArgs obj)". You will notice that "obj" is null when you tap some event.

See Attachment


Attachment: 20240318_175207_ebe78525.zip


VM Vidyalakshmi Mani Syncfusion Team March 21, 2024 01:48 PM UTC

Hi Enzo,


Thank you for bringing this to our attention. After investigating, we've determined that the issue is related to the CommunityToolkit.Maui NuGet package in its latest versions. To resolve this, we recommend reverting to version 1.0 of the CommunityToolkit.Maui package.


We have tested this solution and found that it resolves the issue. Please try using version 1.0 and let us know if you continue to experience any problems.


Additionally, we have also logged an issue report with the framework side and are actively monitoring the reported bug. We will keep you updated on any progress.


Bug report link: https://github.com/dotnet/maui/issues/21354


Thank you for your understanding.


Regards,

Vidyalakshmi M.




EV Enzo Varenna March 21, 2024 01:57 PM UTC

Hi,

As I said on March 15th, this is exactly the problem and with the version 1.0 of CommunityToolkit.Maui it works. The latest stable version is 7.0.1, thanks for letting us know when the bug will be fixed.


Regards



EV Enzo Varenna March 22, 2024 08:45 AM UTC

Hi, 

below you will find the fix to the problem with "CommunityToolkit.Maui" version 7.0.1.

You need to set:

  x:TypeArguments="scheduler:SchedulerTappedEventArgs"


Reference:

 https://github.com/CommunityToolkit/Maui/issues/569



 <scheduler:SfScheduler x:Name="Scheduler"

                        View="Week"

                        DisplayDate="{Binding DisplayDate}"

                        AppointmentsSource="{Binding Events}"

                        AllowedViews="Day,Week,WorkWeek,Month,TimelineDay,TimelineWeek,TimelineWorkWeek,TimelineMonth">

     <scheduler:SfScheduler.BindingContext>

         <local:SchedulerViewModel/>

     </scheduler:SfScheduler.BindingContext>

     <scheduler:SfScheduler.Behaviors>

         <toolkit:EventToCommandBehavior

             x:TypeArguments="scheduler:SchedulerTappedEventArgs"

             EventName="Tapped"

             Command="{Binding TappedCommand}" />

     </scheduler:SfScheduler.Behaviors>

 </scheduler:SfScheduler>


Regards


Attachment: GettingStarted_c23a5187.zip


VM Vidyalakshmi Mani Syncfusion Team March 22, 2024 10:50 AM UTC

Hi Enzo,


Thank you for sharing the solution with us. If you need any further assistance or encounter any more issues, please feel free to let us know. We're here to help!


Regards,

Vidyalakshmi M.



Loader.
Up arrow icon