Forum General

ContentView does not compile: The type 'control1:FontAwesomeButton' was not found. Verify that you a

arame3333arame3333 GBMember ✭✭
edited August 2018 in General

I have created this ContentView:

    <?xml version="1.0" encoding="UTF-8"?>
    <ContentView xmlns="http://xamarin.com/schemas/2014/forms"
                 xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
                 xmlns:Control="clr-namespace:Xamstrap;assembly=Xamstrap"
                 xmlns:Attached="clr-namespace:Xamstrap.AttachedProperties;assembly=Xamstrap"
                 x:Class="Sir.Mobile.UserControls.FontAwesomeButton"
                 x:Name="this">
        <ContentView.Content>
            <Button Text="{Binding Text, Source={x:Reference this}}" Command="{Binding Command, Source={x:Reference this}}"
                      Attached:ResponsiveProperty.Class="{Binding ButtonClass, Source={x:Reference this}}">
                <Button.FontFamily>
                    <OnPlatform x:TypeArguments="x:String"
                                  Android="fa-solid-900.ttf#Font Awesome 5 Free Regular"
                                  iOS="Font Awesome 5 Free"
                                  WinPhone="Assets/fa-solid-900.ttf#Font Awesome 5 Free" />
                </Button.FontFamily>
            </Button>
        </ContentView.Content>
    </ContentView>

using Xamarin.Forms;
using Xamarin.Forms.Xaml;

    namespace Sir.Mobile.UserControls
    {
        [XamlCompilation(XamlCompilationOptions.Compile)]
        public partial class FontAwesomeButton : ContentView
        {
            public static readonly BindableProperty TextProperty = BindableProperty.Create(nameof(Text), typeof(string), typeof(FontAwesomeButton));

            public string Text
            {
                get => (string)GetValue(TextProperty);
                set => SetValue(TextProperty, value);
            }

            public static readonly BindableProperty ButtonClassProperty = BindableProperty.Create(nameof(ButtonClass), typeof(string), typeof(FontAwesomeButton));

            public string ButtonClass
            {
                get => (string)GetValue(ButtonClassProperty);
                set => SetValue(ButtonClassProperty, value);
            }

            public static readonly BindableProperty CommandProperty = BindableProperty.Create(nameof(Command), typeof(string), typeof(FontAwesomeButton));

            public string Command
            {
                get => (string)GetValue(CommandProperty);
                set => SetValue(CommandProperty, value);
            }

            public FontAwesomeButton()
            {
                InitializeComponent();
            }
        }
    }

And I put this in my ContentPage:

   <?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:controls="clr-namespace:XamForms.Controls;assembly=XamForms.Controls.Calendar"
                 xmlns:control1="clr-namespace:Sir.Mobile.UserControl"
                 xmlns:Control="clr-namespace:Xamstrap;assembly=Xamstrap"
                 xmlns:Attached="clr-namespace:Xamstrap.AttachedProperties;assembly=Xamstrap"
                 xmlns:c="clr-namespace:Sir.Mobile.CustomRenderers"
                 xmlns:prism="clr-namespace:Prism.Mvvm;assembly=Prism.Forms"
                 prism:ViewModelLocator.AutowireViewModel="True"
                 x:Class="Sir.Mobile.Views.InspectionDate"
                 ControlTemplate="{StaticResource MainHeader}"
                 Title="Inspection Date">
        <ContentPage.Resources>
            
            <StyleSheet Source="/Assets/Site.css" />
        </ContentPage.Resources>
        <ContentPage.Content>
            <StackLayout Orientation="Vertical"  HorizontalOptions="StartAndExpand">
                <Label Text="{Binding HeaderTitle3}" StyleClass="headerText"  Margin="0, 0, 0, 0"></Label>
                <StackLayout Orientation="Horizontal">
                    <StackLayout>
                        <controls:Calendar  SelectedDate="{Binding DateOfVisit, Mode=TwoWay}"
                                        HorizontalOptions="FillAndExpand" VerticalOptions="CenterAndExpand"
                                        x:Name="calendar" DateCommand="{Binding DateOfVisitCommand}" />
                    </StackLayout>
                    <StackLayout>
                        <control1:FontAwesomeButton Text="&#xf061;" Command="{Binding OnDateOfVisitCommand}" ButtonClass="btn-sm btn-primary" />
                    </StackLayout>
                </StackLayout>
            </StackLayout>
        </ContentPage.Content>
    </ContentPage>

And I get this error;

Error XLS0414 The type 'control1:FontAwesomeButton' was not found. Verify that you are not missing an assembly reference and that all referenced assemblies have been built. Sir.Mobile InspectionDate.xaml 28

There must be a simple explanation as to why I cannot get this to compile?
I am using this as a reference; https://xamarinhelp.com/xamarin-forms-user-control/

Tagged:

Best Answer

Answers

  • arame3333arame3333 GBMember ✭✭
    edited August 2018

    Ok that fixed the initial problem, so thank you for that. I should have spotted that myself, I must have cut and pasted the namespace - I will look out for that next time.
    But now I have a new problem; the Command property does not work. Perhaps I should ask as a seperate question?

  • Patrick.OConnorPatrick.OConnor USMember ✭✭

    Button.Command is of type System.Windows.Input.ICommand (see https://docs.microsoft.com/en-us/dotnet/api/xamarin.forms.button.command?view=xamarin-forms, not string.
    So you should replace

    public static readonly BindableProperty CommandProperty = BindableProperty.Create(nameof(Command), typeof(string), typeof(FontAwesomeButton));
    
    public string Command
    {
        get => (string)GetValue(CommandProperty);   
        set => SetValue(CommandProperty, value);
    }
    

    with

    public static readonly BindableProperty CommandProperty = BindableProperty.Create(nameof(Command), typeof(ICommand), typeof(FontAwesomeButton));
    
    public ICommand Command
    {
        get => (ICommand)GetValue(CommandProperty); 
        set => SetValue(CommandProperty, value);
    }
    

    add using System.Windows.Input; before your namespace declaration.

    and set the property like this:

    fontAwesomeButton.Command = new Command(() =>
    {
        // Do something
        // ...
    });
    
Sign In or Register to comment.