WPF中引入WindowsForms控件的辦法。本站提示廣大學習愛好者:(WPF中引入WindowsForms控件的辦法)文章只能為提供參考,不一定能成為您想要的結果。以下是WPF中引入WindowsForms控件的辦法正文
本文實例講述了WPF中引入WindowsForms控件的辦法。分享給年夜家供年夜家參考,詳細以下:
情況:
[1]WindowsXP with SP3
[2]VS2008 with SP1
注釋:
Step1:在現有工程中引入Windows Forms
鼠標右鍵[References]->選擇[Add Reference]->[.NET]標簽頁
參加[WindowsFormsIntegration]和[System.Windows.Forms]兩項
Step2:在XAML文件裡參加
[S2-1]參加namespace援用:
xmlns:wf="clr-namespace:System.Windows.Forms;assembly=System.Windows.Forms" xmlns:wfi="clr-namespace:System.Windows.Forms.Integration;assembly=WindowsFormsIntegration"
[S2-2]參加Windows Forms控件
<wfi:WindowsFormsHost Name="winFormsContainer" Grid.Row="2" Margin="0,5,0,0"> <wf:ListView x:Name="listView1" Margin="0,2,0,0" Name="listView1"/> </wfi:WindowsFormsHost>
Step3:在CS代碼外面操作WindowsForms控件
Icon icon = new Icon(@"driver.ico"); System.Windows.Forms.ImageList imageList2 = new System.Windows.Forms.ImageList(); imageList2.Images.Add(icon); listView1.SmallImageList = imageList2;
願望本文所述對年夜家C#法式設計有所贊助。