如何在WPF中调用Winform控件
生活随笔
收集整理的這篇文章主要介紹了
如何在WPF中调用Winform控件
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
| 功能實現主要分三步: 1、添加兩個引用:WindowsFormsIntegration.dll (負責整合WPF和Windows)、System.Windows.Forms. 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> 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> 效果圖: 在本人的代碼中Grid的作用相當于Web頁面中用來布局的Table。 此處加上Grid是為了方便移動控件的位置。 |
總結
以上是生活随笔為你收集整理的如何在WPF中调用Winform控件的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 远程更安全?
- 下一篇: 什么是对象?——摘自《设计模式精解》(熊