Getting Started with Xamarin

Introduction

This guide shows how to use the Xamarin edition of our toolkits in Xamarin Studio. Our toolkits are packaged as a Xamarin Component package (.xam) which can installed from the Xamarin Component Store.

Contents

  1. Android
  2. iOS

Android

To begin using the components in Xamarin Studio you may install the toolkit from the Xamarin Component Store or manually install the Xamarin Component package (.xam). To manually install the .xam first download the xamarin-component tool provided by Xamarin, then run the command:

xamarin-component.exe install nsoftware.IPWorks-9.0.xam

Adding the Components to Your Project

After successfully installing the Xamarin Component package the toolkit is now accessible from Xamarin Studio. To select the component in your project right-click on "Components" and choose "Edit Components".

Click "Add to Project" to add the component to your package.

The component will now be visible in the "Components" list and is ready to be used in your code.

Open any of the sample projects for details on how to use the components. Below is a very simple code snippet showing typical usage:

using System;
using Android.App;
using Android.Content;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.OS;
using nsoftware.IPWorks;

namespace nsoftware.HttpurlDemo
{
	[Activity (Label = "HttpurlDemo", MainLauncher = true)]
	public class MainActivity : Activity
	{

		protected override void OnCreate (Bundle bundle)
		{
			base.OnCreate (bundle);

			// Set our view from the "main" layout resource
			SetContentView (Resource.Layout.Main);

			// Get our button from the layout resource,
			// and attach an event to it
			Button goButton = FindViewById<Button> (Resource.Id.GoButton);
			EditText txtResponse = FindViewById<EditText> (Resource.Id.txtResponse);
			EditText txtURL = FindViewById<EditText> (Resource.Id.urlField);

			goButton.Click += (object sender, EventArgs e) => {
				try{
					Http http = new Http(this);
					http.Get(txtURL.Text);
					txtResponse.Text = http.TransferredData;
				}
				catch(Exception ex)
				{
					txtResponse.Text = "ERROR: " + ex.Message;
				}
			};
		}
	}
}

iOS

To begin using the components in Xamarin Studio you may install the toolkit from the Xamarin Component Store or manually install the Xamarin Component package (.xam). To manually install the .xam first download the xamarin-component tool provided by Xamarin, then run the command:

mono xamarin-component.exe install nsoftware.IPWorks-9.0.xam

Adding the Components to Your Project

After successfully installing the Xamarin Component package the toolkit is now accessible from Xamarin Studio. To select the component in your project right-click on "Components" and choose "Edit Components".

Click "Add to Project" to add the component to your package.

The component will now be visible in the "Components" list and is ready to be used in your code.

Open any of the sample projects for details on how to use the components. Below is a very simple code snippet showing typical usage:

using System;
using System.Drawing;
using MonoTouch.Foundation;
using MonoTouch.UIKit;
using nsoftware.IPWorks;

namespace nsoftware.HttpurlDemo
{
	public partial class httpurlViewController : UIViewController
	{
		Http http;

		public httpurlViewController (IntPtr handle) : base (handle)
		{
			http = new Http (this);
		}

		public override void DidReceiveMemoryWarning ()
		{
			// Releases the view if it doesn't have a superview.
			base.DidReceiveMemoryWarning ();
			
			// Release any cached data, images, etc that aren't in use.
		}

		#region View lifecycle

		public override void ViewDidLoad ()
		{
			base.ViewDidLoad ();
			
			// Perform any additional setup after loading the view, typically from a nib.
			var g = new UITapGestureRecognizer(() => View.EndEditing(true));
			g.CancelsTouchesInView = false; //for iOS5
			View.AddGestureRecognizer(g);
		}

		public override void ViewWillAppear (bool animated)
		{
			base.ViewWillAppear (animated);
		}

		public override void ViewDidAppear (bool animated)
		{
			base.ViewDidAppear (animated);
		}

		public override void ViewWillDisappear (bool animated)
		{
			base.ViewWillDisappear (animated);
		}

		public override void ViewDidDisappear (bool animated)
		{
			base.ViewDidDisappear (animated);
		}

		#endregion

		partial void btnGetClick (UIButton sender)
		{
			try{
				http.Get(txtURL.Text);
				txtOutput.Text = http.TransferredData;
			}
			catch(Exception ex)
			{
				new UIAlertView("Error",ex.Message,null,"OK",null).Show();

			}
		}
	}
}

We appreciate your feedback.  If you have any questions, comments, or suggestions about this article please contact our support team at kb@nsoftware.com.