Search code examples
c#androidxamarin.androidvisual-studio-mac

Xamarin/Visual studio for Mac: axml file does not appear in intellisense Class file and throw error on build


Hi everyone I'm writing a app on Visual studio for Mac/Xamarin with C# and I'm trying to add my axml file(Layout) named "Dialog_SignUp" into my class to call it but I don't understand why my intellisense does not recognize it and when I try to build it I have an error that said "Resource layout does not contain a definition of Dialog_SignUp (CS0117)".

Obviously my file exist and it is on the folder resource/layout/Dialog_SigbnUP.axml, so I have done some research on google but I've found nothing on this or I'm not putting the right key words on google.

Hope someone can help me. Thanks.

My Class DialogSignUp.cs:

using System;
using Android.App;
using Android.Widget;
using Android.OS;
using Android.Views;
using Android.Runtime;

namespace LoginSystem
{
    public class DialogSignUp : DialogFragment
    {
        public DialogSignUp()
        {
        }

        public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
        {
            base.OnCreateView(inflater, container, savedInstanceState);

            var view = inflater.Inflate(Resource.Layout.Dialog_SignUp, container, false);

            return view;
        }
    }
}

My Class Dialog_SignUp.axml:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:background="#DEDEDC"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:minWidth="300dp"
    android:minHeight="400dp">
    <EditText
        android:id="@+id/txtFirstName"
        android:layout_width="match_parent"
        android:layout_height="35dp"
        android:background="@drawable/edit_text_style"
        android:layout_marginBottom="10dp"
        android:layout_marginLeft="20dp"
        android:layout_marginRight="20dp"
        android:layout_marginTop="25dp"
        android:hint="First Name"
        android:paddingLeft="10dp"
        android:textColor="#000" />
    <EditText
        android:layout_below="@id/txtFirstName"
        android:inputType="textEmailAddress"
        android:layout_width="match_parent"
        android:layout_height="35dp"
        android:id="@+id/txtEmail"
        android:background="@drawable/edit_text_style"
        android:layout_marginBottom="10dp"
        android:layout_marginLeft="20dp"
        android:layout_marginRight="20dp"
        android:hint="Email"
        android:paddingLeft="10dp"
        android:textColor="#000" />
    <EditText
        android:inputType="textPassword"
        android:layout_width="match_parent"
        android:layout_height="35dp"
        android:id="@+id/txtPassword"
        android:background="@drawable/edit_text_style"
        android:layout_marginLeft="20dp"
        android:layout_marginRight="20dp"
        android:hint="Password"
        android:paddingLeft="10dp"
        android:textColor="#000"
        android:layout_below="@id/txtEmail" />
    <RelativeLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/txtPassword"
        android:layout_marginTop="50dp">
        <Button
            android:text="Sign Up!"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/btnDialogEmail"
            android:textSize="20dp"
            android:textColor="#fff"
            android:textStyle="bold"
            android:paddingLeft="5dp"
            android:paddingBottom="5dp"
            android:paddingRight="5dp"
            android:height="70dp"
            android:paddingTop="2dp"
            android:background="@drawable/ButtonSignUpStyle"
            android:layout_centerHorizontal="true"
            android:layout_marginLeft="30dp" />
    </RelativeLayout>
</RelativeLayout>

Solution

  • In you I would change filenames in lowercase with underscores, like "dialog_signup.axml". In theory both the conventions should be right but I always use the lowercase with underscores.

    Second, check that inside your .csproj there is the file inclusion. There should be something like:

    <AndroidResource Include="Resources\layout\dialog_signup.axml" />
    

    or

    <AndroidResource Include="Resources\layout\dialog_signup.axml">
        <SubType>Designer</SubType>
    </AndroidResource>
    

    Third, check that in the Resource.designer.cs there is a row like this:

    public const int dialog_signup = [int];
    

    Perhaps you simply need to build again the Resource.designer.cs