gpt4 book ai didi

c# - 如何在 WPF 应用程序中放置自定义 Windows 窗体控件?

转载 作者:太空狗 更新时间:2023-10-29 22:29:22 24 4
gpt4 key购买 nike

作为短期解决方案,我正在尝试将 Windows 窗体“用户控件”插入 WPF 应用程序。我在 WPF 应用程序 View 中看到我可以向项目添加一个“自定义 Windows 窗体控件”,它生成一个空的自定义控件,但我不知道如何添加它。理想情况下,我想知道如何从我编译的 Windows 窗体用户控件中获取 .dll 并将其粘贴到 WPF 应用程序中,或者将用户控件导入到 WPF 应用程序中。

谢谢,山姆

最佳答案

您不能真正将其作为控件添加到工具箱中,就像您可以将其添加到 Windows 窗体应用程序中一样。您应该做的是在 WPF 应用程序内部“托管”用户控件。

See how to do it on MSDN .

这是一个如何使用屏蔽文本框的示例(您可以轻松修改它以使用您的自定义控件):

<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:System.Windows.Forms;assembly=System.Windows.Forms"
Title="HostingWfInWpf">
<Grid>
<WindowsFormsHost>
<wf:MaskedTextBox x:Name="mtbDate" Mask="00/00/0000"/>
</WindowsFormsHost>
</Grid>
</Window>

关于c# - 如何在 WPF 应用程序中放置自定义 Windows 窗体控件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1310154/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com