C# - WPF 在“桌面”上最顶层

问题描述 投票:0回答:1

如果其他桌面程序正在运行,则桌面上的 WPF 应用程序不会显示。 (例如壁纸引擎)

[DllImport("User32.dll")]
static extern IntPtr SetParent(IntPtr hWnd, IntPtr hParent);
[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
static extern IntPtr FindWindow(string lpClassName, string lpWindowName);

protected override Window CreateShell()
{
    var mainWindow = Container.Resolve<Main>();
    mainWindow.Loaded += (sender, args) =>
    {
        IntPtr hWnd = new WindowInteropHelper(mainWindow).Handle;
        IntPtr hWndProgMan = FindWindow("Progman", "Program Manager");
        SetParent(hWnd, hWndProgMan);
    };
    return mainWindow;
}

我希望它能使我的应用程序位于桌面的最顶部。

c# wpf winapi prism
1个回答
-1
投票

在您的 xaml 中添加停用事件

<Window x:Class="Sample.MainView"
        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:Sample"
        mc:Ignorable="d" Deactivated="Window_Deactivated"
        :
        :
</Window>

在活动正文中:

    public void Window_Deactivated(object sender, EventArgs e)
    {
        Window window = (Window)sender;
        window.Topmost = true;
    }

应该做的工作....

© www.soinside.com 2019 - 2024. All rights reserved.