Getting Started – Xamarin.Forms
Introduction:
Xamarin.Forms is a cross platform UI toolkit that allow user to efficiently create native user interface layout. Code can be shared all the device (IOS,Android , Windows Phone and Win store app) .System Requirement:
Mac / Windows 7++ Machine with 8 GB RAMXamarin Studio 5.0 or new version/ Visual Studio 2012 or new version
Support Devices:
Xamarin.Forms applications can be support following operating systems devices
Android 4.0.3 (API 15) or higher
iOS 6.1 or higher
Windows Phone 8.1
Windows 8.1
Windows 10 Universal Apps
Windows Phone 8 Silverlight
![](https://lh6.googleusercontent.com/H05qKoVQaLfTsxSrMORoF63iVHy4XPYnkxkgr1pjJTw27RcKLjK6ejdjW-1UiMtpjop-ZKYo0yw5xjCeVSSB2nzdqI3H_5WzdOl84ayvlk1BKGbJAXQO34rd3t-w0AB0MSD1Tipv4U8O83hOoQ)
My system having following VS version with xamarin
![](https://lh3.googleusercontent.com/qkIEnw5ADjh2riwwvLWimG1EGYbT8Qru9UG1W-rQ9Fe-GYJDkictSwtIalrx7kk44UEvtJlOFVDJA8nVWjajy6Ipu7xWHM-ZTkL3l-pJ7S_A4Aqz4N2mtXmtra5CcXAZXw51jW3QNmzWWPGRvQ)
![](https://lh3.googleusercontent.com/mLLncHymZY8yq8wLuZLeJXSaSb28q088ce2FKf1F_3oZrqJbbu9iXVmdy2CF1ZGfHzvlCaYdJ_aLQSxyCkGfbhc1c6Pf5PGGoa3solVp9Ok3PpvG366_9qZOohf4Rmb53YT36Of3PxoggxcK-w)
![](https://lh4.googleusercontent.com/5ncaNoKdtgfPX-eE94EeXfgxv_ZdkpRovLxHPr5pNsAyx2QvIySkQ0VplSnImleyMp-EEmV8FIftRZ2C23y82zoYNtXzrHEn1lZg7XFJtvgV6ljv-8p6wZ2krFnkWDC37CBcazGfbiWQ5qxZ_A)
*** Solution and project name is DevXamarinForms
Visual Studio automatically creates following projects,
DevXamarinForms.Android, DevXamarinForms.iOS, DevXamarinForms.UWP, etc and a shared Portable Class Library (PCL) project named called DevXamarinForms (Refer below)
After create project solution should be like below
![](https://lh4.googleusercontent.com/vK8iDR7So7I7D2vFfxFil3vvjwOnWZzgE_kwMXvRDm-iPj08jHOuIk3EnuyfBlsYqq4jcNz6DbOCxH7Y-0-VTCz6QCu3lvl0jg0TFMfgP_D5gHrF-GHv820W05Blq_Y1p_sFb90Brv4euqdY5w)
![](https://lh5.googleusercontent.com/q_ueCF-JtW952jRJFRyjo_5WYGqpg31kMAx2xe0g8Jfx37cU3AQ1zyODkEwOY788sL6yKp6EeQPjCmB2ctJ6tpTzc8TqOUNY1ZGBrJj4OeT5AAL9VnNUwM8qCDmBgRZcWkuuA4x4SL5sYddulg)
After that two new file are created under portable library HomePage.XAML and HomePage.XAML.cs
In HomePage.XAMl , the below code will automatically added into xaml page
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="DevXamarinForms.HomePage">
<Entry x:Name="txtresult" Text="welcome Devenvexe.com" /> <!--Add this TextBox-->
</ContentPage>
The xml two name space (xmls) are added into xaml page and refered xamarin and micrsoft url with version.
The HomePage.xaml.cs code-behind file looks like this.
using Xamarin.Forms;
namespace DevXamarinForms
{
public partial class HomePage : ContentPage
{
public HomePage()
{
InitializeComponent();
}
}
}
![](https://lh3.googleusercontent.com/M_UjLwT0hYRMIxhTh8wclux7YVXscK8PUV5E-3C3eID_2MXLSaqKjpF6SzhWfhf_wZOUInR5Lx2uqFDJfeI7SdODsX8BDflLV9wZ7cU8RWWyR0hj8idrijKj_Ave0aajHA_AEBX0M4vwmtkDgQ)
namespace DevXamarinForm {
using System;
iOS 6.1 or higher
Windows Phone 8.1
Windows 8.1
Windows 10 Universal Apps
Windows Phone 8 Silverlight
How to create First Xamarin.Form Application?
Step 1:
Open Visual Studio ( Run ➔ Devenv.exe)My system having following VS version with xamarin
Step 2:
Create New Project ( File ➔ New ➔ Project )Step 3:
Open New Project template Cross Platform ➔ Blank App(Xamarin .Forms .Portable)*** Solution and project name is DevXamarinForms
Visual Studio automatically creates following projects,
DevXamarinForms.Android, DevXamarinForms.iOS, DevXamarinForms.UWP, etc and a shared Portable Class Library (PCL) project named called DevXamarinForms (Refer below)
After create project solution should be like below
Step 4:
Right Click on Portable Project (DevXamarinForms) ➔ Add ➔ New Item ➔Cross-Platform ➔ Forms Xaml Page and name it HomePage.CSAfter that two new file are created under portable library HomePage.XAML and HomePage.XAML.cs
In HomePage.XAMl , the below code will automatically added into xaml page
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="DevXamarinForms.HomePage">
<Entry x:Name="txtresult" Text="welcome Devenvexe.com" /> <!--Add this TextBox-->
</ContentPage>
The xml two name space (xmls) are added into xaml page and refered xamarin and micrsoft url with version.
The HomePage.xaml.cs code-behind file looks like this.
using Xamarin.Forms;
namespace DevXamarinForms
{
public partial class HomePage : ContentPage
{
public HomePage()
{
InitializeComponent();
}
}
}
Where Can find InitializeComponent() Method :
InitializeComponent() method will generate during build so build your portable library , C# code file is generated from the XAML file. If you look in the \DevXamarinForms\DevXamarinForms\obj\Debug directory, you’ll find a file named DevXamarinForms.HomePage.xaml.g.cs. The ‘g’ stands for generated.namespace DevXamarinForm {
using System;
using Xamarin.Forms;
using Xamarin.Forms.Xaml;
using Xamarin.Forms.Xaml;
public partial class HomePage : global::Xamarin.Forms.ContentPage {
[System.CodeDom.Compiler.GeneratedCodeAttribute("Xamarin.Forms.Build.
Tasks.XamlG", "0.0.0.0")]
private global::Xamarin.Forms.Entry txtresult;
[System.CodeDom.Compiler.GeneratedCodeAttribute("Xamarin.Forms.Build.
Tasks.XamlG", "0.0.0.0")]
private void InitializeComponent() {
this.LoadFromXaml(typeof(HomePage));
txtresult = this.FindByName<global::Xamarin.Forms.Entry>("txtresult");
}
}
}
[System.CodeDom.Compiler.GeneratedCodeAttribute("Xamarin.Forms.Build.
Tasks.XamlG", "0.0.0.0")]
private global::Xamarin.Forms.Entry txtresult;
[System.CodeDom.Compiler.GeneratedCodeAttribute("Xamarin.Forms.Build.
Tasks.XamlG", "0.0.0.0")]
private void InitializeComponent() {
this.LoadFromXaml(typeof(HomePage));
txtresult = this.FindByName<global::Xamarin.Forms.Entry>("txtresult");
}
}
}
Just Modify App.CS file, like below
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Xamarin.Forms;
namespace DevXamarinForm
{
public class App : Application
{
public App()
{
// The root page of your application
//MainPage = new ContentPage
//{
// Content = new StackLayout
// {
// VerticalOptions = LayoutOptions.Center,
// Children = {
// new Label {
// HorizontalTextAlignment = TextAlignment.Center,
// Text = "Welcome to Xamarin Forms!"
// }
// }
// }
//};
MainPage = new HomePage(); // Add this code
}
}
}
0 Comments