【问题标题】:C# & XAML Popup doesn't show in screenshotC# & XAML 弹出窗口不显示在屏幕截图中
【发布时间】:2015-03-25 08:18:47
【问题描述】:

我在自定义 GUI 应用程序中有许多弹出窗口。这些弹出窗口是窗口对象,而不是弹出窗口对象。使用键盘上的“打印屏幕”按钮时,弹出窗口不会显示在屏幕截图中。相反,下面禁用的主窗口是屏幕截图中显示的所有内容。弹出窗口从不闪烁或消失,只是没有显示在屏幕截图中。

WindowInstance.IsEnabled = true;
WindowInstance.Refresh();
DisplayPopUpWindow(WindowInstance);

DisplayPopupWindow 中的代码:

private void DisplayPopUpWindow(Window theWindow)
{
    if (theWindow != null)
    {
        if (theWindow is MessagePopup)
        {
            // Only show one popup at a time (queue is handled elsewhere)
            RemovePopUpsCommand.Execute(true, null);
        }

        ActiveWindow.IsEnabled = false;  // main screen disabled

        foreach (KeyValuePair<Window, int> aPopup in popUpWindows)
        {
            if ((aPopup.Key.IsVisible) && (aPopup.Key.Opacity == 1) && (aPopup.Key != theWindow))
            {
                // if window is a lower priority then disable it
                if (aPopup.Value > displayPriority)
                    aPopup.Key.IsEnabled = false;
            }
        }
        theWindow.Show();
        theWindow.Opacity = 1;
    }
}

XAML 中是否有某些属性会影响窗口是否对屏幕截图可见?这是一个大问题,因为这也会影响我们使用的一些远程处理软件,因为弹出窗口不会显示在共享屏幕上。也会影响我们的组合框实现。

“弹出窗口”实际上是它们自己的独立窗口。有些实例在应用程序启动期间创建一次,并在需要时简单地显示/隐藏,但是,大多数是按需创建以显示。此问题会影响这两种类型。

使用的remoting软件是axeda access remote。

【问题讨论】:

  • 这是在 WindowsXP 上发生的吗?
  • 见这里:stackoverflow.com/questions/1287373/…。另一种可能是 Alt + Print Screen。
  • 该软件在 Windows XP Embedded 上运行,但我在 Windows 7 中开发时遇到了屏幕截图问题。我有一个程序可以让我进行屏幕截图,但这里更大的问题是远程处理软件。我可以更改 GUI 程序本身,但不能更改远程处理软件。我认为屏幕截图问题的根本原因是相同的,并且可能会导致解决方案。
  • 我之前在XP也遇到过类似的问题(远程桌面没有弹出弹窗),相信你需要为你的Window设置AllowsTransparency="False",你可以试一试。
  • 我相信我们希望窗户透明,它们有圆角,但我会检查一下...

标签: c# wpf xaml c#-4.0 popup


【解决方案1】:

如果我没记错的话,我遇到了同样的问题,我认为这与将弹出窗口父级设置为修复它的主窗口有关,我必须在家里查看我的代码来确认。

所以请确保设置正确。

编辑:

在创建 Window 对象时尝试使用此代码:

MainWindowVariable.Owner = Window.GetWindow(this)

您可以在这里阅读更多内容:

http://msdn.microsoft.com/en-us/library/system.windows.window.owner(v=vs.110).aspx

【讨论】:

  • 我尝试使用[System.Runtime.InteropServices.DllImport("User32.dll")] private static extern int FindWindow(String ClassName, String WindowName); [System.Runtime.InteropServices.DllImport("User32.dll")] private static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndParent); [System.Runtime.InteropServices.DllImport("User32.dll")] private static extern IntPtr GetForegroundWindow();IntPtr popupPtr = new IntPtr(FindWindow(null, theWindow.Name)); IntPtr parentPtr = GetForegroundWindow(); SetParent(popupPtr, parentPtr); 设置父级,结果为空
  • 对不起,太混乱了,不知道如何让我的换行符坚持到帖子中(我使用 shift-return 让它们在那里)
  • 我没有正确获得指向我的窗口的指针,但我解决了这个问题。在将父窗口和子窗口的正确指针传递给 SetParent 后,我​​仍然将父窗口显示为“null”。
  • 如何生成新窗口?你用的是什么远程软件?您在 WPF 应用程序中使用 Prism 吗?用更多细节更新问题。
  • 所有窗口都是在 App.xaml.cs 中创建的。所以“这个”不能用作所有者。我改为使用 App.Current.MainWindow,它设置了所有者。我确认它在显示时仍然有所有者,但这并没有解决问题。 App.Current.MainWindow.Owner 为空,不应该是这样吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2019-03-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-10-11
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多