Calendar: NullReferenceException when setting the AppointmentsSource in UWP
Hi, I am getting NullReferenceException when trying to set AppointmentsSource for RadCalendar (version 2020.3.916.1) in my page, however, it is set and displayed successfully in the Android project.
7 comments
Mehdi
Posted on:05 Dec 2020 20:13
Thanx a lot (Y)
ADMIN
Yana
Posted on:04 Dec 2020 07:22
Hello guys,
Thank you, Lance, for helping sort out this issue.
I have updated the status of this item to "Declined" and raised the priority of the initial issue on UWP, so hopefully we'll manage to look into it soon.
Regards,
Yana
Progress Telerik
Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.
Mehdi
Posted on:02 Dec 2020 23:46
<p>Dear Lance,</p><p>Thanks a lot for the help. Actually this problem took the whole weekend from me, and made me so upset. But now everything will be good, both for this and the ListView. </p>
Warm regards,
Mehdi
ADMIN
Lance | Senior Manager Technical Support
Posted on:02 Dec 2020 20:10
Hello Mehdi,
Thank you for the update with more details.
The reason for the problem is still that same issue as you saw in the threads, but for a slightly different reason. In your case, you are loading the data too fast, before the native control is available, which is the root of the exception.
Solution
To solve this, do not use the page's OnAppearing. Instead, use the RadClaendar's NativeControlLoaded event to set the AppointmentSource.
This will give your app time to load the native component before attempting to start using it.
using System;
using System.Collections.ObjectModel;
using Telerik.XamarinForms.Input;
using Xamarin.Forms;
namespaceXamarinAppUWP
{
publicpartialclassMainPage : ContentPage
{
publicMainPage()
{
InitializeComponent();
}
privatevoidMyCalendar_OnNativeControlLoaded(object sender, EventArgs e)
{
var today = DateTime.Today;
var items = new ObservableCollection<Appointment>
{
new Appointment { Color = Color.Green, Title = "T1", Detail = "D1", StartDate = today, EndDate = today.AddHours(2) },
new Appointment { Color = Color.Red, Title = "T2", Detail = "D2", StartDate = today.AddDays(1), EndDate = today.AddDays(1).AddHours(2) },
new Appointment { Color = Color.Blue, Title = "T3", Detail = "D3", StartDate = today.AddDays(2), EndDate = today.AddDays(2).AddHours(2) }
};
(sender as RadCalendar).AppointmentsSource = items;
}
}
}
Runtime
Notes
For the purposes of this discussion, it doesn't matter if you're using our built-in Appointment or a custom IAppointment
If you use any other View type, then the Calendar will wait to set the AppointmentSource until that view type has changed.
Demo
I have attached the updated demo. Please follow these steps to make sure you have properly unblocked the ZIP before extracting the files.
1. Download my attachment
2. Right-click on the ZIP file and select "Properties"
3. Select "Unblock" checkbox and then click "OK" (now you can unzip it)
4. Right-click on the ZIP file and select "Extract All"
5. Now you can open the sln in Visual Studio (I only kept the UWP project so it will load faster)
Unrelated
As to why you are having issues with Visual Studio is outside the control of our components. I'm not sure what the issue is there, I can confirm the sln and csproj files are correct. It may have been that you didnt unblock the ZIP, but I cant be sure without seeing the VS logs.
In any case, you should definitely make sure you're up to date on Visual Studio 2019. There have been some major changes with Xamarin that are required. Please run the Visual Studio Installer app (it is already on your machine) and make sure you're using at least v16.8.2.
Regards,
Lance | Manager Technical Support
Progress Telerik
Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.
Thanks for the reply. First, I think it's so obvious that the samples should be as simple as possible, so I really don't understand why your support team keeps using MVVM pattern in their samples! I am setting the AppointmentsSource programmatically, and moreover, I am using a class implementing the Telerik.XamarinForms.Input.IAppointment. Second, as the attached screenshot shows, your sent sample wasn't loaded! Third, because of the projects' dependencies, I can't send you any code instances but I have captured a video from my screen, which I hope to be useful (I have also tried to delete all applied themes and styles to the calendar, but the exception was still thrown ). Finally, based on my previous experiences about your products years ago, this was me that suggested my manager to buy and use your products, and now I am disappointed for that decision because clearly your produced components are designed so bad. For example, your RadListView, in spite of using Xamarin.Forms.Cell-inherited cells, doesn't support MenuItems! Why? Haven't your components been written in an object-oriented language? Are you using Fortran for example?
You know what? When a software developer or engineer recommends your products to their company, their normal expectation from such a famous company like you is that your components have been designed and implemented object oriented, so that for example, if your component inherits from the basic ListView or Cell, they expect that it DOES support ALL its base class's functionalities. However, what I observe now is that, for example, your RadListView doesn't support MenuItems and ContextOptions, while its base class does! Have you asked yourselves if someone like me doesn't like to implement the context menu item functionality using your SWIPPING approach? Now I have to change the RadListView wherever it's used?!
I would need more details on the concrete setup, as I didn't manage to reproduce this issue on UWP with our latest releases. I have attached my test project where the AppointmentsSource is set inside OnAppearing event, could you please download it and give it a try? Can you modify it, so that it resembles your actual setup and send it back to me?
Thanks in advance
Regards,
Yana
Progress Telerik
Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.