Tag : visual-studio

What’s new in Xamarin.Forms 1.3 : Inherited App Class

With the new release of Xamarin.Forms 1.3 version, the App Class has its new Avatar.

The Older version of App Class was just a class with static methods.
OldXamarinAppClass

Unlike the older version, the new version is an inherited class from the Xamarin.Forms.Application class.
NewXamarinAppClass

Summary of improvements

Addition of new life cycle events :

We can handle separate events during different phases of app interaction life cycle.

  • onStart :- Allows us to handle the app start up. We can write code here to get executed during on app start up.
  • onSleep :- We can write code here to get executed while app in entering into the sleep/minimize mode.
  • onResume :- Code can be executed after the app regains the focus.

Self static object :
Application class uses a static instance of its own, which is named as Current. It can be accessed through out the application.

MainPage attribute :
MainPage is an attribute of the Application Class of type ContentPage. As the name suggest, we can assign the root page of the application to this attribute.

Properties :
Not to be confused, this is an attribute of the Application Class. It contains the Dictionary object. We can read/write application level global variables to it for further use in a Key and Value pair format.

Resources :
Application Class Resources attribute can store the resources for application use. This attribute is of type ResourceDictionary.We can add Implicit Styles (in XAML) and Key Value pair strings to it.

Happy coding 🙂

Categories: Android, Cross Platform Mobile App, iOS, Visual Studio, Windows Phone, Xamarin

Consuming RESTFul web Service in XamarinForms project Using HttpClient

Web service is an important part of the mobile app. I am trying to consume a RESTFul web service in Xamarin using HttpClient.

Prerequisites :
– Microsoft.Net.Http
– Newtonsoft.Json

In this example, let’s display the name of the places for a given postal code. We will use the http://api.geonames.com webservice to get the places.

Call using GET method

Now let’s create the UI having a Button and a Listview in it. Button will contain the code to fetch the web service on click event and Listview will display the result.

AppClass

We are with the UI, which is equipped with the Listview and the Button. The newButn_Clicked() method is associated with the Button click event to get the data from the Web service. Now, let’s define the code to fetch data from the WebService. Since webservice will return JSON we will decode the JSON using the Newtonsoft.Json.

Webservice class

As mentioned above, webservice will return the JSON and we have used the DeserializeObject<>() method to deserialize the JSON to a model object. Model class would look like as:

Model

The PlaceObject class will get the array of Place class after the JSON deserization process. So we have marked the places attribute as the array name returned by the web service i.e. “postalcodes”.

We can now run the code to see the data fetched from the webservice in separate platforms.

Collectively the code looks like :

Call using POST method

To call the web service in POST method, we will replace the GetAsync() method with PostAsync() method as follows

Code for the POST method will look like

Happy coding 🙂

Categories: Cross Platform Mobile App, iOS, Visual Studio, Windows Phone, Xamarin

Configure Xamarin.Forms XAML intellisense in Visual Studio

There is a plugin available for Visual Studio to enable intellisense for Xamarin.Forms XAML.

Don’t believe me. Here is how I saw before the XAML intellisense is installed.

WithoutIntellisense

 

Let’s configure it in Visual Studio. 

Categories: Cross Platform Mobile App, Visual Studio, Xamarin, XAML

How to setup Xamarin Build Host with Visual Studio

The cross platform app development with Xamarin Forms allows to create multiple platform development projects under a single Visual Studio solution. It is easy to build app for Android and Windows Phone in Windows with Xamarin using Visual Studio. But for the iOS development we need XCode, which can only be installed in a MAC environment due to its dependencies. Xamarin has provided a tool called build host to support iOS development from Visual Studio in Windows.

This video demonstrates how to connect the Xamarin build host from MAC with Visual Studio in order to develop an iOS app.

Categories: Cross Platform Mobile App, Xamarin

%d bloggers like this: