关于WPF中承载 ArcGIS控件。

之前就做过WPF的应用,之前承载的MapGIS的二次开发控件,今天写一下承载的Arcgis的相关控件,

首先,Arcgis的控件不支持WPF,我得环境是vs2010,Engine10,Arcgis的控件支持的还是以前的.net 3.5的winform。但是接触过WPF的都觉得WPF的视觉效果,和用户体验都会比较好,这个时候就需要用承载,WPF的控件中有一个是windowsformshost的控件,这个可以称为是宿主控件吧,然后它里面可以承载一个winform的子控件。

添加引用

  • ESRI.ArcGIS.AxControls—Contains the AxMapControl.
  • ESRI.ArcGIS.System—Contains the AoInitialiseClass class (used to set up the ArcGIS Engine license).
  • ESRI.ArcGIS.Version—Contains runtime manager functionality to bind a specific ArcGIS installation on the machine.

原理就是这样,接下来讲一下首先呢是建项目,然后选择的时候直接选择.net3.5下面的WPF应用,然后是要添加引用,一个是Arcgis 的 axcontrol一个是 control然后,添加这个引用WindowsFormsIntegration,这个是用来承载控件的引用,然后再xmal下面写好空间里面的这样一句 xmlns:in="clr-namespace:System.Windows.Forms.Integration;assembly=WindowsFormsIntegration" Loaded="Window_Loaded",然后就可以直接在wpf下面戴上几个WindowsFormsHost这样的控件,定义好名字和大小位置,然后在c#代码中,windows的load事件中定义几个arcgis的控件,然后再用这样的格式的代码来实现承载

View Code
wfhlin.Child = mylincense;

前面的wfhlin是我定义的windowsformshost的名字,后面的mylincense是我定义的一个 axlincense控件

在app.xmal.cs中写好关于权限许可的代码如下

View Code
1 protected override void OnStartup(StartupEventArgs e)
2 {
3 base.OnStartup(e);

4 InitializeEngineLicense();
5 }
6
7 private void InitializeEngineLicense()
8 {
9 AoInitialize aoi = new AoInitializeClass();
10
11 //More license choices can be included here.
12 esriLicenseProductCode productCode = esriLicenseProductCode.esriLicenseProductCodeEngine;
13 if (aoi.IsProductCodeAvailable(productCode) == esriLicenseStatus.esriLicenseAvailable)
14 {
15 aoi.Initialize(productCode);
16 }
17 }

在调用这个方法的时候

ESRI.ArcGIS.RuntimeManager.Bind(ESRI.ArcGIS.ProductCode.Engine);
posted @ 2011-05-18 16:12  Zoe_J  阅读(1279)  评论(0编辑  收藏  举报