We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

How to use EventToCommandBehaviour (from Prism) to get CellTapped event in the ViewModel? (MVVM Pattern)

Hi, I have implemented an SFSchedule control in my Xamarin.Forms UWP app. But I'm not being able to make the CellTapped event call a command in my ViewModel when i click in some Day Cell with the mouse. You can see that i'm using the MVVM Prism Framework, which has the EventToCommandBehaviour. See my XAML code for the ScheduleControl:

xmlns:syncfusion="clr-namespace:Syncfusion.SfSchedule.XForms;assembly=Syncfusion.SfSchedule.XForms"
xmlns:b="clr-namespace:Prism.Behaviors;assembly=Prism.Forms"

<syncfusion:SfSchedule x:Name="schedule"
                               DataSource="{Binding Meetings}"
                               ScheduleView="MonthView"
                               >
         
            <syncfusion:SfSchedule.Behaviors>
                <b:EventToCommandBehavior Command="{Binding DayClieckedCommand}"
                                    EventName="CellTapped"
                                    EventArgsParameterPath="Item"    
                                    />
            </syncfusion:SfSchedule.Behaviors>
           
</syncfusion:SfSchedule>



And here you can see the Command in my ViewModel

        public DelegateCommand<CellTappedEventArgs> DayClickedCommand => new DelegateCommand<CellTappedEventArgs>(DayClicked);
        public void DayClicked(CellTappedEventArgs args)
        {
            System.Diagnostics.Debug.WriteLine("TEST");
        }

Currently, i'm not being able to even call the method to just print a message for debug purposes. I don't know why the behaviour on the XAML is not calling the Command. Is there another possibility to call commands in the ViewModel, avoiding CodeBehind?

Well, right now im not concerning with parameters, im just trying to call the method, one step at a time. But after, i will need to get in this command the Day that was clicked, to open another page with a Schedule in DayView mode, so i can edit or add appointments in that specific day. I'm kind of lost there because those parameters really blow my mind :)

If anyone can help me please, i'm kind stuck here. Thanks in advance.

12 Replies

SP Subburaj Pandian Veluchamy Syncfusion Team July 19, 2017 02:29 PM UTC

Hi Leandro, 
 
Thank you for contacting Syncfusion support. 
 
Based on the provided information, we have checked and we are unable to reproduce  
the mentioned issue with Schedule CellTapped event is not triggering while tapping with a mouse in Xamarin Forms UWP when triggering the event to Command Behavior. We have prepared sample based on this scenario, please find the below sample. 
 
 
Could you please check the sample and let us know if you face any issue by modifying the provided sample based on your scenario with more details, it will be helpful for us to check on it and provide you the better solution. 
 
Regards,   
Subburaj Pandian V.     



SH Stephen Hauck August 22, 2017 03:16 PM UTC

Paying it forward in case anyone searches for this and is using  Corcav Behaviors  like I am in my MVVM architecture...here is all you need to do







SH Stephen Hauck August 22, 2017 05:15 PM UTC

The above sample will pass in the entire schedule control.

If you just want the CellTappedParameters then simply use this code 



Then in the command cast it like so...





SP Subburaj Pandian Veluchamy Syncfusion Team August 23, 2017 08:45 AM UTC

Hi Stephen, 
 
Thank you for your valuable suggestion. Please let us know if you have any query with SfSchedule, we will happy to help you. 
  
Regards,   
Subburaj Pandian V.  



AM Amen October 2, 2018 03:39 AM UTC

I tried this approach and got this exception:
System.ArgumentException: Expression of type 'Syncfusion.SfCalendar.XForms.MonthCell' cannot be used for parameter of type 'System.EventArgs' of method 'Void OnFired(System.EventArgs)'
Parameter name: arg0

Code in my model view:
        public ICommand BindMonthCellToDateCommand { get; set; }
        public ICommand SetCurrentMonthCommand { get; set; }
        #endregion
        #region constructors 
        public WeatherViewModel()
        {
            BindMonthCellToDateCommand = new Command(
                (object e) => 
                {
// stuff here                  
                }, (object e) => 
                {
                    return true;                    
                });

            SetCurrentMonthCommand = new Command(
               (object e) => {
             // stuff here 
               }, (object e) => {
                   var ee = e as MonthCell;
                   return true; 
               });
        }
