How to build the first Xamarin.Forms App?
8 minute(s) read
|
Published on: Mar 14, 2021
Updated on: Dec 14, 2021
|
Xamarin.Forms are one of the most popular and best options for designing and developing different types of mobile applications that are multi-platform. Xamarin's multi-platform nature is one of its advantages and makes it possible to have several different outputs on several different platforms with just one coding. The output of the code written in Xamarin.Forms in C # will be on Android, iOS, and Windows working systems. One of the reasons that make using Xamarin necessary for designing and developing applications is that the code in Xamarin is compiled natively. If the design and construction of applications are done well, it can be distinguished from Applications designed and built using Xcode.
To build the first app using Xamarin.Forms on iOS, some app developers use languages and IDEs provided by Apple itself, using languages and IDEs provided by Apple is the only way. There is no building and developing applications, and there are other ways and languages to build and design different applications in the iOS operating system.
Xamarin has had a high-cost drawback in the past, but after it was bought by Microsoft and released new and updated pads, the purchase price also went down. So that all companies and small and personal businesses can also benefit from Xamarin facilities and use them to design different types of applications on different platforms.
The features that Xamarin provides to developers are as follows:
- Ability to share written code
- Ability to re-use written code to output on other platforms
- Ability to use all libraries and tools in C # to better build and develop applications
How to build the first application using Xamarin.Forms?
You must first have VStudio and Xamarin installed on your system, which in this article assumes that you have Xamarin and Visual Studio installed.
1- Open this app.
2- Follow the steps File - New - Project to create a new file in VStudio.
3- In the left panel, select the cross-platform option. Since Xamarin.Forms are multi-platform and can get multiple outputs on multiple platforms at once. It is better to choose this option to create the first multi-platform application.
4- Then, in the window that opens, select the Blank App option (Xamarin.Forms. Portable).
5- Enter the name Solution and project. For example, in this tutorial, we will select the project name sampleXamarinForms.
After going through the above steps and selecting the project name and Solution, this will automatically consider the following projects for you:
- sampleXamarinForms .Androids
- sampleXamarinForms .IOS
- sampleXamarinForms.UWP
- After performing the above steps, right-click on Portable Project (sampleXamarinForms), select the Add-New Item -Cross-Platform-Forms Xaml Page option and name it. The name of the link in this article is Home.CS.
The following code snippet is a snippet of code that will be automatically added to the XAML page after the required files are added to the project:
The Home.xaml.cs code that will be in the backend file are as follows:
The InitializeComponent () method will be created when the build operation is performed. Therefore, the portable library must be built and launched, after which the file containing the C # code will be separated from the XAML file.
It is better to go to \ SampleXamarinForms \ SampleXamarinForms \ obj \ Debug and see the file named SampleXamarinForms.Home.xaml.g.cs.
The 'g' at the end of the file name means that the file has been built.
It is better to edit the file according to the code written below:
Then build the program and run it.
The advantage of using Xamarin.Forms are that you can get different outputs from a common piece of code, but you can still get Xamarin.Android, Xamarin.iOS, and Xamarin. Windows is used to build and develop applications.
In this article, we use Xamarin.iOS. Xcode, Swift, and Objective-C are languages and IDEs provided by Apple for use on Xamarin.iOS.
What do we need to build an app on iOS?
To do this, we need two computers:
1- Computer with Windows working system to install Visual Studio and write C # code in it
2- Computer with Mac operating system on which Xcode is also installed. This computer will be used to test the built application.
Note:
It is better for these two computers to be physically and remotely close to each other so that the testing and inspection process can be done smoothly and easily.
Are there any other ways besides having two computers with different operating systems?
In some cases, people may not have two computers with two different operating systems, in which case the Solution is as follows:
For users who only use Mac OS:
In this case, it is better to install the Windows operating system through a virtual machine. If they can install the Windows operating system through a virtual machine and ping the IP addresses of the Mac operating system into the Windows operating system, they can continue working. They must also check to access the Mac network through the Windows operating system.
For users who only use the Windows operating system:
In this case, users can use hosted services such as MacinCloud or Macminicolo for remote access to building applications.
Create the first iOS app in Xamarin.Forms
You must first have Visual Studio and Xamarin installed on your system, which in this article assumes that you have Xamarin and install it.
In other articles, we have explained how to install it and Xamarin. See other articles for more information.
1- Open Visual Studio and go to File \ New \ Project.
2- Select the #Visual C title and select the iOS option from the options opened under the #Visual C title.
3- Then select the iPhone option. Selecting this option means that the app you will design will be for iOS phones and not for other devices such as the iPad.
4- The template we choose in this article is the Single View App. This template actually creates an application to control a single view. In other words, it can be said that this template of our choice in this article will manage and control a view in the iOS application.
5- In the next section, enter the Name and Name Solution fields.
In this case, this asks you to prepare the Mac system to host Xamarin build.
- Open the System Preferences section on the Mac and select Sharing.
- Enable the Remote Login option.
- To define user access, select the Allow access option and set it to Only these users. Then specify a user to access the Xamarin and Xcode code written on the Mac.
1- Go back to your Windows operating system, which you have as a virtual machine or a separate system, and enable Visual Studio.
2- When you return to Visual Studio, you will be asked to select Mac as the build host. In this case, select the Mac in Visual Studio, enter your username and password, and click connect. To check the connection, you can check the Visual Studio toolbar on the Windows operating system.
3- Select iPhone Simulator from the Solution Platform drop-down menu.
4- To execute the written code, you can press the Debug button or the shortcut key and Ctrl + F5 key combination to see the result and output of the written code.
Note:
In this case, your written code and application will be compiled, but you cannot see its execution on the Windows operating system. To view its output, you will need a system with the Mac operating system.
Note:
Of course, in the new updates of Xamarin and Visual Studio, it is possible to place the iOS emulator on the Windows operating system, and using this emulator, a splash page will appear, which is a blank page, and you can output the application in it. See. These types of emulators are available in updated versions of Xamarin and Visual Studio and are used to display the output of iOS applications on the Windows operating system.
About our Android and iOS app development services