我需要将 Windows 窗体用户控件 (Barcode_Scanner.cs) 添加到 WPF View (MainWindow.xaml)
有没有简单的方法来做到这一点? 任何帮助将不胜感激。
最佳答案
您可以使用 WPF WindowsFormsHost
元素承载 Windows.Forms
控件。
例子:
<Window x:Class="WpfApplication10.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:winforms="clr-namespace:System.Windows.Forms;assembly=System.Windows.Forms"
xmlns:myControls="clr-namespace:MyContromNamespace;assembly=MyContromNamespace"
Title="MainWindow" Height="195" Width="191" Name="UI">
<Grid>
<WindowsFormsHost>
<winforms:Button Text="StackOverflow" />
</WindowsFormsHost>
<WindowsFormsHost>
<myControls:MyUserControl />
</WindowsFormsHost>
</Grid>
</Window>
结果:
关于c# - 将 Windows 用户控件添加到 WPF View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15824994/