我正在尝试在 WPF 中使用 winform 控件(我还没有找到好的替代方案)。
控件是来自 sourceforge 的 be.hexbox:https://sourceforge.net/projects/hexbox/files/hexbox/
所以我开始一个新的解决方案 VB.net WPF 并添加 WindowsFormsIntegration.dll 引用。
我还添加了对控制 dll 的引用。
<Window x:Class="MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:wf="clr-namespace:Be.Windows.Forms;assembly=Be.Windows.Forms.HexBox"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:WpfApp2"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800">
<Grid>
<WindowsFormsHost Name="TEST1">
<wf:HexBox x:Name="HX" />
</WindowsFormsHost>
</Grid>
</Window>
但我收到此错误:错误 XLS0502 “WindowsFormsHost”类型不支持直接内容。
有什么建议吗?
最佳答案
确实,您不能直接设置 Content
在 WindowsFormsHost
元素,您需要设置 Child
属性(property)代替。
试试这个:
<WindowsFormsHost Name="TEST1">
<WindowsFormsHost.Child>
<wf:HexBox x:Name="HX" />
</WindowsFormsHost.Child>
</WindowsFormsHost>
关于wpf - 错误 XLS0502 'WindowsFormsHost' 类型不支持直接内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63573863/