现在的位置: 首页 > 综合 > 正文

如何在WPF中嵌入Skyline提供的三维控件

2012年12月23日 ⁄ 综合 ⁄ 共 2015字 ⁄ 字号 评论关闭

以VS2008开发工具以为:

1、创建Visual C# .NET framework 3.0 Windows Application(WPF) 工程
2、添加 reference 到 .NET 组件 WindowsFormsIntegration
3、添加 reference 到 .NET 组件 System.Windows.Forms
4、添加 reference 到 前面生成的Windows Form DLL
5、WPF提供了一个WindowsFormsHost类( 需要添加using System.Windows.Forms.Integration;)用来做Windows Form的容器,我们要用到的Form控件就必须放进这个容器里。我们可以在InitializeComponent()后添加:
WindowsFormsHost host = new WindowsFormsHost();
AxTerraExplorerX.AxTE3DWindow axTE3DWindow1 = new AxTerraExplorerX.AxTE3DWindow();
host.Child = axTE3DWindow1;      
this.TEWindow.Children.Add(host);
以上代码创建一个Windows Form容器,创建Windows Form控件,将控件添加到容器里,再将容器添加到Grid里,这样界面上就可以看到Form控件了,其布局将受到Grid的控制。

 

附后台完整代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Forms.Integration;  // 在WPF中使用ActiveX控件需要引用的类
using TerraExplorerX;  // Skyline提供的类

namespace WPFA_DEMO
{
    /// <summary>
    /// Interaction logic for Window1.xaml
    /// </summary>
    public partial class Window1 : Window
    {
        public Window1()
        {
            InitializeComponent();

            WindowsFormsHost host = new WindowsFormsHost();
            AxTerraExplorerX.AxTE3DWindow axTE3DWindow1 = new AxTerraExplorerX.AxTE3DWindow();
            host.Child = axTE3DWindow1;     
            this.TEWindow.Children.Add(host);
        }

        private TerraExplorer TE;
        private ITerraExplorer51 TE51;

        private void LoadFLY()
        {
            this.TE = new TerraExplorerClass();
            this.TE51 = (ITerraExplorer51)TE;
            this.TE51.Load(@"C:\izhaohe\skyline.fly");

            this.TE.OnLoadFinished += new _ITerraExplorerEvents5_OnLoadFinishedEventHandler(TE_OnLoadFinished);
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            LoadFLY();
        }

        void TE_OnLoadFinished()
        {
            //MessageBox.Show("ok");            
        }

    }
}

 

抱歉!评论已关闭.