Articles in this section
Category / Section

How to bind JSON data to Schedule?

1 min read

How to bind JSON data to Schedule?

You can bind data to the schedule appointments from JSON by following the steps:


  1. Create a JSON data model.


    /// <summary>   
    /// Represents custom data properties.   
    /// </summary>  
    public class JSONData
        public string Subject { get; set; }
        public string StartTime { get; set; }
        public string EndTime { get; set; }
        public string IsAllDay { get; set; }
        public string Background { get; set; }

Note: Convert String type into DateTime type when adding items to the local collection from JSON data model, since JSON does not support DateTime type.


  1. Create data for the data model.


// Add data for JSON Data model
private string jsonData =
            "[{\"Subject\": \"General Meeting\",\"StartTime\": \"30-08-2018 15:00:00\",\"EndTime\":\"30-08-2018 16:00:00\",\"Background\":\"#5944dd\", \"IsAllDay\":\"True\"}, " +
            "{\"Subject\": \"Plan Execution\",\"StartTime\": \"22-08-2018 10:00:00\",\"EndTime\":\"22-08-2018 11:00:00\",\"Background\":\"#ff0000\", \"IsAllDay\":\"False\"}," +
            "{\"Subject\": \"Performance Check\",\"StartTime\": \"17-08-2018 17:00:00\",\"EndTime\":\"17-08-2018 18:00:00\",\"Background\":\"#5944dd\", \"IsAllDay\":\"False\"}," +
            "{\"Subject\": \"Consulting\",\"StartTime\": \"03-08-2018 9:00:00\",\"EndTime\":\"03-08-2018 11:00:00\",\"Background\":\"#ed0497\", \"IsAllDay\":\"True\"}," +
            "{\"Subject\": \"Yoga Therapy\",\"StartTime\": \"27-08-2018 10:00:00\",\"EndTime\":\"27-08-2018 11:00:00\",\"Background\":\"#ff0000\", \"IsAllDay\":\"False\"}," +
            "{\"Subject\": \"Project Plan\",\"StartTime\": \"30-08-2018 15:00:00\",\"EndTime\":\"30-08-2018 16:00:00\",\"Background\":\"#ed0497\", \"IsAllDay\":\"False\"} ]";


  1. Deserialize the JSON data as list of JSON data model.


     List<JSONData> jsonDataCollection = JsonConvert.DeserializeObject<List<JSONData>>(jsonData);


  1. Create another class other than JSON data modal class for appointment mapping, since JSON data modal class does not support certain data types.


/// <summary>   
    /// Represents custom data properties.   
    /// </summary>  
    public class Meeting
        public string EventName { get; set; }
        public DateTime From { get; set; }
        public DateTime To { get; set; }
        public bool AllDay { get; set; }
        public Color Color { get; set; }

Refer to the following UG link for more details about creating custom appointment mapping:


  1. Add the JSON data list into the appointment collection (Meetings).


// Creates Meetings and stores in a collection
public ObservableCollection<Meeting> Meetings  { get; set; }
Meetings = new ObservableCollection<Meeting>();
            foreach (var data in jsonDataCollection)
                Meetings.Add(new Meeting()
                    EventName = data.Subject,
                    From = Convert.ToDateTime(data.StartTime),
                    To = Convert.ToDateTime(data.EndTime),
                    Color = Color.FromHex(data.Background),
                    AllDay = Convert.ToBoolean(data.IsAllDay)



  1. Bind it to a schedule using the SfSchedule.DataSource property.


<schedule:SfSchedule x:Name="schedule" 
        DataSource = "{Binding Meetings}"
        ScheduleView = "WeekView" >





Did you find this information helpful?
Help us improve this page
Please provide feedback or comments
Comments (0)
Please  to leave a comment
Access denied
Access denied