Static Resource Using Xamarin.Forms Version (1.0)

Introduction

Xamarin is a platform that allows us to create multi-platform mobile applications for platforms like Windows, iOS, and Android, through a single integrated development environment (IDE). We will discuss how to create a Static Resource using Xamarin.Forms (or) cross-platform from VS2017.

There are many plugins available for Xamarin.Forms including Stack Layout, Label, and button.

Tools

Windows 10 (Recommended)

Visual Studio 2017 Community/Enterprise/Professional Edition (Software available online at https://www.visualstudio.com/downloads/)

The steps given below are required to be followed in order to design Static Resorce View in Xamarin.Forms, using Microsoft Visual Studio 2017.

StackLayout

 

Step 1

Go to Visual Studio 2017.

Click File —> New —> Project or use shortcut (Ctrl+Shift+N).

 

Step 2

Go to Visual C# --> Cross Platform –> Blank App (Xamarin.Forms or native); change your application name and click the "OK" button.

 

Step 3

After this, go to New Cross Platform App, select Blank App. For UI technology, there are two types; let's select Xamarin.Forms. Similarly, for code sharing strategy, we select Portable Class Library (PCL) and click the “OK” button.

 

Step 4

In this step, go to Select (Portable) page and double click on HomePage.XAML. Then, wait for a few seconds.

 

Step 5

Click HomePage.xaml Page Designer View, wait for some time until the Designer View is visible. Insert the code given below in HomePage.xaml and save it.

 

Code

  1. Xaml Code<?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="StaticResourceDemo.HomePage"  
  5. BackgroundColor="Black">  
  6. <ContentPage.Resources>  
  7. <ResourceDictionary>  
  8. <Style x:Key="MyLabelStyle" TargetType="Label">  
  9.     <Setter Property="TextColor" Value="Green"/>  
  10.     <Setter Property="FontSize" Value="40"/>  
  11. </Style>  
  12.     <Style x:Key="MyEntryStyle" TargetType="Entry">  
  13.     <Setter Property="TextColor" Value="Yellow"/>  
  14. </Style>  
  15. </ResourceDictionary>  
  16. </ContentPage.Resources>  
  17.     <StackLayout>  
  18.         <Label Text="YourName" Style="{StaticResource MyLabelStyle}"/>  
  19.         <Entry Text="Ravishankar" Style="{StaticResource MyEntryStyle}"/>  
  20.         <Label Text="DOB" Style="{StaticResource MyLabelStyle}"/>  
  21.         <Entry Text="22-04-1999" Style="{StaticResource MyEntryStyle}"/>  
  22.         <Label Text="Email" Style="{StaticResource MyLabelStyle}"/>  
  23.         <Entry Text="[email protected]" Style="{StaticResource MyEntryStyle}"/>  
  24.         <Label Text="MOBILE NO" Style="{StaticResource MyLabelStyle}"/>  
  25.         <Entry Text="1234567890" Style="{StaticResource MyEntryStyle}"/>  
  26.     </StackLayout>  
  27. </ContentPage>  
Step 6

In this step, click on App.cs page and create a new class.


  1. public App()  
  2. {  
  3.    MainPage = new HomePage();  
  4. }  

Step 7

After the process is complete, right click on Solution Explorer. There will be project content and more options available. Click on “Set StratUp Project”.

 

Step 8

Then, appears Solution Property page.  Mark the “Multiple StratUp Projects:” option. Just select Start option for Droid and UWP projects. I have selected these two because I have Android and Windows emulators only but you can add iOS option too.

 

Step 9

Now, click on Build option at the top of the toolbar and select Configuration Manager…

 

Step 10

Mark the Build and Deploy check boxes for Android (Droid) and Windows (UWP).

 

Step 11

Now, run the application.

 

Step 12

 

OUTPUT

Process is complete and the output appears as desired. 

 

Your Static Resource application is created successfully.

SUMMARY

In this article, you learned how to create Static Resource application using Xamarin.Forms with .NET Standard libraries.

If you have any questions/ feedback/ issues, please write in the comment box.

Up Next
    Ebook Download
    View all
    Learn
    View all