首页 > 解决方案 > 在 Microsoft Teams 上共享主窗口时,透明子窗口呈现为黑色

问题描述

问题描述
我有一个WPF子窗口和一个WPF主窗口。主窗口设置为子窗口的所有者。子窗口具有透明背景并位于主窗口的顶部。

当我共享我的整个屏幕时,会议客人可以看到主窗口和子窗口以及两个窗口的所有内容都很好。当我只共享主窗口时,会议客人会看到子窗口的背景为黑色而不是透明。

在我自己的屏幕上,两个窗口都渲染得很好——不管它们是如何共享的。

该问题可在 Microsoft Teams 上重现,但不能在 Zoom 上重现。

这是应用程序在我的计算机上呈现的方式 - 无论我如何共享我的屏幕:
透明窗口渲染良好

这是我共享整个屏幕时会议参与者看到应用程序的方式(屏幕截图仅说明应用程序,但显然参与者可以看到整个屏幕):
带有透明窗口的子窗口在我的计算机上渲染得很好

这是当我只共享主窗口时会议参与者看到应用程序的方式(黑色部分是子窗口的背景,它应该真正显示为透明而不是黑色):
具有透明窗口的子窗口以黑色背景呈现

如果我将子窗口的背景更改为 egBrushes.Green而不是Brushes.Transparent,它会正确呈现,如参与者所见: 具有绿色背景的子窗口渲染良好

很明显,在传输透明子窗口的捕获时存在问题。

使用
C#、WPF、.NET Framework 4.8 的技术(尚未测试是否在其他目标框架(例如 .NET Core)上出现相同的问题,但不能选择更改目标框架)。

重现问题的最小示例代码
MainWindow.xaml

<Window x:Class="MyApp.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"
        mc:Ignorable="d"
        Title="MainWindow" Height="600" Width="600"
        Background="LightBlue"
        WindowStartupLocation="CenterScreen">
    <Grid Height="500" Width="500" Background="CornflowerBlue" />
</Window>

MainWindow.xaml.cs

using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;

namespace MyApp
{
    public partial class MainWindow
    {
        public MainWindow()
        {
            InitializeComponent();
            ContentRendered += delegate { CreateChildWindow(); };
        }

        private void CreateChildWindow()
        {
            var childWindow = new Window
            {
                WindowStyle = WindowStyle.None,
                AllowsTransparency = true,
                Background = Brushes.Transparent,
                WindowStartupLocation = WindowStartupLocation.CenterScreen,
                Height = 400,
                Width = 400,
                ShowInTaskbar = false,
                Content = new Grid {Background = Brushes.Red, Height = 100, Width = 100},
                Owner = this
            };

            childWindow.Show();
        }
    }
}

约束

我尝试过的事情无济于事

坦率地说,我对如何解决这个问题有点茫然。可能主要是因为我不明白为什么会出现这个问题。我搜索了互联网,没有发现有类似问题的人。我希望有人能阐明一点——如果不是解决方案,那么至少是为什么会出现问题。

标签: .netwpfwindowspinvokemicrosoft-teams

解决方案


推荐阅读