Hello,
I am getting the following exception, when I use the Calendar control in Year view mode. (The same also happens when the calendar is in week mode)
2015-04-21 11:57:37.212 DzjinTonikMobileiOS[706:165460] Unhandled managed exception: Unable to cast object of type 'TelerikUI.TKCalendarYearPresenter' to type 'UIKit.UIView' (System.InvalidCastException)
at ObjCRuntime.Runtime.GetNSObject[UIView] (IntPtr ptr) [0x00000] in <filename unknown>:0
at UIKit.UIView.get_Superview () [0x00010] in /Developer/MonoTouch/Source/monotouch/src/build/native/UIKit/UIView.g.cs:3239
at Xamarin.Forms.Platform.iOS.PageRenderer+<ViewAndSuperviewsOfView>d__0.MoveNext () [0x00000] in <filename unknown>:0
at System.Linq.Enumerable.Any[UIView] (IEnumerable`1 source, System.Func`2 predicate) [0x00000] in <filename unknown>:0
at Xamarin.Forms.Platform.iOS.PageRenderer.OnShouldReceiveTouch (UIKit.UIGestureRecognizer recognizer, UIKit.UITouch touch) [0x00000] in <filename unknown>:0
at UIKit.UIGestureRecognizer+_UIGestureRecognizerDelegate.ShouldReceiveTouch (UIKit.UIGestureRecognizer recognizer, UIKit.UITouch touch) [0x0000d] in /Developer/MonoTouch/Source/monotouch/src/
build/native/UIKit/UIGestureRecognizer.g.cs:625
at (wrapper managed-to-native) UIKit.UIApplication:UIApplicationMain (int,string[],intptr,intptr)
at UIKit.UIApplication.Main (System.String[] args, IntPtr principal, IntPtr delegate) [0x00005] in /Developer/MonoTouch/Source/monotouch/src/UIKit/UIApplication.cs:62
at UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x0001c] in /Developer/MonoTouch/Source/monotouch/src/UIKit/UIApplication.cs:45
at DzjinTonikMobile.iOS.Application.Main (System.String[] args) [0x00001] in d:\iBoris\DzjinTonikMobile\Main\DzjinTonikMobile\DzjinTonikMobile.iOS\Main.cs:12
My details:
OS: Windows 8.1
Regional settings: bg-BG
IDE: Visual studio Premium 2013 version 12.0.31101.00 update 4
Xamarin SDK: 3.9.547.0
Xamarin.iOS 8.9.1.0
Telerik for Xamarin version: 2015.1.319
Regards,
Mihail
24 Answers, 1 is accepted
Are you able to reproduce the issue consistently? We were able to reproduce it, but it seems to happen intermittently. To make it more complex, the stack trace does not contain code from Telerik and the only clue we have at the moment is that the framework tries to handle TKCalendarYearPresenter as UIView. We will continue to look into the problem and we'll get back to you when we have more info.
Best regards,
Ves
Telerik
See What's Next in App Development. Register for TelerikNEXT.

Ves,
Thank you for the fast reply.
Yes, this problem occurs every time when I try to click on some month (when in year mode) or when I click on a certain day (when in week mode).
I am looking forward to future release that will fix this unfortunate problem.
Regards,
Mihail
We located the issue and it will be addressed with our upcoming release later this month. I added the issue in our feedback portal where you can track its status. I updated also your Telerik points for reporting it.
Should you have any additional questions, do not hesitate to ask.
Regards,
Jack
Telerik

