轉帖|其它|編輯:郝浩|2011-01-13 14:04:33.000|閱讀 1527 次
概述:由于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@fc6vip.cn
文章轉載自:網絡轉載