Monday, 25 July 2016

Activity Life Cycle In Xamarin Forms

Before starting with Xamarin Forms it's important that we should have a strong knowledge 

of Xamarin Forms Activity Life Cycle.

So without wasting any time let's dive into it .

Let's create a Xamarin Forms Project in Visual Studio 2015 or Xamarin Studio.

Once you've successfully created a Xamarin Forms Project then you'll see App.cs Page.Open
it up and in this App.cs you'll see three different activity method i.e., 

  1. OnStart()
  2. OnSleep()
  3. OnResume()


OnStart is called when first time you launch an application.
OnSleep is called when your activity goes into the background state.
OnResume is called when your activity again comes on the front screen or simply
says when your application comes from the OnSleep state then OnResume method will be called 

Enough for this now it's time to put some break point and try to implement this life cycle 
in your Xamarin Forms Application.



I've simply put three different break point on these three LifeCycle methods .
You can also adopt this approach now run your application when your app launches first time then you will notice that OnStart method will be called by using breakpoint.Similarly when you press the back button of your device your application will now go to the sleep state and when you again want to resume your application then OnResume will be fired
It's all for App Life Cycle of Xamarin Forms
Hope it'll help ...

Styles in Xamarin


When we're talking about some kind of design in xamarin then it's very easy if you're well familiar with the styles of xamarin.

So the question is what is style?
A style is a property of your control that tells your control how to look in different scenarios. Styles can be used to create appearance of your controls.
In xamarin we have different types of styles. If you're a web developer and a know how of CSS (Cascading style sheets) then it’s very easy for you to learn style in xamarin and xaml.

So let's dive into the depth of styles.

In xamarin we're going to cover lot of design aspects. So let’s get started...
When someone tells you to create a form or application first page which includes different text boxes and different buttons so what you're going to do is??? Probably you would create different textboxes and buttons and assign style properties in each control. What if someone ask you to add hundred buttons in your page with same properties of all buttons. May be you would hardly code all the styles in each button tag. This thing will also work but the purpose of reusability diminish and your code size grows. So the question is what we're going to do??

So here is the solution of this...
We simply add a following code and now write the Label controls simply without setting any property. What you'll need is simply add a style reference to call all the properties that you've already defined in your custom styles. 

<ContentPage.Resources>
    <ResourceDictionary>
        <Style x:Key="LabelStyle" TargetType="Label">
            <Setter Property="TextColor" Value="Red"/>
            <Setter Property="FontSize" Value="30"/>
        </Style>
    </ResourceDictionary>
</ContentPage.Resources>  




<StackLayout>
        <Label Text="Check out my style." Style="{StaticResource LabelStyle}" />
    </StackLayout>   



Boom...! We've done that tricky thing.
Keep staying with us for different and tricky tips and articles...

Application Page Structure in Xamarin


We are going to talk about the structure of Xamarin Pages in some depth. So let’s get started…
There must be a page with the layout and views. Before moving to the next step first we want to know that what basically a Layout is.
Layout is a container that allows you to add more than one content into your page application.

There are different types of Pages in xamarin.







Content page is the basic and simple page of your application.
Tabbed Page is just like a Content page with some additional tabbed on the bottom or top that allows you to trigger some event.
Master Detailed Page have a menu or you can call it a hamburger that allows you to go to the different pages of your application.
Navigation Page allows you to navigate between different pages.
Carousal Page allows you to slide forward or backward. If you are well familiar with the bootstrap and css then you know what carousal is. If not then don’t be worry because we’re going to start from scratch.



Layouts in Xamarin

In xamarin we have different type of layouts. Let's talk about them one by one.
Layouts is just like a container. The first layout is Stack Layout. It allows us to go to the vertical or horizontal side of screen.
Second is absolute layout. So what it going to do is place view at specific position? It works on the x-axis and y-axis.
Third is the relative layout. What it'll do is place view relative to another, It is used in the page margins of application.
The last is the Table type layout that is the Grid layout.

Basic Controls in Xamarin

Image
Whenever you want to add some picture in your application then you'll use that control.

Label
Label is just like a Text Block if you're familiar with the XAML. If not then it's just a Textbox that cannot be editable

Map
Map is very useful when you want to display some sort of Bing or Google Map Services in to your application.

Web View
As the name implies web view is used to display content of website in to your application.

Button
Button is used to handle some trigger or it will allows us to initiate an event.

Search Bar
Off course it allows you to search something in different pages.

Date Picker
Picks a date for you.

Editor
Editor is a multi-line text field.

Entry
Entry is a single line text field

Progress Bar
It is used when you want the user to wait until the result comes.

List View
List View contains list of items for example if you open your mail box the list view holds your inbox messages.

Some more tools of xamarin are available below.
o   Slider
o   Switch
o   Stepper
o   List View
o   Picker
o   Table View


The most important control we have not talk about is cell.
There are four types of cell.
       I.            Text Cell
     II.            Image Cell
  III.            Entry Cell
  IV.            Switch Cell

Text Cell that displays text into the cell, Image Cell displays images in the cell, Entry Cell allows user to enter some text, Switch Cell allows user to select Boolean value that must be on or off.


So till we have seen the Pages, Layouts, Controls and Cells .Go and explore further to the internet if you have any query related to the article post your comment below. Till then Happy Codding … 

Xamarin OverView

Starting with Xamarin

What is Xamarin?

Basically xamarin is a tool for developing cross platform applications in c#. Sometimes you want to create an application in android and you don't know java. The only thing you know is C# then it's time to shift to the xamarin platform. Xamarin provides the complete cross platform availability. If you want to target the android and iOS applications and you only know the windows phone development then there are two options. First you'll hire a big team of developers that can built native applications for different platforms and the second is to install xamarin studio and target different platforms.


Now the question is what you'll required?

If you are a visual studio lover and love Microsoft technologies and you've a dream spark account then download the xamarin studio with 1 year of membership. However if you don't have any Dream-spark account then don't be worry because xamarin give you 30 days trial. So it's time to start developing some native applications in xamarin studio and publish it in different app store like google play or Apple app store.

Microsoft has decided to acquire xamarin studio. If Microsoft is succeeded in its plan then c-sharp developers directly interact with the xamarin studio. Microsoft will handle all its updates and may be you don't need to pay heavy amount for xamarin. So in short if you want to target cross platform application then xamarin is a good platform for you. Simply go and find your xamarin now and trying to start developing some native applications.


How to test your cross platform application?

Many people think that are they need some physical device other than laptops and desktops PC's .No not at all. The only thing you need is your own laptop or PC with visual studio 2015 OR xamarin studio. If you want to test your application then xamarin android player is best tool for you people if your laptops have 4 GB's of RAM .However if you have laptop with 6-8 GB's of RAM then you can't believe that Microsoft has develop an android emulator for testing android applications.

Now the question is if there're lot of android emulators in the market then why we choose Microsoft Emulator?

The good thing is that it's very faster as compared to other emulators. Its speed is approximately equal to the device speed. Its outer layout is just like Visual studio emulator with an awesome accelerometer, Camera Sensor and GPS location tracker etc.


Stay connected with my articles. If you're interested in the development of cross platform application then the future incoming articles will help you a lot till then install xamarin in your systems and improve your c-sharp concepts...