xaml:
 <calendar:SfCalendar x:Name="calendar">
            <Syncfusion:SfCalendar.MonthViewSettings>
                <Syncfusion:MonthViewSettings DateSelectionColor="#dddddd" CellTemplate="{StaticResource weathertemplate}"/>
            </Syncfusion:SfCalendar.MonthViewSettings>
            <b:Interaction.Behaviors>
                <b:BehaviorCollection>
                <b:EventToCommand Command="{Binding BindMonthCellToDateCommand}" PassEventArgument="True" EventName="OnMonthCellLoaded"/>
                    <b:EventToCommand Command="{Binding SetCurrentMonthCommand}" PassEventArgument="True" EventName="MonthChanged"/>
                </b:BehaviorCollection>
            </b:Interaction.Behaviors>                       
        </calendar:SfCalendar>

Thanks


VR Vigneshkumar Ramasamy Syncfusion Team October 3, 2018 12:50 PM UTC

Hi Amen, 
 
Thank you for contacting Syncfusion Support. 
 
Based on the provided information, we have checked the issue with “System.ArgumentException has been thrown while using EventToCommand behavior in SfCalendar” and it is working fine from our side. We have prepared a sample, please find the sample from the below link. 
 
 
If the given sample also doesn’t meet your requirement, could you please modify the provided sample along with its reproducing procedure? It will be helpful for us to analyze on your requirement and provide you a possible solution. 
 
Please let us know if you have any concern. 
 
Regards,
Vigneshkumar R 



AM Amen replied to Vigneshkumar Ramasamy October 5, 2018 11:32 PM UTC

Hi Amen, 
 
Thank you for contacting Syncfusion Support. 
 
Based on the provided information, we have checked the issue with “System.ArgumentException has been thrown while using EventToCommand behavior in SfCalendar” and it is working fine from our side. We have prepared a sample, please find the sample from the below link. 
 
 
If the given sample also doesn’t meet your requirement, could you please modify the provided sample along with its reproducing procedure? It will be helpful for us to analyze on your requirement and provide you a possible solution. 
 
Please let us know if you have any concern. 
 
Regards,
Vigneshkumar R 


Please feel free to download the project from this url: https://www.dropbox.com/s/irfa0m806zht84e/RiverFindr.zip?dl=0


VR Vigneshkumar Ramasamy Syncfusion Team October 8, 2018 12:59 PM UTC

Hi Amen,

Thanks for the update.  

Based on the provided information, we have checked and we are able to reproduce the mentioned issue " System.ArgumentException has been thrown while using EventToCommand behavior in SfCalendar " from our side. We have already logged issue report on this, we will provide fix for the reported issue in our upcoming Volume 3 SP1 release, which will be rolled out in the end of October. We appreciate your patience until then. 

Regards,
Vigneshkumar R  



AM Amen replied to Vigneshkumar Ramasamy October 8, 2018 11:20 PM UTC

Hi Amen,

Thanks for the update.  

Based on the provided information, we have checked and we are able to reproduce the mentioned issue " System.ArgumentException has been thrown while using EventToCommand behavior in SfCalendar " from our side. We have already logged issue report on this, we will provide fix for the reported issue in our upcoming Volume 3 SP1 release, which will be rolled out in the end of October. We appreciate your patience until then. 

Regards,
Vigneshkumar R  


It would be wiser to make the eventargs parameter of the OnMonthCellLoaded event handler inherit from System.EventArgs. I tried doing this workaround but there is a problem still:
https://stackoverflow.com/questions/52684016/syncfusion-calender-onmonthcellloaded-custom-event-is-passing-a-null-to-my-comma


VR Vigneshkumar Ramasamy Syncfusion Team October 10, 2018 01:09 PM UTC

Hi Amen,

Thank you for your patience.

We have fixed the issue’s with “System.ArgumentException has been thrown while using EventToCommand behavior in SfCalendar”. As per the implementation Monthcell is moved to EventArgs from View and it is deprecated in OnMonthCellLoaded event and use MonthCellLoadedEventArgs. Please find the Custom assemblies for this fix below.

