WPF开发工具可以帮助我们实现许多功能。对于开发者而言,这是一个具有重要意义的开发工具。我们在这里就为大家介绍一下有关WPF调用Winform控件的相关实现方法。
WPF调用Winform控件实现主要分三步:
WPF调用Winform控件1、添加两个引用:WindowsFormsIntegration.dll (负责整合WPF和Windows)、System.Windows.Forms.
WPF调用Winform控件2、在 XAML文件中添加两个引用(粗体部分):
- < Window x:Class="CrossBowDemo.
MainWindow" - xmlns:wfi ="clr-namespace:System.Windows.Forms.Integration;assembly=WindowsFormsIntegration"
- xmlns:wf ="clr-namespace:System.Windows.Forms;assembly=System.Windows.Forms"
- xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
- xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
- Title="Hosting Windows Forms Control In WPF"
- Height="300" Width="650"
- ResizeMode="NoResize" Loaded="WindowLoadedHandler" >
- < /Window>
WPF调用Winform控件3、在XAML编码区实现你想添加的控件:
原文添加的是 DataGridView控件:
- < wfi:WindowsFormsHost>
- < !-- Set some properties on
Windows Forms control in Xaml --> - < wf:DataGridView x:Name="dataGridView" Dock="Fill" SelectionMode="FullRowSelect"/>
- < /wfi:WindowsFormsHost>
本人添加的是 NumericUpDown控件:
- < Grid Height="0" Margin="146,0,0,116" MinHeight="20" MinWidth="20" Name="grid1"
VerticalAlignment="Bottom" HorizontalAlignment="Left" Width="50"> - < wfi:WindowsFormsHost>
- < wf:NumericUpDown x:Name="nupCounter" Maximum="100">
< /wf:NumericUpDown> - < /wfi:WindowsFormsHost>
- < /Grid>
在本人的WPF调用Winform控件代码中Grid的作用相当于Web页面中用来布局的Table。 此处加上Grid是为了方便移动控件的位置。
来源:CSDN
作者:mao_kun
链接:https://blog.csdn.net/mao_kun/article/details/6321712