====== Source Code iOSEditionSample GettingStarted.zip ====== ====AppDelegate.cs==== using Foundation; using UIKit; using System; namespace GettingStartedSample { // The UIApplicationDelegate for the application. This class is responsible for launching the // User Interface of the application, as well as listening (and optionally responding) to // application events from iOS. [Register("AppDelegate")] public partial class AppDelegate : UIApplicationDelegate { // class-level declarations public override UIWindow Window { get; set; } // This method is invoked when the application is about to move from active to inactive state. // OpenGL applications should use this method to pause. public override void OnResignActivation(UIApplication application) { } // This method should be used to release shared resources and it should store the application state. // If your application supports background exection this method is called instead of WillTerminate // when the user quits. public override void DidEnterBackground(UIApplication application) { } // This method is called as part of the transiton from background to active state. public override void WillEnterForeground(UIApplication application) { AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; } void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e) { Console.WriteLine(); } // This method is called when the application is about to terminate. Save data, if needed. public override void WillTerminate(UIApplication application) { } } } ====Main.cs==== using UIKit; namespace GettingStartedSample { public class Application { // This is the main entry point of the application. static void Main(string[] args) { // if you want to use a different Application Delegate class from "AppDelegate" // you can specify it here. UIApplication.Main(args, null, "AppDelegate"); } } } ====MainViewController.cs==== using CoreAnimation; using CoreGraphics; using CoreLocation; using Foundation; using UIKit; using System; using System.Collections.Generic; using System.Drawing; using System.Globalization; using System.Linq; using ThinkGeo.MapSuite.Core; using ThinkGeo.MapSuite.iOSEdition; namespace GettingStartedSample { /// /// This class represents the main window /// public partial class MainViewController : UIViewController { private static readonly Dictionary zoomLevelOptions; private MapView mapView; private InstructionView instructionView; private CLLocationManager locationManager; private Proj4Projection bingToWgs84Projection; private long previousLocationUpdatedTicks; static MainViewController() { zoomLevelOptions = new Dictionary(); zoomLevelOptions["Zoom|to zoomlevel 2"] = 295295895; zoomLevelOptions["Zoom|to zoomlevel 5"] = 36911986; zoomLevelOptions["Zoom|to zoomlevel 10"] = 1153499; zoomLevelOptions["Zoom|to zoomlevel 16"] = 18023; zoomLevelOptions["Zoom|to zoomlevel 18"] = 4505; } public MainViewController(IntPtr handle) : base(handle) { } public override void ViewDidLoad() { base.ViewDidLoad(); iOSCapabilityHelper.SetViewLayout(View); InitializeMap(); InitializeTools(); InitializeZoomToScaleDialog(); InitializeGpsLocationManager(); } public override void DidRotate(UIInterfaceOrientation fromInterfaceOrientation) { base.DidRotate(fromInterfaceOrientation); instructionView.DidRotate(); instructionView.Hidden = false; mapView.MapTools["ScaleTool"].IsEnabled = true; mapView.MapTools.CenterCoordinate.IsEnabled = true; } public override void WillAnimateRotation(UIInterfaceOrientation toInterfaceOrientation, double duration) { base.WillAnimateRotation(toInterfaceOrientation, duration); double resolution = Math.Max(mapView.CurrentExtent.Width / mapView.Frame.Width, mapView.CurrentExtent.Height / mapView.Frame.Height); mapView.Frame = View.Bounds; mapView.CurrentExtent = GetExtentRetainScale(mapView.CurrentExtent.GetCenterPoint(), mapView.Frame, resolution); mapView.Refresh(); } public override void WillRotate(UIInterfaceOrientation toInterfaceOrientation, double duration) { base.WillRotate(toInterfaceOrientation, duration); instructionView.Hidden = true; mapView.MapTools["ScaleTool"].IsEnabled = false; mapView.MapTools.CenterCoordinate.IsEnabled = false; } private void InitializeMap() { bingToWgs84Projection = new Proj4Projection(); bingToWgs84Projection.InternalProjectionParametersString = ManagedProj4Projection.GetBingMapParametersString(); bingToWgs84Projection.ExternalProjectionParametersString = ManagedProj4Projection.GetWgs84ParametersString(); bingToWgs84Projection.Open(); mapView = new MapView(View.Frame); mapView.MapUnit = GeographyUnit.Meter; mapView.BackgroundColor = UIColor.FromRGB(244, 242, 238); mapView.CurrentExtent = new RectangleShape(-13939426.6371, 6701997.4056, -7812401.86, 2626987.386962); View.AddSubview(mapView); // Touch events mapView.MapSingleTap += MapView_MapSingleTap; mapView.MapLongPress += MapView_MapLongPress; // Base overlay. WorldMapKitOverlay worldOverlay = new WorldMapKitOverlay(); worldOverlay.TileType = TileType.MultiTile; worldOverlay.Projection = WorldMapKitProjection.SphericalMercator; mapView.Overlays.Add("WMK", worldOverlay); // Location marker layer. MarkerOverlay locationOverlay = new MarkerOverlay(); mapView.Overlays.Add("LocationOverlay", locationOverlay); // Single tap popup overlay. PopupOverlay popupOverlay = new PopupOverlay(); popupOverlay.OverlayView.UserInteractionEnabled = true; mapView.Overlays.Add("PopupOverlay", popupOverlay); mapView.MapTools.CenterCoordinate.IsEnabled = true; mapView.MapTools.CenterCoordinate.DisplayProjection = bingToWgs84Projection; mapView.MapTools.CenterCoordinate.DisplayTextFormat = "Longitude:{0:N4}, Latitude:{1:N4}"; ScaleZoomLevelMapTool scaleTool = new ScaleZoomLevelMapTool(); scaleTool.IsEnabled = true; mapView.MapTools.Add("ScaleTool", scaleTool); mapView.Refresh(); } private void InitializeTools() { instructionView = new InstructionView(View, RefreshInstructionView, Instruction_ExpandStateChanged); Add(instructionView); } private void InitializeZoomToScaleDialog() { longPressDailog.Layer.BorderColor = UIColor.Gray.CGColor; longPressDailog.Layer.BorderWidth = 3; longPressDailog.Layer.ShadowColor = UIColor.Gray.CGColor; longPressDailog.Layer.ShadowRadius = 2; longPressDailog.Layer.ShadowOpacity = .6f; longPressDailog.Layer.ShadowOffset = new SizeF(1, 1); TableViewSource longPressOptions_Source = new TableViewSource(); SectionModel section = new SectionModel(); foreach (var zoomLevelOption in zoomLevelOptions) { section.Rows.Add(new CellModel(zoomLevelOption.Key)); } longPressOptions_Source.Sections.Add(section); longPressOptions_Source.RowClick += LongPressOptionsSource_RowClick; tbvLongPressOptions.Source = longPressOptions_Source; View.BringSubviewToFront(dailogBackground); View.BringSubviewToFront(longPressDailog); dailogBackground.Hidden = true; longPressDailog.Hidden = true; } private void InitializeGpsLocationManager() { locationManager = new CLLocationManager(); iOSCapabilityHelper.SetGpsLocationManagerCapability(locationManager); locationManager.DesiredAccuracy = 1; locationManager.LocationsUpdated += LocationManager_LocationsUpdated; locationManager.StartUpdatingLocation(); } /// /// Handles the LocationsUpdated event of the LocationManager control. /// /// The source of the event. /// The instance containing the event data. private void LocationManager_LocationsUpdated(object sender, CLLocationsUpdatedEventArgs e) { long currentTicks = DateTime.Now.Ticks; // Check the location update time, if is less that 5 seconds, don't need update the GPS marker. if (TimeSpan.FromTicks(currentTicks - previousLocationUpdatedTicks).TotalSeconds > 5 && !mapView.ExtentOverlay.IsBusy) { previousLocationUpdatedTicks = currentTicks; } else { return; } CLLocation gpsLocation = e.Locations.FirstOrDefault(); if (gpsLocation == null) return; PointShape currentLocationInWgs84 = new PointShape(gpsLocation.Coordinate.Longitude, gpsLocation.Coordinate.Latitude); PointShape currentLocationInMercator = (PointShape)bingToWgs84Projection.ConvertToInternalProjection(currentLocationInWgs84); MarkerOverlay locationOverlay = (MarkerOverlay)mapView.Overlays["LocationOverlay"]; GpsMarker locationMarker = locationOverlay.Markers.OfType().FirstOrDefault(); // Create a location marker if not exists. if (locationMarker == null) { locationMarker = new GpsMarker(); locationOverlay.Markers.Add(locationMarker); } // Update the GPS marker position. locationMarker.HaloRadiusInMeter = (float)gpsLocation.HorizontalAccuracy; locationMarker.Position = currentLocationInMercator; locationOverlay.Refresh(); } private void LongPressOptionsSource_RowClick(object sender, TableViewRowClickEventArgs e) { CellModel row = ((TableViewSource)e.TableView.Source).Sections[e.IndexPath.Section].Rows[e.IndexPath.Row]; double scale = double.Parse(zoomLevelOptions[row.Name].ToString(CultureInfo.InvariantCulture)); mapView.ZoomToScale(scale); SetZoomToScaleDialogIsHidden(true); } private void Instruction_ExpandStateChanged(CGRect instructionFrame, bool animate) { if (animate) { UIView.BeginAnimations("MapToolsPositionChanged"); UIView.SetAnimationDuration(0.2); } MapTool scaleTool = mapView.MapTools["ScaleTool"]; MapTool coordinateTool = mapView.MapTools.CenterCoordinate; coordinateTool.Center = new CGPoint(View.Frame.Width - scaleTool.Frame.Width / 2 - 5, instructionFrame.Top - 25); scaleTool.Center = new CGPoint(View.Frame.Width - coordinateTool.Frame.Width / 2 - 5, instructionFrame.Top - 40); CALayer attributionLayer = mapView.EventView.Layer.Sublayers.FirstOrDefault(l => l.Name.Equals("AttributionLayer")); attributionLayer.Frame = new CGRect(0, -instructionFrame.Height, attributionLayer.Frame.Width, attributionLayer.Frame.Height); if (animate) UIView.CommitAnimations(); } partial void dialogBackground_TouchUpInside(UIButton sender) { SetZoomToScaleDialogIsHidden(true); } partial void btnClose_TouchUpInside(UIButton sender) { SetZoomToScaleDialogIsHidden(true); } private void MapView_MapSingleTap(object sender, UIGestureRecognizer e) { PointF location = (PointF)e.LocationInView(mapView); PointShape worldPoint = ExtentHelper.ToWorldCoordinate(mapView.CurrentExtent, location.X, location.Y, (float)mapView.Frame.Width, (float)mapView.Frame.Height); PointShape wgs84Point = (PointShape)bingToWgs84Projection.ConvertToExternalProjection(worldPoint); string displayText = string.Format("Longitude : {0:N4}\r\nLatitude : {1:N4}", wgs84Point.X, wgs84Point.Y); PopupOverlay popupOverlay = (PopupOverlay)mapView.Overlays["PopupOverlay"]; CurrentLocationPopup popup = (CurrentLocationPopup)popupOverlay.Popups.FirstOrDefault() ?? new CurrentLocationPopup(worldPoint, displayText); popup.Position = worldPoint; popup.Hidden = false; popup.Content = displayText; popup.UserInteractionEnabled = true; popupOverlay.Popups.Clear(); popupOverlay.Popups.Add(popup); popupOverlay.Refresh(); } private void MapView_MapLongPress(object sender, UIGestureRecognizer e) { SetZoomToScaleDialogIsHidden(false); } private void LocateButton_TouchUpInside(object sender, EventArgs e) { MarkerOverlay locaterOverlay = (MarkerOverlay)mapView.Overlays["LocationOverlay"]; Marker locateMarker = locaterOverlay.Markers.FirstOrDefault(); if (locateMarker != null) { mapView.ZoomTo(locateMarker.Position, 18023); } } private void FullExtentButton_TouchUpInside(object sender, EventArgs e) { Overlay worldOverlay = mapView.Overlays["WMK"]; mapView.CurrentExtent = worldOverlay.GetBoundingBox(); mapView.Refresh(); } private void PreviousExtentButton_TouchUpInside(object sender, EventArgs e) { mapView.ZoomToPreviousExtent(); } private void NextExtentButton_TouchUpInside(object sender, EventArgs e) { mapView.ZoomToNextExtent(); } private void InformationButton_TouchUpInside(object sender, EventArgs e) { UIApplication.SharedApplication.OpenUrl(new NSUrl("http://thinkgeo.com/map-suite-developer-gis/ios-edition/")); } private void RefreshInstructionView(UIView contentView) { UIButton locateButton; UIButton fullExtentButton; UIButton previousExtentButton; UIButton nextExtentButton; UIButton informationButton; UIInterfaceOrientation orientation = UIApplication.SharedApplication.StatusBarOrientation; // Check the device orientation, refresh the controls layout for instruction view. if (orientation == UIInterfaceOrientation.LandscapeLeft || orientation == UIInterfaceOrientation.LandscapeRight) { locateButton = InitializeButton(contentView.Bounds.Width - 195, "location40X40", LocateButton_TouchUpInside); fullExtentButton = InitializeButton(contentView.Bounds.Width - 155, "fullext40X40", FullExtentButton_TouchUpInside); previousExtentButton = InitializeButton(contentView.Bounds.Width - 115, "Preext40X40", PreviousExtentButton_TouchUpInside); nextExtentButton = InitializeButton(contentView.Bounds.Width - 75, "Nxtext40X40", NextExtentButton_TouchUpInside); informationButton = InitializeButton(contentView.Bounds.Width - 35, "info40X40", InformationButton_TouchUpInside); } else { locateButton = InitializeButton(0, "location40X40", LocateButton_TouchUpInside); fullExtentButton = InitializeButton(40, "fullext40X40", FullExtentButton_TouchUpInside); previousExtentButton = InitializeButton(80, "Preext40X40", PreviousExtentButton_TouchUpInside); nextExtentButton = InitializeButton(120, "Nxtext40X40", NextExtentButton_TouchUpInside); informationButton = InitializeButton(contentView.Bounds.Width - 35, "info40X40", InformationButton_TouchUpInside); } contentView.AddSubview(locateButton); contentView.AddSubview(fullExtentButton); contentView.AddSubview(previousExtentButton); contentView.AddSubview(nextExtentButton); contentView.AddSubview(informationButton); } private void SetZoomToScaleDialogIsHidden(bool hidden) { UIView.Animate(0.2, () => { dailogBackground.Hidden = hidden; longPressDailog.Hidden = hidden; }); } /// /// Gets the current extend for MapView by frame and GPS location. /// /// The current location in mercator. /// The frame. /// The resolution. private static RectangleShape GetExtentRetainScale(PointShape currentLocationInMercator, CGRect frame, double resolution) { double left = currentLocationInMercator.X - resolution * frame.Width * .5; double right = currentLocationInMercator.X + resolution * frame.Width * .5; double top = currentLocationInMercator.Y + resolution * frame.Height * .5; double bottom = currentLocationInMercator.Y - resolution * frame.Height * .5; return new RectangleShape(left, top, right, bottom); } private static UIButton InitializeButton(nfloat x, string imageName, EventHandler touchEventHandler) { UIButton button = UIButton.FromType(UIButtonType.RoundedRect); button.Frame = new CGRect(x, 0, 35, 35); button.TintColor = UIColor.White; button.SetImage(UIImage.FromBundle(imageName), UIControlState.Normal); button.TouchUpInside += touchEventHandler; return button; } } } ====MainViewController.designer.cs==== // WARNING // // This file has been generated automatically by Xamarin Studio from the outlets and // actions declared in your storyboard file. // Manual changes to this file will not be maintained. // using System; using Foundation; using UIKit; using System.CodeDom.Compiler; namespace GettingStartedSample { [Register|("MainViewController")] partial class MainViewController { [Outlet] [GeneratedCode|("iOS Designer", "1.0")] UIButton btnClose { get; set; } [Outlet] [GeneratedCode|("iOS Designer", "1.0")] UIButton dailogBackground { get; set; } [Outlet] [GeneratedCode|("iOS Designer", "1.0")] UIView longPressDailog { get; set; } [Outlet] [GeneratedCode|("iOS Designer", "1.0")] UITableView tbvLongPressOptions { get; set; } [Action|("btnClose_TouchUpInside:")] [GeneratedCode|("iOS Designer", "1.0")] partial void btnClose_TouchUpInside (UIButton sender); [Action|("dailogBackground_TouchUpInside:")] [GeneratedCode|("iOS Designer", "1.0")] partial void dialogBackground_TouchUpInside (UIButton sender); void ReleaseDesignerOutlets () { if (btnClose != null) { btnClose.Dispose (); btnClose = null; } if (dailogBackground != null) { dailogBackground.Dispose (); dailogBackground = null; } if (longPressDailog != null) { longPressDailog.Dispose (); longPressDailog = null; } if (tbvLongPressOptions != null) { tbvLongPressOptions.Dispose (); tbvLongPressOptions = null; } } } } ====CurrentLocationPopup.cs==== using CoreGraphics; using ThinkGeo.MapSuite.Core; using ThinkGeo.MapSuite.iOSEdition; using UIKit; namespace GettingStartedSample { /// /// This class represents the location popup which display the location information. /// public class CurrentLocationPopup : Popup { private UILabel lblLocation; private string content; public CurrentLocationPopup(PointShape position, string content) : base(position) { UIView view = new UIView(new CGRect(0, 0, 200, 45)); lblLocation = new UILabel(new CGRect(5, 5, 165, 40)); lblLocation.LineBreakMode = UILineBreakMode.WordWrap; lblLocation.Lines = 2; lblLocation.Font = UIFont.FromName("Arial", 16); Content = content; UIButton popupClose = UIButton.FromType(UIButtonType.System); popupClose.Frame = new CGRect(170, 10, 30, 30); popupClose.SetImage(UIImage.FromBundle("close_noborder"), UIControlState.Normal); popupClose.TintColor = UIColor.Black; popupClose.Layer.CornerRadius = 15; popupClose.Layer.BorderWidth = 2; popupClose.Layer.BorderColor = UIColor.Black.CGColor; popupClose.TouchUpInside += (s, e1) => Hidden = true; view.Add(lblLocation); view.Add(popupClose); ContentView.Add(view); } public string Content { get { return content; } set { content = value; lblLocation.Text = content; } } } } ====InstructionView.cs==== using CoreGraphics; using System; using UIKit; namespace GettingStartedSample { /// /// This class represents the toolbar instruction view for the MapView. /// internal class InstructionView : UIView { private nfloat fullHeight; private UIView containerView; private Action instructionViewTopChanged; private Action resetChildrenLayout; public InstructionView(UIView containerView, Action resetChildrenLayout, Action instructionViewTopChanged) { this.containerView = containerView; this.resetChildrenLayout = resetChildrenLayout; this.instructionViewTopChanged = instructionViewTopChanged; ResetChildrenLayout(); } private static int DescriptionMarginLeft { get { return iOSCapabilityHelper.IsOnIPhone ? 10 : 20; } } private void CollapseButton_TouchDown(object sender, EventArgs e) { nfloat barHeight = fullHeight - Frame.Height; UIView.Animate(.2, () => { CGPoint upperLeft = new CGPoint(0, Frame.Bottom - barHeight); CGSize size = new CGSize(Frame.Width, barHeight); Frame = new CGRect(upperLeft, size); }); instructionViewTopChanged(Frame, true); } private void ResetChildrenLayout() { UIInterfaceOrientation orientation = UIApplication.SharedApplication.StatusBarOrientation; nfloat titleHeight = 40; nfloat instructionHeight = orientation == UIInterfaceOrientation.LandscapeLeft || orientation == UIInterfaceOrientation.LandscapeRight ? 50 : 90; Frame = new CGRect(0, containerView.Bounds.Bottom - instructionHeight, containerView.Bounds.Width, instructionHeight); Alpha = 0.6f; BackgroundColor = UIColor.FromRGBA(126, 124, 129, 255); fullHeight = Frame.Height + titleHeight; UIView topLine = new UIView(new CGRect(0, 0, Frame.Width, 2)); topLine.BackgroundColor = UIColor.DarkGray; topLine.Layer.CornerRadius = 4; topLine.Layer.ShadowRadius = 3; topLine.Layer.ShadowOpacity = .8f; topLine.Layer.ShadowColor = UIColor.Black.CGColor; topLine.Layer.ShadowOffset = new CGSize(1, 0); UIView contentView; UILabel instructionLabel = new UILabel(); instructionLabel.BackgroundColor = BackgroundColor; instructionLabel.Text = "Getting Started"; instructionLabel.Font = UIFont.FromName("Helvetica-Bold", 20); instructionLabel.TextColor = UIColor.White; instructionLabel.ShadowColor = UIColor.Gray; instructionLabel.ShadowOffset = new CGSize(1, 1); instructionLabel.TextAlignment = UITextAlignment.Left; Add(instructionLabel); if (orientation == UIInterfaceOrientation.LandscapeLeft || orientation == UIInterfaceOrientation.LandscapeRight) { instructionLabel.Frame = new CGRect(DescriptionMarginLeft, 5, 160, titleHeight); contentView = new UIView(new CGRect(DescriptionMarginLeft, 10, Frame.Width - 2 * DescriptionMarginLeft, Frame.Height)); } else { UIButton collapseButton = UIButton.FromType(UIButtonType.RoundedRect); collapseButton.Frame = new CGRect(new CGPoint(Frame.Width - 60, 10), new CGSize(55, 30)); collapseButton.SetImage(UIImage.FromBundle("More"), UIControlState.Normal); collapseButton.TintColor = UIColor.White; collapseButton.TouchUpInside += CollapseButton_TouchDown; instructionLabel.Frame = new CGRect(DescriptionMarginLeft, 0, Frame.Width, titleHeight); UIButton titleView = new UIButton(); titleView.Frame = new CGRect(0, 0, Frame.Width, titleHeight); titleView.TouchUpInside += CollapseButton_TouchDown; titleView.Add(instructionLabel); titleView.Add(collapseButton); Add(titleView); nfloat contentViewTop = titleView.Frame.Bottom + 5; contentView = new UIView(new CGRect(DescriptionMarginLeft, contentViewTop, Frame.Width - 2 * DescriptionMarginLeft, Frame.Height - (contentViewTop))); } Add(topLine); Add(contentView); resetChildrenLayout(contentView); instructionViewTopChanged(Frame, false); } internal void DidRotate() { foreach (var subview in Subviews) { subview.RemoveFromSuperview(); } ResetChildrenLayout(); } } } ====ScaleZoomLevelMapTool.cs==== using CoreGraphics; using System; using System.Globalization; using ThinkGeo.MapSuite.iOSEdition; using UIKit; namespace GettingStartedSample { /// /// This class represents the Scale/ZoomLevel we displayed on the map. /// public class ScaleZoomLevelMapTool : MapTool { private UILabel contentLabel; public ScaleZoomLevelMapTool() { IsEnabled = true; contentLabel = new UILabel(); } protected override void InitializeCore(MapView mapView) { base.InitializeCore(mapView); Frame = new CGRect(5, mapView.Frame.Bottom - 30, mapView.Frame.Width - 10, 30); contentLabel.LineBreakMode = UILineBreakMode.WordWrap; contentLabel.Lines = 2; contentLabel.Font = UIFont.FromName("Arial", 12); contentLabel.Frame = new CGRect(0, 0, Frame.Width, Frame.Height); contentLabel.TextAlignment = UITextAlignment.Right; AddSubview(contentLabel); UpdateScaleContent(mapView.CurrentScale); mapView.CurrentScaleChanged += MapView_CurrentExtentChanged; mapView.AddSubview(this); } private void MapView_CurrentExtentChanged(object sender, CurrentScaleChangedMapViewEventArgs e) { UpdateScaleContent(e.NewScale); } private void UpdateScaleContent(double newScale = double.NaN) { if (!double.IsNaN(newScale)) { int zoomLevelIndex = CurrentMap.GetSnappedZoomLevelIndex(newScale); string textFormat = "Scale 1:{1:N0} Zoom Level {0:N0}"; contentLabel.Text = String.Format(CultureInfo.InvariantCulture, textFormat, zoomLevelIndex, newScale); } else { contentLabel.Text = "Scale 1:-- Zoom Level --"; } } } } ====TableViewRowClickEventArgs.cs==== using Foundation; using UIKit; using System; namespace GettingStartedSample { /// /// This class represents the TableViewRowClickEventArgs. /// public class TableViewRowClickEventArgs : EventArgs { private UITableView tableView; private NSIndexPath indexPath; public TableViewRowClickEventArgs(UITableView tableView, NSIndexPath indexPath) : base() { this.tableView = tableView; this.indexPath = indexPath; } public UITableView TableView { get { return tableView; } set { tableView = value; } } public NSIndexPath IndexPath { get { return indexPath; } set { indexPath = value; } } } } ====TableViewSource.cs==== using Foundation; using UIKit; using System; using System.Collections.ObjectModel; namespace GettingStartedSample { /// /// This class represents the TableViewSource class. /// public class TableViewSource : UITableViewSource { private readonly Collection sections; public event EventHandler RowClick; public TableViewSource() { sections = new Collection(); } public Collection Sections { get { return sections; } } public override UITableViewCell GetCell(UITableView tableView, NSIndexPath indexPath) { CellModel currentModel = sections[indexPath.Section].Rows[indexPath.Row]; UITableViewCell cell = tableView.DequeueReusableCell("cell") ?? new UITableViewCell(UITableViewCellStyle.Subtitle, "Cell"); cell.Tag = indexPath.Row; cell.TextLabel.Text = currentModel.Name; cell.TextLabel.Font = UIFont.FromName("Arial", 13); return cell; } public override nint NumberOfSections(UITableView tableView) { return sections.Count; } public override nint RowsInSection(UITableView tableview, nint section) { return sections[(int)section].Rows.Count; } public override void RowSelected(UITableView tableView, NSIndexPath indexPath) { EventHandler handler = RowClick; if (handler != null) { handler(this, new TableViewRowClickEventArgs(tableView, indexPath)); } } public override nfloat GetHeightForRow(UITableView tableView, NSIndexPath indexPath) { return 30; } } public class CellModel { private string name; public CellModel(string name) { this.name = name; } public string Name { get { return name; } } } public class SectionModel { private Collection rows; public SectionModel() { rows = new Collection(); } public Collection Rows { get { return rows; } } } } ====AssemblyInfo.cs==== using System.Reflection; using System.Runtime.InteropServices; // General Information about an assembly is controlled through the following // set of attributes. Change these attribute values to modify the information // associated with an assembly. [assembly:|AssemblyTitle("GettingStartedSample")] [assembly: AssemblyDescription("")] [assembly:|AssemblyConfiguration("")] [assembly: AssemblyCompany("")] [assembly:|AssemblyProduct("GettingStartedSample")] [assembly: AssemblyCopyright("Copyright © 2015")] [assembly:|AssemblyTrademark("")] [assembly: AssemblyCulture("")] // Setting ComVisible to false makes the types in this assembly not visible // to COM components. If you need to access a type in this assembly from // COM, set the ComVisible attribute to true on that type. [assembly:|ComVisible(false)] // The following GUID is for the ID of the typelib if this project is exposed to COM [assembly:|Guid("38e125d5-8180-4b44-9cff-100b569b69d5")] // Version information for an assembly consists of the following four values: // // Major Version // Minor Version // Build Number // Revision // // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly:|AssemblyVersion("1.0.*")] [assembly: AssemblyVersion("9.0.0.0")] [assembly:|AssemblyFileVersion("9.0.0.0")] ====iOSCapabilityHelper.cs==== using CoreGraphics; using CoreLocation; using System; using UIKit; namespace GettingStartedSample { internal static class iOSCapabilityHelper { private static Version currentSystemVersion; public static Version CurrentSystemVersion { get { return currentSystemVersion ?? (currentSystemVersion = Version.Parse(UIDevice.CurrentDevice.SystemVersion)); } } public static bool IsOnIPhone { get { return UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Phone; } } public static void SetViewLayout(UIView mainView) { if (CurrentSystemVersion.Major < 8) { UIInterfaceOrientation statusBarOrientation = UIApplication.SharedApplication.StatusBarOrientation; if (statusBarOrientation == UIInterfaceOrientation.LandscapeLeft || statusBarOrientation == UIInterfaceOrientation.LandscapeRight) { mainView.Frame = new CGRect(0, 0, UIScreen.MainScreen.Bounds.Height, UIScreen.MainScreen.Bounds.Width); } else { mainView.Frame = UIScreen.MainScreen.Bounds; } } } public static void SetGpsLocationManagerCapability(CLLocationManager locationManager) { if (CurrentSystemVersion.Major >= 8) { // Add "NSLocationWhenInUseUsageDescription" and "NSLocationAlwaysUsageDescription" key into plist file. locationManager.RequestAlwaysAuthorization(); locationManager.RequestWhenInUseAuthorization(); } } } }