WPF加载Winform控件时总是位于顶层,同位置处再放置WPF控件将会被遮挡。这在实际应用当中,例如:加载视频流时,总是使用Winform的PictureBox控件来显示,如果用WPF去加载这个PictureBox控件,想在上面加个控制按钮或者默认图标时就会出现这个显示层级问题。
例如窗体代码:
<Window x:Class="WpfWinformDemo.MainWindow"
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:WinFormHost="clr-namespace:System.Windows.Forms.Integration;assembly=WindowsFormsIntegration"
xmlns:WinFormControls="clr-namespace:System.Windows.Forms;assembly=System.Windows.Forms"
xmlns:local="clr-namespace:WpfWinformDemo"
mc:Ignorable="d" Loaded="Window_Loaded"
Title="MainWindow" Height="350" Width="525">
<Grid Margin="10">
<Window

当WPF加载Winform控件如PictureBox时,可能会遇到显示遮挡问题。本文介绍了这个问题的背景,以及如何通过使用Popup控件来解决。通过创建一个自定义的CusPopup控件,使得WPF的控件能始终保持在PictureBox之上,并随窗口移动。
最低0.47元/天 解锁文章
3万+





