繁体   English   中英

在WPF工具箱中找不到我的winforms控件

[英]Can't find my winforms control in WPF toolbox

我从一个项目中制作了自定义winforms控件,然后切换到WPF。 我引用了旧项目,但我的自定义控件没有显示在工具箱中,似乎没有“简单”的方法将它们添加到我的winforms主机中。 我必须在代码中添加它们吗?

另外,如果我决定在wpf中重新编写代码,它会有多难/不同?

因为WPF与WinForms的工作方式有很大不同,所以WPF中没有WinForms的交互式设计器。 使用WindowsFormsHost将WinForms控件放在WPF窗口中。

您可以通过XAML执行此操作:

<Window x:Class="Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:wf="clr-namespace:My.Custom.Assembly;assembly=My.Custom.Assembly"  
Title="HostingWfInWpf">
<Grid>
    <WindowsFormsHost>
       <wf:MyCustomControl />
    </WindowsFormsHost>
</Grid>
</Window>

My.Custom.Assembly替换为您自己的程序集,将MyCustomControl替换为您的控件名称。

如果可能,重写WPF控件将是最佳选择,因为它将允许WPF功能,如硬件加速。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM