Introduction
Xamarin.Forms is a mobile application framework for building User interfaces(UI) and a cross-platform UI toolkit that allows developers to easily create native user interface layouts that can be shared across Android, iOS, and Windows Phone.
Xamarin.Forms new version has been published:
- Stable Release: Xamarin.Forms 2.4.0.280
XAML
XAML stands for extensible Application Mark up Language. The XAML file describes the interface with all its elements, while the Code Behind handles all the events and has access to manipulate the XAML controls.
Tools
I am using Windows 10 and Visual Studio 2017 with Xamarin installed in it. You can also develop Xamarin.Forms applications in Visual Studio.
C#
C# was designed by Anders Hejlsberg, and its development team is currently led by Mads Torgersen .C# has already been used for projects as diverse as dynamic Web sites, development tools, and even compilers. C# is a new language created by Microsoft and submitted to the ECMA for Standardization. The most recent version is C# 7.3. Which was released in 2018 alongside Visual Studio 2017 version 15.7.2
Login
Our login page has the following components
- AbsoluteLayout
- Stack Layout
- Label
- Image
- Entry
- Button
StackLayout
In stacklayout we use different tags to design an app. In stacklayout first we use Margin and Padding etc. The next step is we use the tag of an image and set the image in it. After using the tag of the image we use the tag of Label. In Label we used Text, Text color and Fontsize. Next tag is Entry. In Entry we use placeholder. Last tag is button. In button we use the tag of Login page when we click the tag Login to next page. On the next page we use the tag of Navigation push async it is used to the next page and sign up or Logout.
AbsoluteLayout
Sometime when we developing an application we face some situations in layouts where we have a design that needs to implement different layouts that are not the ones we normally use for stacklayout etc.
Let’s create an absolutelayout .we always need to define absolutelayout Tag, declare all the graphic elements that we need, and then, set the properties that allow us to position these elements on the screen use LayoutBounds(Absolutelayout.layoutbound”X,Y,Width,Height”) and LayoutFlag(All,Height proportional…etc. I will be explaining this below.
Creating a Xamarin.Forms Project
Follow these steps to create a new application project.
Open visual studio. Go to file>New Project>select Cross platform and then select cross platform app(xamarin.forms)
Now, set the setting given below.
- Blank app
- Forms
- .Net Standard
And then click ok.
Now, your project is created and starts for development.
Here, you see 3 projects,
- Android project.
- IOS project
- Window project
Now, open mainpage.xaml and write some code in XAML and design our frontend page.
Xaml
- <AbsoluteLayout>
-
- <StackLayout AbsoluteLayout.LayoutBounds="0.1,0,400,100" AbsoluteLayout.LayoutFlags="XProportional">
- <Label Text="Hello" TextColor="Black" FontSize="Medium" HorizontalOptions="Start" VerticalOptions="Start" Margin="20,10,0,0"></Label>
- <Label Text="You can use your email or passward, or you can continue with your social account" TextColor="Black" HorizontalOptions="Start" VerticalOptions="Start" WidthRequest="250" HeightRequest="50" Margin="20,10,0,0" ></Label>
- </StackLayout>
- <StackLayout AbsoluteLayout.LayoutBounds="0.5,370,400,130" AbsoluteLayout.LayoutFlags="XProportional" Margin="0,20,0,0">
- <Button Text="REGISTER" x:Name="rgstr" Clicked="Rgstr_Clicked" TextColor="White" BackgroundColor="OrangeRed" HeightRequest="40" WidthRequest="300" HorizontalOptions="Center"></Button>
- <Button Text="SIGN IN" x:Name="signin" Clicked="Signin_Clicked" TextColor="OrangeRed" BackgroundColor="AntiqueWhite" HeightRequest="40" WidthRequest="300" HorizontalOptions="Center"></Button>
- <Label Text="or sign in with" HorizontalOptions="Center"></Label>
- </StackLayout>
- <StackLayout AbsoluteLayout.LayoutBounds="0.5,502,400,100" AbsoluteLayout.LayoutFlags="XProportional" Orientation="Horizontal" HorizontalOptions="Center">
- <ImageButton Source="facebook.png" x:Name="face" Clicked="Face_Clicked" HeightRequest="50" WidthRequest="50" Aspect="AspectFit" BackgroundColor="Transparent" Margin="0,0,10,0" ></ImageButton>
- <ImageButton Source="google.png" HeightRequest="50" WidthRequest="50" Aspect="AspectFit" BackgroundColor="Transparent" Margin="10,0,0,0"></ImageButton>
- <ImageButton Source="instagram.png" HeightRequest="50" WidthRequest="50" Aspect="AspectFit" BackgroundColor="Transparent" Margin="14,0,0,0"></ImageButton>
-
- </StackLayout>
-
- <StackLayout AbsoluteLayout.LayoutBounds="0.5,100,350,300" AbsoluteLayout.LayoutFlags="XProportional" >
- <ContentView x:Name="overlay"
- AbsoluteLayout.LayoutBounds="0.5, 0, 1, 1"
- AbsoluteLayout.LayoutFlags="All"
- IsVisible="False"
- BackgroundColor="#C0808080"
- Padding="10, 0">
-
- <StackLayout WidthRequest="400" Orientation="Vertical"
- BackgroundColor="White"
- HorizontalOptions="Center"
- VerticalOptions="Center"
- Padding="10">
-
- <Label FontSize="18"
- TextColor="Green"
- HorizontalOptions="Center"
- VerticalOptions="Center"
- Text="SIGN UP PAGE" />
-
- <Entry
- Placeholder="Name" x:Name="Name1"
- TextColor="Black"
- VerticalOptions="CenterAndExpand"
- HorizontalOptions="FillAndExpand"/>
-
- <Entry
- Placeholder="Enter your email" x:Name="Email1"
- TextColor="Black"
- VerticalOptions="CenterAndExpand"
- HorizontalOptions="FillAndExpand"/>
-
- <Entry
- Placeholder="passward" IsPassword="True"
- TextColor="Black" x:Name="Passward1"
- VerticalOptions="CenterAndExpand"
- HorizontalOptions="FillAndExpand"/>
-
- <Entry
- Placeholder="Entre your address" x:Name="address1"
- TextColor="Black"
- VerticalOptions="CenterAndExpand"
- HorizontalOptions="FillAndExpand"/>
-
- <StackLayout Orientation="Horizontal" HorizontalOptions="Center">
-
- <Button Text="Cancel" FontSize="Large"
- VerticalOptions="CenterAndExpand"
- HorizontalOptions="Center"
- BorderRadius="10"
- x:Name="cncll" Clicked="Cncll_Clicked" />
-
- <Button Text="singup" FontSize="Large"
- VerticalOptions="CenterAndExpand"
- HorizontalOptions="Center"
- BorderRadius="10"
- x:Name="enntr" Clicked="Enntr_Clicked" />
- </StackLayout>
- </StackLayout>
-
- </ContentView>
- <ContentView x:Name="overlay1"
- AbsoluteLayout.LayoutBounds="0.5, 0, 1, 1"
- AbsoluteLayout.LayoutFlags="All"
- IsVisible="False"
- BackgroundColor="#C0808080"
- Padding="10, 0">
- <StackLayout Orientation="Vertical" WidthRequest="400"
- BackgroundColor="White"
- HorizontalOptions="Center"
- VerticalOptions="Center"
- Padding="10">
- <Label FontSize="18"
- TextColor="Green"
- HorizontalOptions="Center"
- VerticalOptions="Center"
- Text="Login in page" />
- <Entry
- Placeholder="Enter your email" x:Name="logemail"
- TextColor="Black"
- VerticalOptions="CenterAndExpand"
- HorizontalOptions="FillAndExpand"/>
- <Entry
- Placeholder="your passward" IsPassword="True" x:Name="logpassward"
- TextColor="Black"
- VerticalOptions="CenterAndExpand"
- HorizontalOptions="FillAndExpand"/>
-
- <StackLayout Orientation="Horizontal" HorizontalOptions="Center">
-
- <Button Text="close" FontSize="Large"
- VerticalOptions="CenterAndExpand"
- HorizontalOptions="Center"
- BorderRadius="10"
- x:Name="cncll1" Clicked="Cncll1_Clicked" />
-
- <Button Text="Signin" FontSize="Large"
- VerticalOptions="CenterAndExpand"
- HorizontalOptions="Center"
- BorderRadius="10"
- x:Name="enntr1" Clicked="Enntr1_Clicked" />
- </StackLayout>
- </StackLayout>
- </ContentView>
- </StackLayout>
- </AbsoluteLayout>
Here,I add the code given below to make this Layout.
- Stack Layout
- Absolute Layout
The content page is used and the content page contains only one main element in it. Thus, we use Stack Layout in our content page.
- Another stack layout with horizontal orientation
- Entry with placeholder of the first name.
- Entry with placeholder of the last name.
- Entry with placeholder Email.
- Entry with placeholder Password.
- Entry with placeholder to User Name.
- Lable with tapped Gesture
- Label With Text
- Image button
- Content view
- Stack layout with orientation Horizontal
- Label with text needs to be UserName and password needs to be entered
- Register button tap to user registration page appear and fill all entry and then click signup button. Now user is register and then Next Step click sign in button and appear login page
- Sign in button tab and then appear login page
- A Signup button click then appear signup page
- A Sign Up button then show you sing in page
- A Login button place
- Use page navigation
- Labels with text already have the account.
Refer to the screenshot given below.
1st Reference