Friday, October 20, 2017

Creating an Android app

If you’re interested in using Xamarin.Forms to target Android devices, first become familiar with the Getting Started documents on the Xamarin website:

If you’re using Visual Studio, and if everything is installed correctly, you should be able to select File > New > Project from the menu, and in the New Project dialog, from the left, select Visual C# and then Android, and from the template list in the center, select Blank App (Android).

If you’re using Xamarin Studio, you should be able to select File > New > Solution from the menu, and in the New Project dialog, from the left, select Android and App, and in the template list in the center, select Android App.

Give it a location and a name; build and deploy. If you can’t get this process to work, it’s not a Xamarin.Forms issue, and you might want to check the Xamarin.Android forums for a similar problem:

Source of Information : Creating Mobile Apps with Xamarin.Forms

Thursday, October 19, 2017

Creating an iOS app

If you’re interested in using Xamarin.Forms to target the iPhone, first become familiar with the appropriate Getting Started documents on the Xamarin website:

This will give you guidance on using the Xamarin.iOS library to develop an iPhone application in C#. All you really need to do is get to the point where you can build and deploy a simple iPhone application on either a real iPhone or the iPhone simulator.

If you’re using Visual Studio, and if everything is installed correctly, you should be able to select File > New > Project from the menu, and in the New Project dialog, from the left, select Visual C# and iOS and then Universal (which refers to targeting both iPhone and iPad), and from the template list in the center, select Blank App (iOS).

If you’re using Xamarin Studio, you should be able to select File > New > Solution from the menu, and in the New Project dialog, from the left, select iOS and then App, and from the template list in the center, select Single View App.

In either case, select a location and name for the solution. Build and deploy the skeleton application created in the project. If you’re having a problem with this, it’s not a Xamarin.Forms issue. You might want to check the Xamarin.iOS forums to see if anybody else has a similar problem:

Source of Information : Creating Mobile Apps with Xamarin.Forms

Wednesday, October 18, 2017

Xamarin - Your development environment

How you set up your hardware and software depends on what mobile platforms you’re targeting and what computing environments are most comfortable for you. The requirements for Xamarin.Forms are no different from the requirements for using Xamarin.iOS or Xamarin.Android or for programming for Windows Runtime platforms.

This means that nothing in this section is specific to Xamarin.Forms. There exists much documentation on the Xamarin website on setting up machines and software for Xamarin.iOS and Xamarin.Android programming, and on the Microsoft website about Windows Phone.

Machines and IDEs
If you want to target the iPhone, you’re going to need a Mac. Apple requires that a Mac be used for building iPhone and other iOS applications. You’ll need to install Xcode on this machine and, of course, the Xamarin platform that includes the necessary libraries and Xamarin Studio. You can then use Xamarin Studio and Xamarin.Forms on the Mac for your iPhone development.

Once you have a Mac with Xcode and the Xamarin platform installed, you can also install the Xamarin platform on a PC and program for the iPhone by using Visual Studio. The PC and Mac must be connected via a network (such as Wi-Fi). Visual Studio communicates with the Mac through a Secure Shell (SSH) interface, and uses the Mac to build the application and run the program on a device or simulator.

You can also do Android programming in Xamarin Studio on the Mac or in Visual Studio on the PC.
If you want to target the Windows platforms, you’ll need Visual Studio 2015. You can target all the platforms in a single IDE by running Visual Studio 2015 on a PC connected to the Mac via a network. (That’s how the sample programs in this book were created.) Another option is to run Visual Studio in a virtual machine on the Mac.

Devices and emulators
You can test your programs on real phones connected to the machines via a USB cable, or you can test your programs with onscreen emulators.

There are advantages and disadvantages to each approach. A real phone is essential for testing complex touch interaction or when getting a feel for startup or response time. However, emulators allow you to see how your application adapts to a variety of sizes and form factors.

The iPhone and iPad emulators run on the Mac. However, because Mac desktop machines don’t have touchscreens, you’ll need to use the mouse or trackpad to simulate touch. The touch gestures on the Mac touchpad do not translate to the emulator. You can also connect a real iPhone to the Mac, but you’ll need to provision it as a developer device.

Historically, Android emulators supplied by Google have tended to be slow and cranky, although they are often extremely versatile in emulating a vast array of actual Android devices. Fortunately, Visual Studio now has its own Android emulator that works rather better. It’s also very easy to connect a real Android phone to either a Mac or PC for testing. All you really need do is enable USB Debugging on the device.

The Windows Phone emulators are capable of several different screen resolutions and also tend to run fairly smoothly, albeit consuming lots of memory. If you run the Windows Phone emulator on a touchscreen, you can use touch on the emulator screen. Connecting a real Windows Phone to the PC is fairly easy but requires enabling the phone in the Settings section for developing. If you want to unlock more than one phone, you’ll need a developer account.

Source of Information : Creating Mobile Apps with Xamarin.Forms

Tuesday, October 17, 2017

A cross-platform panacea?

For the most part, Xamarin.Forms defines its abstractions with a focus on areas of the mobile user interface that are common to the iOS, Android, and Windows Runtime APIs. These Xamarin.Forms visual objects are mapped to platform-specific objects, but Xamarin.Forms has tended to avoid implementing anything that is unique to a particular platform.

