Skip to content

Instantly share code, notes, and snippets.

@potatoqualitee
Last active September 12, 2022 10:52
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save potatoqualitee/b9faf8c706d6d14e068e to your computer and use it in GitHub Desktop.
Save potatoqualitee/b9faf8c706d6d14e068e to your computer and use it in GitHub Desktop.
PowerShell WPF popup in lower right corner of the screen
[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