Search code examples
c#xamlxamarinxamarin.formscustom-renderer

XamarinForms: Use a Control from a Custom Renderer in XAML


I created my own custom renderer in Xamarin that looks like so:

namespace TestApp
{
    public class CustomEntry : Entry
    {
        public CustomEntry ()
        {
        }
    }
}

How can I include this in my HomePage.xaml file? I tried this:

<?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:TestApp;assembly:TestApp" 
x:Class="TestApp.SubPage">
    <ContentPage.Content>
        <StackLayout>
            <local:CustomEntry></local:CustomEntry>
        </StackLayout>
    </ContentPage.Content>
</ContentPage>

But it didn't work, saying CustomEntry is not a valid control in the "http://xamarin.com/schemas/2014/forms" namespace. Any ideas?


Solution

  • Nevermind, I found the problem. It seems that the xmlns:local declaration I had was wrong. I had this:

    <ContentPage xmlns="http://xamarin.com/schemas/2014/forms" 
    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" 
    xmlns:local="clr-namespace:TestApp;assembly:TestApp" 
    x:Class="TestApp.SubPage">
    

    And it was this:

    <ContentPage xmlns="http://xamarin.com/schemas/2014/forms" 
    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" 
    xmlns:local="clr-namespace:TestApp;assembly=TestApp" 
    x:Class="TestApp.SubPage">
    

    Seems that assembly was assigned with the '=' operator, not the ':' one. The class stayed the same and everything works now.