让窗口回到顶部

时间:2017-06-07 09:34:12

标签: powershell xaml user-interface

我使用基于XAML的GUI启动了一个新项目,但我遇到了问题。当我打开另一个窗口,消息框甚至调用Get-Credential时,主窗口会在后台消失(在所有其他打开的窗口后面)。

是否有一种简单的方法可以让窗户重回顶部? 我找到了许多Get-Process等解决方案,但这对于这个简单的问题似乎很复杂。

1 个答案:

答案 0 :(得分:0)

也可能太复杂了...... 尽管如此,使用SetWindowsPos function

$User32 = Add-Type -Debug:$False -MemberDefinition '
    [DllImport("user32.dll")] public static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int X,int Y, int cx, int cy, uint uFlags);
' -Name "User32Functions" -namespace User32Functions -PassThru 

$Xaml = ...
$Window = [Windows.Markup.XamlReader]::Load((New-Object System.Xml.XmlNodeReader($Xaml)))
$Handle = (New-Object System.Windows.Interop.WindowInteropHelper($Window)).Handle

[Void]$User32::SetWindowPos($Handle, -1, 0, 0, 0, 0, 0x53)
相关问题