Last active
September 12, 2022 10:52
-
-
Save potatoqualitee/b9faf8c706d6d14e068e to your computer and use it in GitHub Desktop.
PowerShell WPF popup in lower right corner of the screen
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[xml]$xaml = '<Window | |
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | |
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | |
WindowStyle="None" ResizeMode="NoResize" ShowInTaskbar="False" | |
Height="0" Width="0" Background="Transparent"> | |
<Popup Name="popup" Placement="AbsolutePoint" StaysOpen="False"> | |
<Grid Name="grid" Height="400" Width="390" Background="DarkGray"> | |
<Label Name="label" Content="Double-click to close" Foreground="White" FontSize="18"/> | |
</Grid> | |
</Popup> | |
</Window>' | |
try { Add-Type -AssemblyName PresentationFramework,System.Windows.Forms} | |
catch { throw "Failed to load Windows Presentation Framework assemblies." } | |
$script:form = [Windows.Markup.XamlReader]::Load((New-Object System.Xml.XmlNodeReader $xaml)) | |
$xaml.SelectNodes("//*[@Name]") | ForEach-Object { Set-Variable -Name ($_.Name) -Value $form.FindName($_.Name) -Scope Script } | |
$screen = [Windows.Forms.Screen]::PrimaryScreen.WorkingArea | |
$popup.VerticalOffset=$screen.height | |
$popup.HorizontalOffset=$screen.width | |
$popup.Add_Loaded({$popup.IsOpen=$true}) | |
$form.Add_MouseDoubleClick({ | |
$popup.IsOpen = $false | |
[void]$form.Close() | |
}) | |
[void]$form.ShowDialog() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment