Bug 59878 - Using a custom renderer for NavigationPage results in InvalidCastException when calling base.OnElementChanged()
Summary: Using a custom renderer for NavigationPage results in InvalidCastException wh...
Status: CONFIRMED
Alias: None
Product: Forms
Classification: Xamarin
Component: Android (show other bugs)
Version: 2.4.0
Hardware: PC Windows
: Normal normal
Target Milestone: ---
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2017-10-01 06:45 UTC by Nicholas Bauer
Modified: 2017-10-03 21:25 UTC (History)
2 users (show)

See Also:
Tags: custom renderer, navigationpage, ac
Is this bug a regression?: ---
Last known good build:


Attachments

Description Nicholas Bauer 2017-10-01 06:45:31 UTC
Using this custom renderer causes InvalidCastException inside the base class OnElementChanged function:

using Xamarin.Forms.Platform.Android;
using Xamarin.Forms;
using MyApp.Droid.Renderers;

[assembly: ExportRenderer(typeof(NavigationPage), typeof(NavigationPageRenderer))]
namespace MyApp.Droid.Renderers
{
    public class NavigationPageRenderer : NavigationRenderer
    {
        protected override void OnElementChanged(ElementChangedEventArgs<NavigationPage> e)
        {
            base.OnElementChanged(e);
        }
    }
}

It may or may not matter, but in my case, the NavigationPage in question is being used inside a MasterDetailPage Detail pane.


This bug appears to be documented elsewhere:

https://forums.xamarin.com/discussion/71524/masterdetail-and-navigationpage-custom-renderer-both-fail

https://forums.xamarin.com/discussion/96232/invalidcastexception-when-calling-base-onelementchanged-e-in-custom-renderer
Comment 1 Nicholas Bauer 2017-10-03 21:25:17 UTC
Ah... I figured out the problem.

It's AppCompat vs. regular. Which I had no idea was a thing until encountering this.

It would be really useful to have an informative exception message to direct developers to the correct classes.

Note You need to log in before you can comment on or make changes to this bug.