.Net5 WPF 使用 WindowsFormsHost
(1)csproj文件添加
<UseWindowsForms>true</UseWindowsForms>
如图:
添加前后框架对比
(2)WPF窗口引入命名空间
xmlns:wfh="clr-namespace:System.Windows.Forms.Integration;assembly=WindowsFormsIntegration"
xmlns:wfc="clr-namespace:System.Windows.Forms;assembly=System.Windows.Forms"
(3)使用
<Grid Grid.Row="1" Background="Black"> <!--<ContentControl Content="{Binding VideoWind}" />--> <WindowsFormsHost VerticalAlignment="Center" Height="300" Width="350" HorizontalAlignment="Center" Margin="10"> <wfc:Panel x:Name="ctrVideo" BackColor="gray" Dock="Fill" /> </WindowsFormsHost> </Grid>