Saturday, September 24, 2011

How to set up ArcGIS for WPF with Prism.

Got a question on the Testing ArcGIS for WPF + Funbeat + Prism. blog post if I could share the code. Sure thing! I've added a project for the sample code on google projects hosting https://code.google.com/p/arcgis-samples/ . I've removed the Funbeat APIs from the solution because it only adds to the complexity and probably only make sense for people in Sweden. 

Here is a step by step description on how I set up the project:
1. Shell app
Create a Wpf Application

1.1 Install Prism using NuGet
Use NuGet  to install microsoft Prism dependencies into the project:
Install-Package prism

1.1.1 Install Extensions using NuGet
Do the same for the extension to be used to load modules:

Install-Package Prism.UnityExtensions
Or
Install-Package Prism.MefExtensions

1.2 Rename MainWindow
Rename MainWindow to Shell both filename and class name, use refactor to rename class so that the partial classes get renamed as well.


1.3 Add region in Shell.xaml
xmlns:prism="http://www.codeplex.com/prism"
 
           
               
                   
               

           

       

1.4 Add Bootstrapper
Add a class Bootstrapper.cs to the project:


Add using:


using System.Windows;
using Microsoft.Practices.Prism.Modularity;
using Microsoft.Practices.Prism.UnityExtensions;
using Microsoft.Practices.Unity;
The bootstrapper should inherit from the UnitBootstrapper if it is the Unity extension you are using:
: UnityBootstrapper
 
 
 
Override methods as shown below:
 
protected override DependencyObject CreateShell()
{
    return new Shell();
}
protected override void InitializeShell()
{
    base.InitializeShell();
    App.Current.MainWindow = (Window)this.Shell;
    App.Current.MainWindow.Show();
}
protected override void ConfigureModuleCatalog()
{
    base.ConfigureModuleCatalog();
}

1.5 App.cs
Change the App.cs so that the Bootstrapper gets called:
protected override void OnStartup(StartupEventArgs e) {
base.OnStartup(e);
Bootstrapper bootstrapper = new Bootstrapper();
bootstrapper.Run();
}
1.6 App.xaml
The bootstrapper is now doing the job remove StartupUri in App.xaml:
StartupUri="MainWindow.xaml"

2. Module
Create a new project for the MapModule.
2.1 Install Prism using NuGet
Install-Package prism
2.1.1 Extensions
Install-Package Prism.UnityExtensions
Or
Install-Package Prism.MefExtensions
2.2 Add references
PresentationCore.dll
PresentationFramework.dll
WindowsBase.dll
System.Xaml.dll
2.3 Rename Class1

Class1 to MapModule
2.4 Add code to MapModule
Add using:

using Microsoft.Practices.Prism.Modularity;
 
Let MapModule inherit IModule:
: IModule
public void Initialize()
{
}
2.4.1 Solutions folders
Add Solution folders:
  • Model
  • Services. In this folder, you store service implementations and service interfaces.
  • ViewModels. In this folder, you store view models.
  • Views. In this folder you add your views.
2.5 Connect the Module with Shell
2.5.1 Add reference
In Shell project add areference to the Module project
2.5.2 Change code in Bootstrapper
Change the code in the bootstrapper so the Module get loaded:

ModuleCatalog moduleCatalog = (ModuleCatalog)this.ModuleCatalog;
moduleCatalog.AddModule(typeof(Module.Module));


3. Add View

3.1 Add xaml

3.1.1 View
Before we can add our map we need to add some references to the ArcGIS for WPF:
Add some esri elements to the view so we can see if it get's loaded correctly:

       
           
                   Url="
http://server.arcgisonline.com/ArcGIS/rest/services/ESRI_StreetMap_World_2D/MapServer"/>
           
       
   



When running the application the end result looks like this:


Sunday, September 18, 2011

Windows 8 and VS2011 developer previews.

Have been busy this weekend checking out the keynotes and some sessions from the Microsoft Build conference last week. Microsoft has released a windows 8 developer preview and a Visual Studio 2011, .Net4.5 developer preview. So I've installed both products. VS11 is included in the 64bit Win8 developer preview, but only the win 8 only features are available and if you install the vs2011 on win7 you can't use the win8 features, So I installed Win8 on Virtualbox see some notes on virtual environment and VS2011 on my win7 machine. I've have made some initial testing:
First Windows 8, the new metro style start page feels like it's spot on when using touch-screens. There is also a mouse and keyboard integration, I don't have touch-screen on my laptop, so I have only used the mouse and keyboard approach, it does not feel perfect though, specially in the metro style applications. In VS2011 you can build metro style applications using C++, C#/VB.Net and HTML/Javascript using the Windows Runtime API. The applications created can be suspended to save battery. A lot of the focus is to save battery time, The fact that Win8 will run on ARM devices, the web sockets support that will be built-in in IE10, IIS8, Windows Runtime Client SDK, .Net4.5...

VS2011 and .Net4.5, .Net4.5 is an in-place update of .Net4.0, that mean that there can be compatibility problems, so any applications built in 4.0 should be tested carefully and as early as possible to avoid problems. .Net4.5 has been made faster. VS2011, the productivity Tools has been integrated into VS2011 also there has been a lot of work done so tools can be used without the need to switch context from the editor. Expression Blend now includes support for HTML and CSS making it easy to use the same Product for all GUI stuff.