For this reason, despite the enormous help that Xamarin.Forms can offer in creating platform- independent applications, it is not a complete replacement for native API programming. If your application relies heavily on native API features such as particular types of controls or widgets, then you might want to stick with Xamarin.iOS, Xamarin.Android, and the native Windows Phone API.
You’ll probably also want to stick with the native APIs for applications that require vector graphics or complex touch interaction. The current version of Xamarin.Forms is not quite ready for these scenarios.

On the other hand, Xamarin.Forms is great for prototyping or making a quick proof-of-concept application. And after you’ve done that, you might just find that you can continue using Xamarin.Forms features to build the entire application. Xamarin.Forms is ideal for line-of-business applications.

Even if you begin building an application with Xamarin.Forms and then implement major parts of it with platform APIs, you’re doing so within a framework that allows you to share code and that offers structured ways to make platform-specific visuals.

Source of Information : Creating Mobile Apps with Xamarin.Forms

Monday, October 16, 2017

Platform specificity

In the section of that XAML file involving the ToolbarItem, you can also see a tag named OnPlatform. This is one of several techniques in Xamarin.Forms that allow introducing some platform speci-ficity in otherwise platform-independent code or markup. It’s used here because each of the separate platforms has somewhat different image format and size requirements associated with these icons.

A similar facility exists in code with the Device class. It’s possible to determine what platform the code is running on and to choose values or objects based on the platform. For example, you can specify different font sizes for each platform or run different blocks of code based on the platform. You might want to let the user manipulate a Slider to select a value in one platform but pick a number from a set of explicit values in another platform.

In some applications, deeper platform specificities might be desired. For example, suppose your application requires the GPS coordinates of the user’s phone. This is not something that Xamarin.Forms provides, so you’d need to write your own code specific to each platform to obtain this information.

The DependencyService class provides a way to do this in a structured manner. You define an interface with the methods you need (for example, IGetCurrentLocation) and then implement that interface with a class in each of the platform projects. You can then call the methods in that interface from the Xamarin.Forms project almost as easily as if it were part of the API.

Each of the standard Xamarin.Forms visual objects—such as Label, Button, Switch, and Slider—are supported by a renderer class in the various Xamarin.Forms.Platform libraries. Each renderer class implements the platform-specific object that maps to the Xamarin.Forms object.

You can create your own custom visual objects with your own custom renderers. The custom visual object goes in the common code project, and the custom renderers go in the individual platform projects. To make it a bit easier, generally you’ll want to derive from an existing class. Within the individual Xamarin.Forms platform libraries, all the corresponding renderers are public classes, and you can derive from them as well.

Xamarin.Forms allows you to be as platform independent or as platform specific as you need to be. Xamarin.Forms doesn’t replace Xamarin.iOS and Xamarin.Android; rather, it integrates with them.

Source of Information : Creating Mobile Apps with Xamarin.Forms

Sunday, October 15, 2017

XAML support

Xamarin.Forms also supports XAML (pronounced “zammel” to rhyme with “camel”), the XML-based Extensible Application Markup Language developed at Microsoft as a general-purpose markup language for instantiating and initializing objects. XAML isn’t limited to defining initial layouts of user interfaces, but historically that’s how it’s been used the most, and that’s what it’s used for in Xamarin-.Forms.

Here’s the XAML file for the program whose screenshots you’ve just seen:

xmlns:x="" x:Class="PlatformVisuals.PlatformVisualsPage" Title="Visuals">
<StackLayout Padding="10,0">
<Label Text="Hello, Xamarin.Forms!" FontSize="Large" VerticalOptions="CenterAndExpand" HorizontalOptions="Center" />
<Button Text = "Click Me!" VerticalOptions="CenterAndExpand" HorizontalOptions="Center" />
<Switch VerticalOptions="CenterAndExpand" HorizontalOptions="Center" />
<Slider VerticalOptions="CenterAndExpand" />
<ToolbarItem Text="edit" Order="Primary">
<OnPlatform x:TypeArguments="FileImageSource" iOS="edit.png" Android="ic_action_edit.png" WinPhone="Images/edit.png" />
<ToolbarItem Text="search" Order="Primary">
<OnPlatform x:TypeArguments="FileImageSource" iOS="search.png" Android="ic_action_search.png" WinPhone="Images/" />
<ToolbarItem Text="refresh" Order="Primary">
<OnPlatform x:TypeArguments="FileImageSource" iOS="reload.png" Android="ic_action_refresh.png" WinPhone="Images/refresh.png" />
<ToolbarItem Text="explore" Order="Secondary" />
<ToolbarItem Text="discover" Order="Secondary" />
<ToolbarItem Text="evolve" Order="Secondary" />

Unless you have experience with XAML, some syntax details might be a little obscure. But even so, you can see the Label, Button, Switch, and Slider tags. In a real program, the Button, Switch, and Slider would probably have event handlers attached that would be implemented in a C# code file. Here they do not. The VerticalOptions and HorizontalOptions attributes assist in layout.

Source of Information : Creating Mobile Apps with Xamarin.Forms