Platform App Info In Android And UWP Using Xamarin.Forms

This article demonstrates how to retrieve platform app info in Android and UWP using Xamarin.Forms.

Introduction
 
This article demonstrates how to retrieve platform app info in Android and UWP using Xamarin.Forms. Xamarin is a platform that allows us to create a multi-platform mobile application for platforms, like Android, Windows, iOS through the single integrated development environment (IDE). And with Xamarin.Forms, the interface design for all three platforms can be accomplished within its XAML-based standard, native user-interface control.
 
Android Output 
 
Android
 
UWP Output 
 
 
 Android
 
Android 
 
Step 1 
 
Open Visual Studio and go to New project >> Installed >> Visual C# >> Cross-Platform.
 
Select Cross-Platform app, then give your project a name and location and click "OK" button.
 
Android 
 
Step 2 
 
Open Solution Explorer >> Project Name (Portable) >> App.xaml.cs >> Double click will open the design view of this page.
 
Android 
 
The code is given below just copy it.
 
Android 
 
C# Code 
  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.Linq;  
  4. using System.Text;  
  5.   
  6. using Xamarin.Forms;  
  7.   
  8. namespace OnPlatform  
  9. {  
  10.     public partial class App : Application  
  11.     {  
  12.         public App()  
  13.         {  
  14.             InitializeComponent();  
  15.   
  16.             MainPage = new NavigationPage(new MainPage());  
  17.         }  
  18.   
  19.         protected override void OnStart()  
  20.         {  
  21.             // Handle when your app starts  
  22.         }  
  23.   
  24.         protected override void OnSleep()  
  25.         {  
  26.             // Handle when your app sleeps  
  27.         }  
  28.   
  29.         protected override void OnResume()  
  30.         {  
  31.             // Handle when your app resumes  
  32.         }  
  33.     }  
  34. }  
 
Step 3
 
Next, add  an image to Solution Explorer >> Project Name.Android >> Resources >> Right-Click >> Drawable >> Add >> Existing Item. When the click an existing item button, it opens a dialogue box.
 
Android 
 
Choose image location and add images. 
 
Android 
 
The image is added successfully. Then move the cursor to that image just verify the image.
 
Android 
 
Step 4 
 
Now, Open Solution Explorer >> Project Bame (Portable) >> Right-Click >> Add >> New Item or ctrl+Shift+A.
 
Android 
 
A new dialogue box will open. Now, add the XAML page and give it a name. Click the "Add" button. The XAML page name is "Platform"
 
Android 
 
Step 5 
 
Open Solution Explorer >> Project Name >> MainPage.xaml. Double Click for Opening the design view of this page.
 
Android 
 
The Code is given below just copy it.
 
Android 
 
Xaml Code 
 
We are create a button and clicked event inside the stacklayout. The button name is "Platform".
  1. <?xml version="1.0" encoding="utf-8" ?>  
  2. <ContentPage xmlns="http://xamarin.com/schemas/2014/forms"  
  3.              xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"  
  4.              xmlns:local="clr-namespace:OnPlatform"  
  5.              x:Class="OnPlatform.MainPage">  
  6.     <ContentPage.Content>  
  7.         <StackLayout>  
  8.             <Button Text="Platform"  
  9.                    FontAttributes="Bold"  
  10.                    FontSize="Medium"  
  11.                    Clicked="Button_Clicked"/>  
  12.         </StackLayout>  
  13.     </ContentPage.Content>  
  14. </ContentPage>  
Step 6 
 
Open Solution Explorer >> Project Name >> MainPage.xaml.cs. Double Click for Opening the design view of this page. 
 
Android 
 
The Code is given below just copy it.
 
Android
 
C# Code 
 
The code is button navigation. 
  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.Linq;  
  4. using System.Text;  
  5. using System.Threading.Tasks;  
  6. using Xamarin.Forms;  
  7.   
  8. namespace OnPlatform  
  9. {  
  10.     public partial class MainPage : ContentPage  
  11.     {  
  12.         public MainPage()  
  13.         {  
  14.             InitializeComponent();  
  15.         }  
  16.   
  17.         private async void Button_Clicked(object sender, EventArgs e)  
  18.         {  
  19.             await Navigation.PushAsync(new Platform());  
  20.         }  
  21.     }  
  22. }  
Step 7 
 
Open Solution Explorer >> Project Name >>Platform.xaml. Double Click for Opening the design view of this page.
 
 Android
 
The Code is given below just copy it.
 
Android 
 
Xaml Code
  1. <?xml version="1.0" encoding="utf-8" ?>  
  2. <ContentPage xmlns="http://xamarin.com/schemas/2014/forms"  
  3.              xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"  
  4.              x:Class="OnPlatform.Platform"  
  5.              BackgroundImage="Android.png">  
  6.     <Label Text="{Binding MainText}" VerticalOptions="Center" HorizontalOptions="Center">  
  7.         <Label.Text>  
  8.             <OnPlatform x:TypeArguments="x:String"  
  9.                         Android="Android App"  
  10.                         iOS="iOS App"  
  11.                         WinPhone="Windows App"/>  
  12.         </Label.Text>  
  13.         <Label.TextColor>  
  14.             <OnPlatform  x:TypeArguments="Color"  
  15.                          Android="Green"  
  16.                          iOS="Yellow"  
  17.                          WinPhone="Red"/>  
  18.   
  19.         </Label.TextColor>  
  20.     </Label>  
  21. </ContentPage>  
Step 8
 
Next, select the Built & Deploy option followed by selecting from the list of Android Emulator or Simulator. You can choose any API(Application Program Interface) Level Emulator or simulator to run it.
 
Output 
 
After a few seconds, you will see your app working.
 
Android Output 
 
You can choose Android platform. 
 
Android
 
Click button "Platform" to navigation platform page and the result is displayed. Android platform's label is green.
 
Android 
 
 UWP Output
 
Similarly,  you can choose UWP.
 
Android 
 
Click button "Platform" to navigate to platform page. 
 
Android 
 
The result is displayed. UWP's label color is red.
 
Android 
 
Finally, we have successfully created Xamarin.Forms application.
 
Conclusion 
 
I hope you have learned Platform App Info In Android and UWP using Xamarin.Forms with Visual Studio and C#