Xamarin C# Tutorial For Beginners in Urdu: Guide to Install Xamarin and Run First App 102

Installing Xamarin

How to set up Visual Studio and Xamarin to start building mobile apps with .NET.

Installing Xamarin on Windows

Step-by-step instructions

Xamarin can be installed as part of a new Visual Studio 2019 installation, with the following steps:

  1. Download Visual Studio 2019 Community, Visual Studio Professional, or Visual Studio Enterprise from the Visual Studio page (download links are provided at the bottom).
  2. Double-click the downloaded package to start installation.
  3. Select the Mobile development with .NET workload from the installation screen:
  4. When you are ready to begin Visual Studio 2019 installation, click the Install button in the lower right-hand corner: Install button Use the progress bars to monitor the installation: Progress bars during installation
  5. When Visual Studio 2019 installation has completed, click the Launch button to start Visual Studio: Location of Launch button

Build your first Xamarin.Forms App

Step-by-step instructions for Windows

Download the sample

Follow these steps along with the video above:

  1. Choose File > New > Project… or press the Create new project… button:
  2. Search for “Xamarin” or choose Mobile from the Project type menu. Select the Mobile App (Xamarin.Forms) project type:
  3. Choose a project name – the example uses “AwesomeApp”:
  4. Click on the Blank project type and ensure Android and iOS are selected:
  5. Wait until the NuGet packages are restored (a “Restore completed” message will appear in the status bar).
  6. New Visual Studio 2019 installations won’t have an Android emulator configured. Click the dropdown arrow on the Debug button and choose Create Android Emulator to launch the emulator creation screen: Create Android Emulator dropdown
  7. In the emulator creation screen, use the default settings and click the Create button:
  8. Creating an emulator will return you to the Device Manager window. Click the Start button to launch the new emulator: Android emulator in the Device Manager
  9. Visual Studio 2019 should now show the name of the new emulator on the Debug button: Android emulator name on the Debug button
  10. Click the Debug button to build and deploy the application to the Android emulator: Android emulator displaying the application

Customize the application

The application can be customized to add interactive functionality. Perform the following steps to add user interaction to the application:

  1. Edit MainPage.xaml, adding this XAML before the end of the </StackLayout>: XAML
<Button Text="Click Me" Clicked="Button_Clicked" />

Edit MainPage.xaml.cs, adding this code to the end of the class: C#

  1. int count = 0; void Button_Clicked(object sender, System.EventArgs e) { count++; ((Button)sender).Text = $"You clicked {count} times."; }
  2. Debug the app on Android: Android app

Note

The sample application includes the additional interactive functionality that is not covered in the video.

Leave a Reply