wpf - 错误 XLS0502 'WindowsFormsHost' 类型不支持直接内容

标签 wpf vb.net winforms

我正在尝试在 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”类型不支持直接内容。
有什么建议吗?

最佳答案

确实,您不能直接设置 ContentWindowsFormsHost元素,您需要设置 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/

相关文章:

c# - 取消 CheckedListBox 上的 ItemCheck 事件的可靠方法

vb.net "if statement"包含加号

C# PictureBox - 无法使其工作

c# - 如何更改 WinForms Treeview 控件中用于内联编辑节点文本的字体?

C# - 矩形动画闪烁

c# - MVVM 疯狂 : Commands

c# - 将 TabControl 绑定(bind)到 ViewModel 集合

wpf - 绑定(bind)到 WPF 中 TabControl 的 ItemsSource

wpf - 从 DataTemplate 内的资源绑定(bind)

asp.net - 循环遍历 gridview 并获取数据键值