Articles in this section

How to bind JSON data to WPF Scheduler (Calendar)?

You can bind data from JSON to the WPF Scheduler appointments. 

C#

Create a JSON data model

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.

 

C#

Create JSON 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\"} ]";

C#

Deserialize the JSON data as list of JSON data model.

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

C#

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

public class Meeting
{
    public string EventName { get; set; }
    public DateTime From { get; set; }
    public DateTime To { get; set; }
    public Brush color { get; set; }
    public bool AllDay { get; set; }
}

C#

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

public SchedulerViewModel()
{
    Meetings = new ObservableCollection<Meeting>();
 
    List<JSONData> jsonDataCollection = JsonConvert.DeserializeObject<List<JSONData>>(JsonData);
 
    foreach (var data in jsonDataCollection)
    {
        Meetings.Add(new Meeting()
        {
            EventName = data.Subject,
            From = DateTime.Parse(data.StartTime),
            To = DateTime.Parse(data.EndTime),
            color = new SolidColorBrush((Color)ColorConverter.ConvertFromString(data.Background)),
            AllDay = Convert.ToBoolean(data.IsAllDay)
        });
    }
}

XAML

Bind appointments that collected through JSON data to a schedule using the Scheduler.ItemsSource property.

<Window.DataContext>
<local:SchedulerViewModel />
</Window.DataContext>
<Grid>
<syncfusion:SfScheduler x:Name="Schedule"
                                ItemsSource="{Binding Meetings}"
                                ViewType="Week">
    <syncfusion:SfScheduler.AppointmentMapping>
        <syncfusion:AppointmentMapping
                    EndTime="To"
                    StartTime="From"
                    Subject="EventName"
                    AppointmentBackground="color"
                    IsAllDay="AllDay"  />
    </syncfusion:SfScheduler.AppointmentMapping>
</syncfusion:SfScheduler>
</Grid>

View sample in GitHub

Demo image for JSON offline

Conclusion

I hope you enjoyed learning about how to bind JSON data to WPF Scheduler.

You can refer to our WPF Scheduler feature tour page to know about its other groundbreaking feature representations and documentation, and how to quickly get started for configuration specifications.

For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.

If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forumsDirect-Trac, or feedback portal. We are always happy to assist you!

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Access denied
Access denied