演练:在 Windows 窗体中承载 Windows Presentation Foundation 复合控件 【转载】
http://msdn.microsoft.com/zh-cn/library/ms745781.aspx
更新:2007 年 11 月
本演练演示如何创建 WPF 复合控件,并通过使用 ElementHost 控件在 Windows 窗体控件和窗体中承载它。
在本演练中,将实现一个包含两个子控件的 WPFUserControl。 UserControl 显示一个三维 (3-D) 圆锥。使用 WPF 呈现三维对象比使用 Windows 窗体更简单。因此,对于在 Windows 窗体中创建三维图形,承载 WPFUserControl 类非常有意义。
本演练涉及以下任务:
创建 WPFUserControl。
创建 Windows 窗体宿主项目。
承载 WPFUserControl。
有关本演练中所阐释任务的完整代码清单,请参见在 Windows 窗体中承载 Windows Presentation Foundation 复合控件的示例。
注意 显示的对话框和菜单命令可能与“帮助”中所述的有所不同,具体取决于当前的设置或版本。若要更改设置,请在“工具”菜单上选择“导入和导出设置”。有关更多信息,请参见 Visual Studio 设置。
先决条件
您需要以下组件来完成本演练:
Visual Studio 2008.
创建 UserControl
创建 UserControl
创建一个名为 HostingWpfUserControlInWf 的 WPF 用户控件库项目。
在 WPF 设计器中打开 UserControl1.xaml。
用下面的代码替换生成的代码。
该代码定义一个包含两个子控件的 System.Windows.Controls.UserControl。第一个子控件是 System.Windows.Controls.Label 控件;第二个控件是显示三维圆锥的 Viewport3D 控件。
创建 Windows 窗体宿主项目
创建宿主项目
将名为 WpfUserControlHost 的 Windows 应用程序项目添加到解决方案中。有关更多信息,请参见“添加新项目”对话框。
在解决方案资源管理器中,添加一个对名为 WindowsFormsIntegration.dll 的 WindowsFormsIntegration 程序集的引用。
添加对以下 WPF 程序集的引用:
PresentationCore
PresentationFramework
WindowsBase
添加对 HostingWpfUserControlInWf 项目的引用。
在解决方案资源管理器中,将 WpfUserControlHost 项目设置为启动项目。
承载 Windows Presentation Foundation UserControl
承载 UserControl
在 Windows 窗体设计器中打开 Form1。
在“属性”窗口中,单击“事件”,然后双击 Load 事件以创建事件处理程序。
代码编辑器打开并定位到新生成的 Form1_Load 事件处理程序。
将 Form1.cs 中的代码替换为以下代码。
Form1_Load 事件处理程序将创建一个 UserControl1 实例,并将其添加到ElementHost 控件的子控件集合中。ElementHost 控件将被添加到窗体的子控件集合中。
Visual Basic
Imports System Imports System.Collections.Generic Imports System.ComponentModel Imports System.Data Imports System.Drawing Imports System.Text Imports System.Windows.FormsImports System.Windows.Forms.IntegrationPublic Class Form1Inherits FormPrivate Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load' Create the ElementHost control for hosting the' WPF UserControl.
Dim host As New ElementHost()
host.Dock = DockStyle.Fill' Create the WPF UserControl.Dim uc As New HostingWpfUserControlInWf.UserControl1()' Assign the WPF UserControl to the ElementHost control's' Child property.host.Child = uc' Add the ElementHost control to the form's' collection of child controls.Me.Controls.Add(host)End SubEnd Class
按 F5 生成并运行该应用程序。
转载于:https://www.cnblogs.com/chenxizhang/archive/2009/05/07/1451281.html
演练:在 Windows 窗体中承载 Windows Presentation Foundation 复合控件 【转载】相关推荐
- win7禁用powershell_简述Windows 7中的Windows PowerShell功能
Win7之家( www.win7china.com):简述Windows 7中的Windows PowerShell功能 也许有人会问,这么多的Windows版本过去了,命令提示符怎么还是那样啊?以前 ...
- wav文件 服务器失败,修复:Windows 7 中的 Windows Media Player 出现问题或错误,在 .wav 文件结束之前停止播放...
修补程序信息 Microsoft 提供了一个受支持的修补程序.但是,此修补程序仅用于修复本文所述的问题.仅将此修补程序应用于出现文本中所描述问题的系统.此修补程序可能还会接受进一步的测试.因此,如果这 ...
- 微软打印机驱动服务器,无法通过 Windows Server 中的 Windows 更新来安装打印机驱动程序 - Windows Server | Microsoft Docs...
打印机驱动程序无法通过 Windows Server 2019 Windows Server 2016 Windows Update 进行安装 12/07/2020 本文内容 本文提供了从 Windo ...
- win10 关机变注销重启_如何在Windows 10中更改Windows 10注销,登录和关机声音
win10 关机变注销重启 Before Windows 10 came along, we were free to change the sounds that played when we sh ...
- windows管理右键菜单_在Windows 8中使用Windows 7开始菜单,资源管理器和任务管理器...
windows管理右键菜单 If you've tried the Windows 8 Developer Preview and found you don't like the new Start ...
- 在Windows家庭版中安装Windows Sandbox(Windows 沙盒)
Windows的版本 Windows有很多版本,例如企业版.专业版和家庭版,而企业版和专业版中的一些功能是家庭版没有的,接下来我将尝试在Windows 11家庭版中安装Windows沙盒 开始了 首先 ...
- 计算机打印机用户,如何:在 Windows 窗体中选择连接到用户计算机的打印机
使用 PrintDialog 组件选择要使用的打印机. 在下面的代码示例中,有两个要处理的事件.第一个事件是 Button 控件的 Click 事件,在该事件中,PrintDialog 类被实例化,并 ...
- 在Windows 7中的Windows Media Player 12中快速预览歌曲
Do you ever wish you could quickly preview a song without having to play it? Today we look at a quic ...
- 第五十九期:如何在Windows 10中执行Windows Defender离线扫描?
如果你使用Windows并经常上网浏览,强烈建议使用防病毒/安全保护软件.Windows 10随带一款名为Windows Defender/Security的内置防病毒保护工具,在过去几年不断成熟,已 ...
最新文章
- python中排序英文单词怎么写_Python实现对文件进行单词划分并去重排序操作示例...
- 图论(九)最小生成树-Kruskal算法
- 17. Merge Two Binary Trees 融合二叉树
- sqlserver结果集转为字符串
- 用户注意到用户计算机中千兆位网卡,为何你电脑上的千兆网卡跑不到千兆?
- Circular buffer
- Flask带参URL传值的方法
- UITabBarController的一些基础设置
- vba遍历字符串_操蛋的VBA程序错误!
- IE、Chrome、Firefox下的按钮文字居中
- FeHelper ( 浏览器插件 )
- 【原创】EXCEL公式经验(1)---如何拆解/拆分字符串为多列和多行,但是注意不要超过EXCEL字符串最长长度限制!
- SPSS-描述统计与图示分析
- 数据同步工具之DataX理论
- Matlab|模拟电动汽车的充放电【充电顺序,波动发电,电池缓冲】
- 红包活动竟藏着这么多玩法(附使用技巧)
- 将两个字符串连接起来,不要用strcat函数
- eclipes的使用
- 隐藏Spring Elements
- java中向上的尖括号是什么,什么lt; Tgt; (尖括号)在Java中是什么意思?
热门文章
- 配置单臂路由、三层交换技术以及动态路由
- margin负值布局(一)
- dwz简单配置与操作
- shell配置,选择,环境变量修改(ORACLE_HOME,ORACLE_SID),无法使用sqlplus
- 漫谈数据库索引 | 脚印 footprint(转载)
- 图解SQL Join用法
- Linux下Verilog仿真过程(一)
- Android 蓝牙操作--读取远程已配对的蓝牙设备
- 磁盘空间去向不明的问题
- [ShapeInferenceError] Mismatch between number of source and target dimensions. Source=1 Target=0