Forum Xamarin.Forms


The Xamarin Forums have officially moved to the new Microsoft Q&A experience. Microsoft Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

To create new threads and ask questions head over to Microsoft Q&A for .NET and get involved today.

Visual Studio 2019, Xamarin.Android, and ContentPage

njsokalskinjsokalski Member ✭✭✭

I am a UWP developer attempting to learn Xamarin to convert my apps for Android. I know almost nothing about Xamarin or Android, so please forgive me if I am missing anything obvious. When selecting "Android App (Xamarin)" in Visual Studio 2019 (I think I have installed all related updates and workloads), the project that is created includes MainActivity.cs, content_main.xml, and activity_main.xml files, but I was expecting/hoping for something more XAML style (maybe MainActivity.xaml & MainActivity.xaml.cs or something like that?). Also, from what I have found (although like I said, I am completely new to Xamarin & Android, so I might be wrong) it sounded like I wanted something more like ContentPage as the root rather than RelativeLayout. I was hoping to have all my XAML (except, of course, for things like external or custom controls or elements that are not part of the page) in one file, but Visual Studio 2019 is creating 2 *.xml files rather than a single *.xaml or *.axml file. Is there any way to get a single *.xaml file that is more associated with the codebehind? I don't know if all this is just me adjusting to Xamarin, whether I am doing or expecting something wrongly, or if there is actually a problem. I also noticed that my Resources folder has a lot of folders starting with mipmap, which I do not see in the screenshots of most of the tutorials I have found. Am I missing or have the wrong SDKs? Any help would be appreciated. Thanks.


  • AhmetErcekAhmetErcek Member ✭✭

    Hello, you can use Xamarin.Forms for shared UI, you dont need re-write it for Android's xml files. Here is you can see how Xamarin.Forms works;

  • njsokalskinjsokalski Member ✭✭✭

    I probably shouldn't have asked my question here, since it probably isn't really a Xamarin.Forms question. When I say "When selecting "Android App (Xamarin)" in Visual Studio 2019", that means I am creating a single Project that is only for Android, there is no code shared between versions of the app for other platforms (iOS, UWP, etc.) because I am writing only for Android. It probably uses much of the same stuff behind the scenes, but it is a different Template in Visual Studio 2019. Sorry for being unclear, I probably should have posted somewhere else.

  • AhmetErcekAhmetErcek Member ✭✭

    there is no obligation. You can develop just Android app with Xamarin.Forms. For design you can use xaml and for logic you can use C#. Create Xamarin.Forms and delete iOS project or you can choose just android from template window.

  • njsokalskinjsokalski Member ✭✭✭

    That still creates 2 projects (1 for shared code, one for Android specific code)

  • shaunpryszlakshaunpryszlak USMember ✭✭✭

    @njsokalski said:
    That still creates 2 projects (1 for shared code, one for Android specific code)

    If you are going to do things properly then you want one project for shared code, one for Android specific code and another for Unit tests. Having the code split like that is no great overhead and IT IS the Xamarin way of doing things (until Maui comes along). If all that was in one project and you suddenly decided to do an iOS version then you would have to try and unpick all the shared code parts. It also means your test project can ignore all the android bits and just test the shared library.

    All my pages have a qwerty.xaml file and a qwerty.xaml.cs code behind file. what extra files have you got? all the android resource folders are standard so don't worry about them. Also Shell is the way to go for organising your pages . Read up on that.

Sign In or Register to comment.