0
votes

I'm trying to create a button renderer. I followed the custom renderer for an entry found here:

The solution is build using PLC.

Am I using the wrong assemblies?

More info on error:

Xamarin.Forms.Xaml.XamlParseException was thrown

Type local:MyButton not found in xmlns:local="clr-namespace:MyApp;assembly=MyApp"

https://developer.xamarin.com/guides/xamarin-forms/application-fundamentals/custom-renderer/entry/

and I get a xaml parse exception error.

<?xml version="1.0" encoding="UTF-8"?>
<ContentPage 
    xmlns="http://xamarin.com/schemas/2014/forms" 
    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" 
    xmlns:local="clr-namespace:MyApp;assembly=MyApp"
    x:Class="MyApp.LoginPage"
    BackgroundColor="White">
    <StackLayout>           
            <local:MyButton
                Text="Login"
                TextColor="Blue"
                BackgroundColor="Transparent"
                HorizontalOptions="CenterAndExpand" />
    </StackLayout>
</ContentPage>

Android Renderer:

using Xamarin.Forms.Platform.Android;
using Xamarin.Forms;
using DeliveryTracker;
using DeliveryTracker.Droid;

[assembly: ExportRenderer(typeof(MyButton), typeof(MyButtonRenderer))]

    namespace MyApp.Droid
    {
        class MyButtonRenderer : ButtonRenderer
        {
            protected override void OnDraw(Android.Graphics.Canvas canvas)
            {
                base.OnDraw(canvas);
            }
        }
    }

In Forms:

using System;
using Xamarin.Forms;

namespace MyApp
{
    public class MyButton : Button
    {
        public MyButton()
        {
        }
    }
}
1
You haven't told us anything about what error you've seen. "A xaml parse exception" doesn't give us nearly enough information. What's the error message? Do it specify a particular location within your XAML? - Jon Skeet
enable XAML Compilation to get more info about the root cause: developer.xamarin.com/guides/xamarin-forms/xaml/xamlc - Jason
The error comes from the XAML preview. After running the app in the simulator I get no errors and it display the custom button renderer. - MartDavious
@MartDavious File a bug : bugzilla.xamarin.com - SushiHangover
Try removing the ";assembly=MyApp" part in your namespace declarations, so just xmlns:local="clr-namespace:MyApp". Did you by any change rename your project or namespaces or something? Make sure your namespace in the XAML is the same as where your control is declared. - Gerald Versluis

1 Answers

3
votes

Have you tried

xmlns:local="clr-namespace:MyApp"

Instead of

xmlns:local="clr-namespace:MyApp;assembly=MyApp"

? If it works, you have probably renamed your project or changed your namespace. It has already happened to me. Check your control's namespace and make sure it is the same as in your XAML.