Jack,
If you look up you will see that I reported the issue, not Trevor. Actually, at the time that I posted this, I was able to reproduce the bug also in the simulator.
Nevertheless, I am glad that a fix will come in the next release.
Regards,
Pavel
Thank you for pointing this out. Yes, I confirm that the issue occurs both when using a simulator and on device. I updated your points accordingly.
Regards,
Jack
Telerik
It seems that there is no EvaluateCellStyle method in our UI for iOS, UI for Android or UI for Xamarin suites of controls. Where do you find it? Where it is defined?
Please elaborate more on your scenario.
Regards,
Pavel R. Pavlov
Telerik
Its mentioned in the Calendar for Tamarin.Forms Styling
http://docs.telerik.com/devtools/xamarin/controls/calendar/features/calendar-styling
The confusion comes from the fact that "EvaluateCellStyle" is the name of a custom method used for demonstration purposes in the referenced article. It is not part of our control.
Anyway, I got your point. Let me try to explain what is happening on your side. I would like to turn your attention to the fact that the article demonstrates how the RadCalendar.SetStyleForCell property can be used. Note that users are able to determine the type of the cell. There are three types of cells in the RadCalendar:
- Date - this is the type of all dates in a month.
- WeekNumber - if visualized these are the cells displaying which number is the visualized week.
- DayName - this is the row displaying the name of the days (e.g. Monday, Tuesday, Wednesday...)
This property should be used for customizing the mentioned aspects only. If you need to customize how the separate dates look like you need to change your approach.
For example you can check if the cell that comes in the custom method is of type DayName or WeekNumber. If so you can return the appropriate CalendarCellStyle. If the cell is neither of them you can determine what exactly the cell will be used for based on the properties of the cell itself. You can cast it to CalendarDayCell and then check its properties. You can use the following code to start the required customization:
private
CalendarCellStyle SetStyleForCell(CalendarCell cell)
{
if
(cell.Type == CalendarCellType.DayName)
{
return
new
CalendarCellStyle
{
BackgroundColor = Color.Transparent,
BorderColor = Color.Silver,
BorderThickness = CalendarCustomResources.Instance.BorderThickness,
FontSize = CalendarCustomResources.Instance.DayNamesFontSize,
FontWeight = FontWeight.Bold,
ForegroundColor = Color.FromRgb(0, 122, 255)
};
}
if
(cell.Type == CalendarCellType.WeekNumber)
{
return
new
CalendarCellStyle
{
BackgroundColor = CalendarCustomResources.Instance.Background,
BorderColor = Color.Silver,
BorderThickness = CalendarCustomResources.Instance.BorderThickness,
FontSize = CalendarCustomResources.Instance.WeekNumbersFontSize,
FontWeight = FontWeight.Normal,
ForegroundColor = Color.Silver
};
}
var defaultStyle =
new
CalendarCellStyle
{
BackgroundColor = CalendarCustomResources.Instance.Background,
BorderColor = Color.Silver,
BorderThickness = CalendarCustomResources.Instance.BorderThickness,
FontSize = CalendarCustomResources.Instance.FontSize,
FontWeight = FontWeight.Normal,
ForegroundColor = Color.FromRgb(139, 209, 0)
};
var dayCell = cell
as
CalendarDayCell;
if
(dayCell !=
null
)
{
if
(dayCell.IsFromCurrentMonth)
{
if
(dayCell.IsToday)
{
defaultStyle.ForegroundColor = Color.FromRgb(0, 122, 255);
defaultStyle.FontWeight = FontWeight.Bold;
}
}
else
{
if
(dayCell.IsToday)
{
defaultStyle.ForegroundColor = Color.FromRgb(115, 174, 239);
}
else
{
defaultStyle.ForegroundColor = Color.FromRgb(166, 181, 137);
//212, 251, 133);
}
}
if
(dayCell.IsSelected)
{
defaultStyle.ForegroundColor = CalendarCustomResources.Instance.SelectedCellForegroundColor;
}
return
defaultStyle;
}
Pavel R. Pavlov
Telerik

Was this original issue from April resolved?
I am also encountering this when I zoom out to the month view then select a month.
We will release our latest version of the components by the end of the workday today. You will be able to check if your issue is properly addressed and fixed. If however the issue still exist, please contact us with some additional details on that matter.
Regards,
Pavel R. Pavlov
Telerik

Could you please share with us a sample project demonstrating the reported issue? It will help us to investigate the reasons behind. Also it will be nice to share exact steps that reproduce the behavior on your side.
We are looking forward to hearing from you.
Regards,
Pavel R. Pavlov
Telerik by Progress

Hey Pavel,
Well, let me pose this question first and this might solve the problem.
It appears that in iOS that if the CalendarViewMode is Year and I select a month, RadCalendar does not automatically go to that month like Android does. Is this a known issue or am I missing something? My only solution to this problem was to do the following:
private
void
InitCalendar(CalendarViewMode mode)
{
ViewMode = mode;
calendar =
new
RadCalendar()
{
HorizontalOptions = LayoutOptions.FillAndExpand,
VerticalOptions = LayoutOptions.FillAndExpand,
};
calendar.ViewChanged += calendar_ViewChanged;
calendar.SelectionChanged += (sender, args) =>
{
if
(calendar.ViewMode == CalendarViewMode.Year)
{
InitCalendar(CalendarViewMode.Month);
}
};
calendar.NativeControlLoaded += (sender, arg) =>
{
(sender
as
RadCalendar).TrySetViewMode( ViewMode);
};
calendar.SetStyleForCell = EvaluateCellStyle;
Content = calendar;
}
I tested the reported steps and could not see the behavior that you observe. Could you please share with us the version of our components that you use? This may be a difference that matters in this scenario.
Regards,
Pavel R. Pavlov
Telerik by Progress

Pavel,
Just a reminder, you have to build using "Release" configuration. The version is 2016.6.614.
Also, are you saying that in iOS "Year" view mode, when you select a month that it should automatically switch to the Month view like Android?
Thanks.

Please accept our apology for misleading you. It is true that in Year ViewMode the iOS RadCalendar does not navigate to the specific month after tap. You should set the ViewMode to MonthNames in order to achieve the behavior that you need.
Please give this approach a try and let us know if you need any further assistance.
Regards,
Pavel R. Pavlov
Telerik by Progress

Hello Pavel,
I think the bug still exist because we also encountered it but can only reproduce it reliable when deploying it on a real device. What we try to do is displaying the RadCalendar initially in CalendarViewMode 'Month'. After loading the user has the opportunity to select CalendarViewMode 'Year'. After the Calendar has switched the viewMode the user taps/touches on a month and the app crashes with the following exception in the VisualStudio Output Window:
System.InvalidCastException: Unable to cast object of type 'TelerikUI.TKCalendarYearPresenter' to type 'UIKit.UIView'
at ObjCRuntime.Runtime.GetNSObject[T] (IntPtr ptr) <0x108a03c + 0x00278> in <filename unknown>:0
at UIKit.UIView.get_Superview () [0x00010] in /Users/builder/data/lanes/3539/f37444ae/source/maccore/src/build/ios/native/UIKit/UIView.g.cs:3648
at Xamarin.Forms.Platform.iOS.PageRenderer+<ViewAndSuperviewsOfView>d__34.MoveNext () [0x00035] in C:\BuildAgent\work\aad494dc9bc9783\Xamarin.Forms.Platform.iOS\Renderers\PageRenderer.cs:223
at Xamarin.Forms.Platform.iOS.PageRenderer.OnShouldReceiveTouch (UIKit.UIGestureRecognizer recognizer, UIKit.UITouch touch) [0x00037] in C:\BuildAgent\work\aad494dc9bc9783\Xamarin.Forms.Platform.iOS\Renderers\PageRenderer.cs:189
at UIKit.UIGestureRecognizer+_UIGestureRecognizerDelegate.ShouldReceiveTouch (UIKit.UIGestureRecognizer recognizer, UIKit.UITouch touch) [0x0000d] in /Users/builder/data/lanes/3539/f3744
4ae/source/maccore/src/build/ios/native/UIKit/UIGestureRecognizer.g.cs:819
at (wrapper managed-to-native) UIKit.UIApplication:UIApplicationMain (int,string[],intptr,intptr)
at UIKit.UIApplication.Main (System.String[] args, IntPtr principal, IntPtr delegate) [0x00005] in /Users/builder/data/lanes/3539/f37444ae/source/maccore/src/UIKit/UIApplication.cs:79
at UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x0001c] in /Users/builder/data/lanes/3539/f37444ae/source/maccore/src/UIKit/UIApplication.cs:62
at Mobile.Forms.View.iOS.Application.Main (System.String[] args) [0x00002] in D:\XXX\YYY\proj\dev\dev\src\Mobile\Forms\View\View.iOS\Main.cs:16
The app has been terminated.
The app crashes without having any chance to catch an event from RadCalendar like 'ViewChanged', 'SelectionChanged' nor 'DisplayDateChanged'.
Details:
Tested on iPhone 5 and iPad 2
Telerik UI for Xamarin: latest stable nuget version 2016.3.830.1
Xamarin.Forms Version 2.3.1.114
Visual Studio 2015 Enterprise Update 3
Region Settings: 'de-DE'
Thanks in advance
Chris

*UPDATE*
I just encountered a strange behavior. The described behavior only occurs when the device is connected (via usb) to the mac. When it's not plugged in and I start our debug compiled app it doesn't crash.
Maybe this will help a little bit
Regards
Chris
Thank you for this report.
We confirm that this is actually a bug in the RadCalendar control and we will do our best to provide a fix for it in some of our future releases.
Your Telerik points are updated accordingly.
Regards,
Vladislav
Telerik by Progress

Hi, I have just encountered this bug, it seems my app throws the invalid cast exception only on my iphone 6, not in the simulator at all. It throws it in release and debug with and without the usb cable attached. Is there a bug report for this one so I can follow its progress? It is seriously hindering our development efforts.
Thanks, James.
Thank you for contacting us.
We confirm that this issue is more general than it's original description in this thread.
It is already logged and I just made it visible here where you can track it's progress.
Regards,
Vladislav
Telerik by Progress