WPF 嵌入winform 控件


引入 WindowsFormsIntegration.dll   和   System.Windows.Forms.dll

  

<Window x:Class="wgscd.Window1"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:WinFormHost="clr-namespace:System.Windows.Forms.Integration;assembly=WindowsFormsIntegration"
xmlns:WinFormControls="clr-namespace:System.Windows.Forms;assembly=System.Windows.Forms" Title="Window1" Height="362" Width="655">
    <Grid Name="grid">
        <WindowsFormsHost  Margin="0,65,0,0" Name="windowsFormsHost1" >
            <WinFormControls:WebBrowser  x:Name="web"/>
        </WindowsFormsHost>
        <Button Height="39" VerticalAlignment="Top"  HorizontalAlignment="Left" Width="159" Margin="107,20,0,0" Click="Button_Click">gggg</Button>
    </Grid>
</Window>

  

 

也可以代码动态添加:

System.Windows.Forms.Integration.WindowsFormsHost host =
                new System.Windows.Forms.Integration.WindowsFormsHost();
          
         System.Windows.Forms.WebBrowser web = new System.Windows.Forms.WebBrowser();
         
         web.Url = new Uri("http://www.baidu.com");
            
         host.Child = web;
          
         this.grid.Children.Add(host);

  

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM