windows窗体程序中使用WPF控件 Host WPF Controls in Windows Forms Application
2013-06-15 15:28
691 查看
参考http://keyvan.io/host-wpf-controls-in-windows-forms
在windows form appliation中添加wpf空间,需要使用一个ElementHost的容器,接着将创建出来的WPF对象赋值到ElementHost的child属性中,类似子控件添加到Panel或者Form的controls容器中,可以ElementHost只能对应一个wpf控件,接着将ElementHost添加到父级Controls中。
实现如下:
1. 创建Windows Form Application项目,命名为HostWPFWinForm
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Windows.Forms.Integration;
namespace HostWPFWinForm
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
// Add WPF Control
MyWPFControl control = new MyWPFControl();
ElementHost host = new ElementHost();
host.Top = 0;
host.Left = 0;
host.Width = 300;
host.Height = 40;
host.Child = control;
this.Controls.Add(host);
}
}
}
[/code]6. 编译并且运行程序,效果图如下:
在windows form appliation中添加wpf空间,需要使用一个ElementHost的容器,接着将创建出来的WPF对象赋值到ElementHost的child属性中,类似子控件添加到Panel或者Form的controls容器中,可以ElementHost只能对应一个wpf控件,接着将ElementHost添加到父级Controls中。
实现如下:
1. 创建Windows Form Application项目,命名为HostWPFWinForm
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Windows.Forms.Integration;
namespace HostWPFWinForm
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
// Add WPF Control
MyWPFControl control = new MyWPFControl();
ElementHost host = new ElementHost();
host.Top = 0;
host.Left = 0;
host.Width = 300;
host.Height = 40;
host.Child = control;
this.Controls.Add(host);
}
}
}
[/code]6. 编译并且运行程序,效果图如下:
相关文章推荐
- wpf怎么使用WindowsFormsHost(使用WinForms中的控件)
- 在WPF中内嵌WindowsForm控件-使用WindowsFormsControlLibrary
- wpf怎么使用WindowsFormsHost
- How to: Host Controls in Windows Forms DataGridView Cells (CalendarCell)
- WPF 中如何使用第三方控件 ,可以使用WindowsFormsHost 类
- 让WPF的TextBox控件可以使用System.Windows.Forms.FontDialog设置样式
- 转载 [WPF][C#]在WPF中内嵌WindowsForm控件-使用WindowsFormsControlLibrary
- How to: Host Controls in Windows Forms DataGridView Cells(介绍如何在datagridview中自定义列)
- WPF—DocumentGroup中用到了WindowsFormsHost,窗体浮动的时候winform控件不可见的解决办法
- 在 .NET 程序的窗体中使用 XP 风格的控件
- 使用两个 Windows 窗体 DataGridView 控件创建一个主/从窗体
- vs2008 使用c#编写web浏览器加载的windows窗体控件
- 在IE浏览器中使用Windows窗体控件(1)
- ExtJS中表格控件的使用,属性设置和数据的获取(copyfrom:http://www.itzhai.com/extjs-form-controls-in-the-use-of-property-)
- Creating the Same Program in Windows Forms and WPF
- 在 Internet Explorer 中使用 Windows 窗体控件
- 演练:使用 Visual C# 从 Windows 窗体控件继承
- 使用 TableLayoutPanel 在 Windows 窗体上自动排列控件
- 使用.Net编写Windows程序,对于窗体控制常见项目