WPF使用WinForm控件遇到的一些问题
作者:互联网
WPF使用WinForm控件PIctureBox实现视频流
<Window x:Class="Test.TestPictureBox"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:Test"
xmlns:wf="clr-namespace:System.Windows.Forms;assembly=System.Windows.Forms"
mc:Ignorable="d" WindowStyle="None" AllowsTransparency="True"
Title="TestPictureBox" Height="450" Width="800">
<Grid>
<WindowsFormsHost>
<wf:PictureBox x:Name="pbVideo" />
</WindowsFormsHost>
</Grid>
</Window>
/// <summary>
/// TestPictureBox.xaml 的交互逻辑
/// </summary>
public partial class TestPictureBox : Window
{
public TestPictureBox()
{
InitializeComponent();
var handle = (this.pbVideo).Handle;
// 此处设置handle接收视频
}
}
测试过程中出现问题, 但在实际使用中发现PictureBox控件无法显示,查找资料发现是因为
AllowsTransparency="True"
导致WindowsFormsHost无法显示,去掉此属性又会导致窗体无法达到显示的效果,找到了WindowChrome
<Window x:Class="Test.TestPictureBox"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:Test"
xmlns:wf="clr-namespace:System.Windows.Forms;assembly=System.Windows.Forms"
mc:Ignorable="d" WindowStyle="None"
WindowChrome.WindowChrome="{DynamicResource WindowChromeKey }"
Title="TestPictureBox" Height="450" Width="800">
<Window.Resources>
<WindowChrome x:Key="WindowChromeKey" ResizeBorderThickness="0"
CaptionHeight="0" CornerRadius="0" GlassFrameThickness="0"/>
</Window.Resources>
<Grid>
<WindowsFormsHost>
<wf:PictureBox x:Name="pbVideo" />
</WindowsFormsHost>
</Grid>
</Window>
参考资料
WindowChrome官方介绍
WinformHost Control does not shown when windows AllowTransparency = true
WPF在WindowStyle=None时去掉顶部白条
标签:控件,handle,TestPictureBox,WindowChrome,WPF,public,WinForm 来源: https://www.cnblogs.com/upslw/p/14759640.html