Appointment Problems

I am trying to add a test appointment before I connect the Schedule to our database, but I ran into a problem. I created a class with the generic properties, including Name, From, To, and Color. Then I added the Appointment Mappings to my view. Then in my c# I added the appointment almost exactly how they did in the example. However, I got an error saying: "System.InvalidCastException: Specified cast is not valid."

Does anyone have a clue on what I could do? Here is my c# code.

private void AddJobs()
        {
            JobInstall jobInstall = new JobInstall();

            jobInstall.From = new DateTime(2018, 07, 19);

            jobInstall.To = jobInstall.From.AddHours(5);

            jobInstall.JobName = "Suprise";

            jobInstall.Color = ConsoleColor.Cyan;

            var JobInstalls = new ObservableCollection<JobInstall>();

            JobInstalls.Add(jobInstall);

            schedule.DataSource = JobInstalls;
        }

3 Replies

VR Vigneshkumar Ramasamy Syncfusion Team July 18, 2018 12:22 PM UTC

Hi Dalan, 
 
Thanks for contacting Syncfusion support. 
 
As per implementation in SfSchedule Xamarin Forms control, it is only possible to map Color property of appointment with the custom property of type Xamarin.Forms.Color (that is of same data type) using ColorMapping property of ScheduleAppointmentMapping. In your code you have used ConsoleColor type for ColorMapping, so that InvalidCastException occurs since the default data type of Color property of ScheduleAppointment is Xamarin.Forms.Color. 
 
Either you can change the type of Color property in JobInstall class to Xamarin.Forms.Color or else if you don’t want to change model class (JobInstall) , you can declaring a new property (Color type) in a class derived from your existing class. We have prepared a sample for the same and please find the sample in the below link. 
 
Sample link:ScheduleSample 
Please find the code snippet below 
C# 
  public class CustomAppointment : JobInstall 
    { 
        public Color MappingColor 
        { 
            get 
            { 
                return ColorConverter(); 
            } 
        } 
 
        public Color ColorConverter() 
        { 
            if (this.Color == ConsoleColor.Cyan) 
            { 
                return Xamarin.Forms.Color.Cyan; 
            } 
            else if (this.Color == ConsoleColor.Blue) 
            { 
                return Xamarin.Forms.Color.Blue; 
            } 
            return Xamarin.Forms.Color.Default; 
        } 
    } 
 
XAML 
 
<syncfusion:SfSchedule x:Name="schedule"  
                     ScheduleView = "WeekView" > 
                                  <syncfusion:SfSchedule.AppointmentMapping> 
            <syncfusion:ScheduleAppointmentMapping 
                ColorMapping="MappingColor" 
                EndTimeMapping="To" 
                StartTimeMapping="From" 
                SubjectMapping="JobName"/> 
        </syncfusion:SfSchedule.AppointmentMapping> 
              </syncfusion:SfSchedule> 
 
 
Please let us know if this helpful.  
 
Regards 
Vigneshkumar R 



DK Dalan Kelsch July 18, 2018 02:48 PM UTC

That worked thank you!  I should've thought to check all the things I was adding. Good to know for future reference.


VR Vigneshkumar Ramasamy Syncfusion Team July 19, 2018 04:52 AM UTC

Hi Dalan, 
 
We are glad to know that your requirement has been achieved. Please get in touch if need further assistance on this.  
 
Regards 
Vigneshkumar R 


Loader.
Up arrow icon