I'm using the calendar control in the master page of a master/detail scenario.When I perform a modal navigation to another page and then navigate back, the calendar crashes with this exception:
"System.NullReferenceException: Object reference not set to an instance of an object. at Telerik.UI.Xaml.Controls.Input.Calendar.XamlHeaderContentLayer.MeasureContent(Object owner, Object content) at Telerik.UI.Xaml.Controls.Input.RadCalendar.Telerik.Core.IElementPresenter.MeasureContent(Object owner, Object content) at Telerik.UI.Xaml.Controls.Input.Calendar.CalendarMonthViewModel.GetCalendarViewRect(RadRect availableRect) at Telerik.UI.Xaml.Controls.Input.Calendar.CalendarMonthViewModel.Upd"
Am I doing something wrong?
Telerik_UI_for_Xamarin 2018.2.620.250
Shared code project targets .NET Standard 2.0
Xamarin Forms 2.5.1.527436
UWP
Here is the relevant code, simplified as much as possible:
MainPage.xaml
<?xml version="1.0" encoding="utf-8" ?><MasterDetailPage xmlns="http://xamarin.com/schemas/2014/forms" x:Class="RadCalendarBug.MasterDetailPage" xmlns:pages="clr-namespace:RadCalendarBug" x:Name="Self"> <MasterDetailPage.ToolbarItems> <ToolbarItem Name="Settings" Order="Primary" Command="{Binding ShowSettingsCommand, Source={x:Reference Name='Self'}}" > <ToolbarItem.Icon> <OnPlatform x:TypeArguments="FileImageSource"> <On Platform="UWP" Value="Resources/Settings.png" /> </OnPlatform> </ToolbarItem.Icon> </ToolbarItem> </MasterDetailPage.ToolbarItems> <MasterDetailPage.Master> <pages:MasterPage x:Name="MasterPage" /> </MasterDetailPage.Master> <MasterDetailPage.Detail> <NavigationPage> <x:Arguments> <pages:DetailPage /> </x:Arguments> </NavigationPage> </MasterDetailPage.Detail></MasterDetailPage>
Main.xaml.cs
using Xamarin.Forms;using Xamarin.Forms.Xaml;namespace RadCalendarBug{ [XamlCompilation(XamlCompilationOptions.Compile)] public partial class MasterDetailPage : Xamarin.Forms.MasterDetailPage { public Command ShowSettingsCommand { private set; get; } public MasterDetailPage() { ShowSettingsCommand = new Command(ShowSettings, CanShowSettings); InitializeComponent(); } private bool CanShowSettings(object arg) { return true; } private void ShowSettings(object obj) { Navigation.PushModalAsync(new NavigationPage(new Settings())); } }}
MasterPage.xaml
<?xml version="1.0" encoding="utf-8" ?><ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:telerikInput="clr-namespace:Telerik.XamarinForms.Input;assembly=Telerik.XamarinForms.Input" x:Class="RadCalendarBug.MasterPage" Title="Master"> <Grid> <Grid.RowDefinitions> <RowDefinition Height="500"/> <RowDefinition Height="1*"/> </Grid.RowDefinitions> <Grid.ColumnDefinitions> <ColumnDefinition Width="*"/> </Grid.ColumnDefinitions> <telerikInput:RadCalendar x:Name="calendar" /> <Label Grid.Row="1" Text="BottomHalf" /> </Grid></ContentPage>
MasterPage.xaml.cs
using Xamarin.Forms;using Xamarin.Forms.Xaml;namespace RadCalendarBug{ [XamlCompilation(XamlCompilationOptions.Compile)] public partial class MasterPage : ContentPage { public MasterPage() { InitializeComponent(); } }}
DetailPage.xaml
<?xml version="1.0" encoding="utf-8" ?><ContentPage xmlns="http://xamarin.com/schemas/2014/forms" x:Class="RadCalendarBug.DetailPage" Title="Detail"> <StackLayout Padding="10"> <Label Text="This is a detail page. "/> </StackLayout></ContentPage>
DetailPage.xaml.cs
using Xamarin.Forms;using Xamarin.Forms.Xaml;namespace RadCalendarBug{ [XamlCompilation(XamlCompilationOptions.Compile)] public partial class DetailPage : ContentPage { public DetailPage() { InitializeComponent(); } }}
Settings.xaml
<?xml version="1.0" encoding="utf-8" ?><ContentPage xmlns="http://xamarin.com/schemas/2014/forms" x:Class="RadCalendarBug.Settings" x:Name="Self"> <ContentPage.ToolbarItems> <ToolbarItem Name="Cancel" Order="Default" Command="{Binding CancelCommand, Source={x:Reference Name='Self'}}" Priority="1"> <ToolbarItem.Icon> <OnPlatform x:TypeArguments="FileImageSource"> <On Platform="UWP" Value="Resources/Cancel.png" /> </OnPlatform> </ToolbarItem.Icon> </ToolbarItem> </ContentPage.ToolbarItems> <ContentPage.Content> <StackLayout> <Label Text="Welcome to Xamarin.Forms!" VerticalOptions="CenterAndExpand" HorizontalOptions="CenterAndExpand" /> </StackLayout> </ContentPage.Content></ContentPage>
Settings.xaml.cs
using Xamarin.Forms;using Xamarin.Forms.Xaml;namespace RadCalendarBug{ [XamlCompilation(XamlCompilationOptions.Compile)] public partial class Settings : ContentPage { public Command CancelCommand { private set; get; } public Settings () { CancelCommand = new Command(Cancel, CanCancel); InitializeComponent(); } private bool CanCancel(object arg) { return true; } private void Cancel(object obj) { Navigation.PopModalAsync(); } }}
I'm not attaching the icons for the toolbar buttons but they're not really needed. Just click the ... button in the app bar to show the toolbar item text.
From the main page, click ..., then settings to navigate to the settings page. In the settings page, click ... then Cancel to go back. Note the exception.
Any pointers are appreciated.
