Creating a custom task for a Windows application
This walkthrough describes how to use a Visual Studio project template to develop a task and deploy it using Mobile Project Center (MPC).
ArcGIS for Windows Mobile ships with two Visual Studio 2008 C# project templates to help you create Visual Studio projects for building a Windows application task or project extension. These templates are integrated with Visual Studio 2008 and can be used in the same way as the Visual Studio built-in project templates. A project created based on the template contains classes for your task or project extension, assembly reference, and project properties.
In this walkthrough, you'll learn how to create a Hello World task using the Visual Studio project template and deploy it with MPC.
The steps involved include the following:
- Create a solution using the template for Visual Studio .NET 2008.
- Review the generated code and skeleton methods.
- Add a simple button to a page.
- Add the custom task to a project with MPC.
- Deploy the project to the ArcGIS Mobile for Windows application.
- Test the App Menu project extension.
Where to get the sample
Download the HelloWorldTask sample.
Prerequisites
To complete this walkthrough, you need the following:
- Visual Studio .NET 2008 SP1
- .NET Framework 3.5 SP1
- ArcGIS Mobile for Windows application, Mobile API
assemblies, and Visual Studio 2008 project templates for ArcGIS
Mobile
When running the ArcGIS for Windows Mobile setup on a machine with Visual Studio 2008 installed, these components will be automatically installed and configured.
Creating an ArcGIS Mobile application task using a Visual Studio project template
The Hello World task appears as a menu item on the View Map page menu. Tap this task menu item, and the application starts the Hello World task workflow and navigates to another page.
- Start Visual Studio .NET 2008 and click File > New > Project.
- Click ArcGIS Mobile under Visual C# in the Project types pane on the New Project dialog box.
- Choose .NET Framework 3.5 from the drop-down list at the top right of the dialog box.
- Choose Task in the Templates pane.
- Name the project HelloWorldTask, specify the
location for the project, then click OK.
- Since you do not need the Windows Mobile project, you
can delete it from the solution.
Visual Studio creates three projects in the solution using this template: one for the Windows application, one for the Windows Mobile application, and one for MPC.
- The Windows and Windows Mobile projects are for developing task assemblies used with the Windows application and Windows Mobile application.
- The MPC project is for developing an assembly for describing the application's HelloWorldTask assembly. MPC needs it to deploy the Hello World task to mobile projects.
- Review the HelloWorldTask_Win
project. It contains a HelloWorldTask class derived from Task. Task
is the base class for all tasks within the ArcGIS Mobile for
Windows application.
In the constructor, it defines task name and description.
This HelloWorldTask class also has a function called Execute(), which is called when the Hello World task is launched in the application, it should be created as follows:
MobileApplication.Current.Transition(new Page1());
Page1 is an empty Mobile Application page created from the Task project template.
Now the HelloWorldTask_Win.cs file looks like this:
using System; using System.Collections.Generic; using System.Linq; using System.Text; using ESRI.ArcGIS.Mobile; using ESRI.ArcGIS.Mobile.Client; namespace HelloWorldTask { /// <summary> /// TODO: Make the following attributes the same for all /// the projects in this solution /// 1. Current Namespace /// 2. Task class name and project center class name /// 3. Assembly name (through Project's Property dialog) /// 4. Default Namespace (through Project's Property dialog) /// </summary> public class HelloWorldTaskClass : Task { // TODO: Update constructor name after you change task name public HelloWorldTaskClass() { //Name Name = "HelloWorldTaskClass"; //Description Description = "My Custom Task description"; } // task icon, // need the same way as for page icon // TODO: If you change task assembly name, replace the "HelloWorldTask" // in the Uri with new Task assembly name. protected override System.Windows.Media.ImageSource GetImageSource() { Uri uri = new Uri("pack://application:,,,/HelloWorldTask;Component/TaskIcon72.png"); return new System.Windows.Media.Imaging.BitmapImage(uri); } public override void Execute() { MobileApplication.Current.Transition(new Page1()); } } }
- Add a button to the empty Page1 by opening the Page1.xaml file and adding a button within the grid as follows:
<ArcGISMobileApplication:MobileApplicationPage x:Class="HelloWorldTask.Page1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:ArcGISMobileApplication="clr-namespace:ESRI.ArcGIS.Mobile.Client;assembly=ESRI.ArcGIS.Mobile.Client" Height="300" Width="300"> <Grid> <Button Height="100" Width="200" Name="button1" >Hello again</Button> </Grid> </ArcGISMobileApplication:MobileApplicationPage>
- Now, this simple Hello World task is done, compile it to make HelloWorldTask.dll.
- To deploy this Hello World task to a mobile project using MPC, the *_ProjectCenter project will be used. Ensure that it compiles correctly.
- Copy the compiled assemblies to the Program Data folder to be used by MPC.
- Copy the Windows assembly HelloWorldTask.dll from C:\COGS\HelloWorldTask\HelloWorldTask\HelloWorldTask_Win\bin\Debug to C:\ProgramData\ESRI\MobileProjectCenter\Extensions\Win32.
- Copy the MPC assembly HelloWorldTask.dll from the build location to the MPC folder. Your build location should be <working folder>HelloWorldTask\HelloWorldTask_ProjectCenter\bin\Debug, and the MPC folder for the Windows task C:\ProgramData\ESRI\MobileProjectCenter\Extensions.
- Add the Hello World task to a mobile project using MPC.
- Launch MPC and create a new project, or open an existing project.
- Click the Tasks tab and click Add. The
Hello World task is listed here. Add it to the project and save the
project.
- Test the Hello World task in the Windows application.
- Share your project with the HelloWorld task to ArcGIS Online or your own ArcGIS Server.
- Start the ArcGIS Mobile application, and download the project with your custom task.
- Open the Task Menu; the Hello World task should be added to the View Map page menu.
- Launch the ArcGIS Mobile for Windows application, and open the project you just created.
- Click Hello World Task; the application navigates to the Hello World Page.