Custom assemblies: http://www.syncfusion.com/downloads/support/directtrac/217023/ze/Assembly1814496033.zip

Please clear the NuGet cache before replacing the custom assemblies. Please find the link below,
https://www.syncfusion.com/kb/6987/how-to-clear-nuget-cache

Assembly Version: 16.3.0.21
Installation Directions:
Replace the files “Syncfusion.SfCalendar.XForms.dll, Syncfusion.SfCalendar.XForms.Android.dll, Syncfusion.SfCalendar.XForms.iOS.dll” under following folders. Before replacing the new assemblies please take backup of old assemblies.
{Syncfusion Installed location} \Essential Studio\16.3.0.21\Xamarin\lib\pcl\Syncfusion.SfCalendar.XForms.dll 
{Syncfusion Installed location} \Essential Studio\16.3.0.21\Xamarin\lib\Android\Syncfusion.SfCalendar.XForms.dll 
{Syncfusion Installed location}\EssentialStudio\16.3.0.21\Xamarin\lib\Android\Syncfusion.SfCalendar.XForms.Android.dll 
{Syncfusion Installed location} \Essential Studio\16.3.0.21\Xamarin\lib\iOS\Syncfusion.SfCalendar.XForms.dll 
{Syncfusion Installed location}\EssentialStudio\16.3.0.21\Xamarin\lib\iOS\Syncfusion.SfCalendar.XForms.iOS.dll 

Disclaimer:
Please note that we have created these custom assemblies for version 16.3.0.21 .This fix will be included in our upcoming Vol 3 SP1 release which is expected to be available by end of October 2018. Please use the provided assemblies and let us know if you have any concern. 

Regards,
Vigneshkumar R 



AM Amen replied to Vigneshkumar Ramasamy October 10, 2018 04:01 PM UTC

Hi Amen,

Thank you for your patience.

We have fixed the issue’s with “System.ArgumentException has been thrown while using EventToCommand behavior in SfCalendar”. As per the implementation Monthcell is moved to EventArgs from View and it is deprecated in OnMonthCellLoaded event and use MonthCellLoadedEventArgs. Please find the Custom assemblies for this fix below.

Custom assemblies: http://www.syncfusion.com/downloads/support/directtrac/217023/ze/Assembly1814496033.zip

Please clear the NuGet cache before replacing the custom assemblies. Please find the link below,
https://www.syncfusion.com/kb/6987/how-to-clear-nuget-cache

Assembly Version: 16.3.0.21
Installation Directions:
Replace the files “Syncfusion.SfCalendar.XForms.dll, Syncfusion.SfCalendar.XForms.Android.dll, Syncfusion.SfCalendar.XForms.iOS.dll” under following folders. Before replacing the new assemblies please take backup of old assemblies.
{Syncfusion Installed location} \Essential Studio\16.3.0.21\Xamarin\lib\pcl\Syncfusion.SfCalendar.XForms.dll 
{Syncfusion Installed location} \Essential Studio\16.3.0.21\Xamarin\lib\Android\Syncfusion.SfCalendar.XForms.dll 
{Syncfusion Installed location}\EssentialStudio\16.3.0.21\Xamarin\lib\Android\Syncfusion.SfCalendar.XForms.Android.dll 
{Syncfusion Installed location} \Essential Studio\16.3.0.21\Xamarin\lib\iOS\Syncfusion.SfCalendar.XForms.dll 
{Syncfusion Installed location}\EssentialStudio\16.3.0.21\Xamarin\lib\iOS\Syncfusion.SfCalendar.XForms.iOS.dll 

Disclaimer:
Please note that we have created these custom assemblies for version 16.3.0.21 .This fix will be included in our upcoming Vol 3 SP1 release which is expected to be available by end of October 2018. Please use the provided assemblies and let us know if you have any concern. 

Regards,
Vigneshkumar R 


Thanks!


VR Vigneshkumar Ramasamy Syncfusion Team October 11, 2018 05:11 AM UTC

 
Hi Amen, 
 
Thanks for the update. Please get in touch if you required further assistance on this. 
   
Regards 
Vigneshkumar R 


Loader.
Up arrow icon