且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在我的WPF页面上添加Winforms控件

更新时间:2023-12-06 09:44:58

什么不起作用?的意思是,该页面托管在哪里? WPF桌面应用程序有一个主窗口,您可以在其中放置一个框架来显示页面:

What does "not work" mean and where is the Page hosted? A WPF desktop application has a main window in which you can put a Frame to display pages:

<Window x:Class="WpfApplication1.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        mc:Ignorable="d"            
        Title="MainWindow" Width="564" Height="574" Name="win"
        d:DataContext="{d:DesignInstance local:MyViewModel,IsDesignTimeCreatable=True}">
    <StackPanel>
        <Frame Source="PageAbout.xaml"/>
</StackPanel>
</Window>

然后页面上的WindowsFormsHost应该照常工作.

Then the WindowsFormsHost on the Page should work as usual.

您还可以如以下链接中所述在XBAP内托管Windows窗体控件,但它需要完全信任: http://ahmadreza.com/2011/05/17/how-to-host-a-windows-form-application-inside-xbap/

You can also host a Windows Forms controls inside an XBAP as described on the following link but it requires full trust: http://ahmadreza.com/2011/05/17/how-to-host-a-windows-form-application-inside-xbap/

部署完全信任的XBAP: http://msdn.microsoft.com/zh-cn/library/aa970060(v=vs.110).aspx

Deploying a Full-Trust XBAP: http://msdn.microsoft.com/en-us/library/aa970060(v=vs.110).aspx