转帖|其它|编辑:郝浩|2011-01-13 14:04:33.000|阅读 1519 次
概述:由于WPF很方便承载Windows Form控件,而Map Control、Toolbar Control、TOC Control等都是.NET 控件,当然也可以用XAML来承载ArcEngine的这些控件来开发了。
# 慧都年终大促·界面/图表报表/文档/IDE等千款热门软控件火热促销中 >>
用Windows Form进行ArcGIS Engine二次开发时常见的形式,当然也可以用WPF来进行ArcEngine的二次开发。
由于WPF很方便承载Windows Form控件,而Map Control、Toolbar Control、TOC Control等都是.NET 控件,当然也可以用XAML来承载ArcEngine的这些控件来开发了。
下面简单记述开发步骤:
1.打开VS2008,创建WPF应用程序;
2.添加程序集引用:
ESRI.ArcGIS.AxControls:包含地图控件
ESRI.ArcGIS.System:包含ArcGIS Engine license初始化类
WindowsFormsIntegration:包含WindowsFormsHost,用来在WPF中承载Windows控件
System.Windows.Forms
3.在XAML中添加名称空间:
xmlns:controlHost=
"clr-namespace:System.Windows.Forms.Integration;assembly
=WindowsFormsIntegration"
添加初始化事件Loaded="Window_Loaded"
4.在XAML中添加Map Control、Toolbar Control、TOC Control控件,最后你的XAML代码看起来是这样:
<Window x:Class="WPFMapViewer.MapWindow"
xmlns="//schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="//schemas.microsoft.com/winfx/2006/xaml"
Title="MapViewer Hosted in WPF" Height="433.29" Width="559.944" Loaded=
"Window_Loaded" Background="Beige"
MaxHeight="768" MaxWidth="1024"
xmlns:my="clr-namespace:System.Windows.Forms.Integration;assembly=
WindowsFormsIntegration">
<Grid>
<my:WindowsFormsHost Name="mapHost" Margin="174,30,0,22" />
<my:WindowsFormsHost Margin="0,30,0,22" Name=
"tocHost" HorizontalAlignment="Left" Width="173" />
<my:WindowsFormsHost Height="30" Name="toolbarHost" VerticalAlignment=
"Top" Margin="0,0,252,0" />
<Button Content="MyZoomInBoxTool" x:Name="MyZoomInBoxTool" Click=
"MyZoomInBox_Click" HorizontalAlignment=
"Right" Width="120" Height="30" VerticalAlignment=
"Top" Panel.ZIndex="1" Margin="0,0,7.056,0"></Button>
<TextBlock Height="23.75" VerticalAlignment=
"Bottom" Name="textBlock1" Margin="0,0,7.056,0">Ready</TextBlock>
<Button x:Name="DrawCircleTool" Height="23" HorizontalAlignment="Right"
Margin="0,5,153,0" VerticalAlignment="Top" Width="75" Click=
"DrawCircleTool_Click">DrawCircle</Button>
</Grid>
</Window>
5.编辑XAML的C#代码,添加Map Control、Toolbar Control、TOC Control三个变量,即
AxMapControl mapControl;
AxToolbarControl toolbarControl;
AxTOCControl tocControl;
并在初始化窗口的下面添加对这三个控件变量的创建,即
private void CreateEngineControls ()
{
mapControl = new AxMapControl ();
mapHost.Child = mapControl;
toolbarControl = new AxToolbarControl ();
toolbarHost.Child = toolbarControl;
tocControl = new AxTOCControl ();
tocHost.Child = tocControl;
}
6.在Window_Loaded事件中加载上述三个控件,如下:
7.将上述代码连起来,你的代码看起来是这样:
public partial class MapWindow: Window8.ArcEngine的二次开发当然要License啦,在Windwos From的开发中可以用License控件来进行许可证的初始化,在这里就只能用代码在App.XAML.cs中初始化License了。
代码如下:
public partial class App: Application
{
public App ()
{
InitializeEngineLicense ();
}
private void InitializeEngineLicense ()
{
AoInitialize aoi = new AoInitializeClass ();
esriLicenseProductCode productCode =
esriLicenseProductCode.esriLicenseProductCodeEngine;
if (aoi.IsProductCodeAvailable (productCode) ==
esriLicenseStatus.esriLicenseAvailable)
{
aoi.Initialize (productCode);
}
}
}
9.在WPF中添加自定义工具,如在视图上画圆形的工具,添加DrawCircleToolClass类,如下:
using System;注意:要添加ArcEngine的相关程序集的引用,如:ESRI.ArcGIS.ADF,ESRI.ArcGIS.Carti,ESRI.ArcGIS.Controls,
ESRI.ArcGIS.Display,ESRI.ArcGIS.Geometry,ESRI.ArcGIS.SystemUI
10.在XAML中添加一个Button,并添加一个事件,DrawCircleTool_Click,在C#代码中添加该事件的代码如下:
//绘制圆形
本站文章除注明转载外,均为本站原创或翻译。欢迎任何形式的转载,但请务必注明出处、不得修改原文相关链接,如果存在内容上的异议请邮件反馈至chenjj@pclwef.cn
文章转载自:网络转载