Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/ant/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在WPF用户控件上添加自定义Windows控件_Wpf_Xaml_User Controls - Fatal编程技术网

在WPF用户控件上添加自定义Windows控件

在WPF用户控件上添加自定义Windows控件,wpf,xaml,user-controls,Wpf,Xaml,User Controls,我有一个WinForms用户控件(一个工具栏),我想把它添加到WPF用户控件上,有什么方法可以做到这一点吗 就像我想要一个WinForms用户控件(工具栏)和其他WPF控件一样 (datagrid)在新的WPF用户控件上 我看到了几个示例,它们显示了WPF控件中托管的Windows窗体。但这不是我想看到的。这很容易实现。有一个叫做WindowsFormHost的小东西,您只需在控件的XAML中声明它,并将表单控件嵌套在其中,如下所示: <UserControl> ... <Gr

我有一个WinForms用户控件(一个工具栏),我想把它添加到WPF用户控件上,有什么方法可以做到这一点吗

就像我想要一个WinForms用户控件(工具栏)和其他WPF控件一样 (datagrid)在新的WPF用户控件上


我看到了几个示例,它们显示了WPF控件中托管的Windows窗体。但这不是我想看到的。

这很容易实现。有一个叫做
WindowsFormHost
的小东西,您只需在控件的XAML中声明它,并将表单控件嵌套在其中,如下所示:

<UserControl>
...
<Grid>
  <WindowsFormsHost>
    <forms:MyFormsToolbarControl/>
  </WindowsFormHost>
</Grid>

...

...
...
WindowsFormHost
位于普通WPF工具箱中,因此不难找到它。同时,还有一个例子说明了如何在这个位置在代码中生成等效的XAML


您可以在此处查看我对类似问题的回答:


这还将向您展示如何解决wpf视图中的windows控件的制表符问题。

您想在WinForms应用程序中使用wpf控件,对吗?所谓“windows.NET用户控件”是指WinForms用户控件还是wpf用户控件?@Joe White-win forms用户控件。@iaimtomisbehave:不是另一种方式,WPF用户控件中的windows用户控件“但这不是我想看到的”听起来正是您想看到的:在WPF父级中托管WinForms。你能解释一下为什么这些样品不能解决你的问题吗?