【发布时间】:2020-06-07 13:10:12
【问题描述】:
我正在尝试调整this WPF Popup 实现以实现消息传递系统。目标是在我需要发送消息的任何时候弹出窗口,用户可以通过双击消息来关闭弹出窗口,并且消息也会在设定的时间后消失。 我现在拥有的是这个
using assembly PresentationFramework
using assembly System.Windows.Forms
using assembly System.Drawing
$icon = [System.Drawing.Icon]::ExtractAssociatedIcon("$pshome\powershell.exe")
[xml]$xaml = '<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Name="window" WindowStyle="None" Height="200" Width="400"
ResizeMode="NoResize" ShowInTaskbar="False">
<Grid Name="grid" Background="#313130" Height="200" Width="400">
<Label Name="label" Content="Messanger Test" Foreground="White" FontSize="18" Margin="10,10,0,15"/>
<TextBox x:Name="Message" Height = "50" FontSize="18" Margin="10,10,0,15" />
</Grid>
</Window>'
$window = [Windows.Markup.XamlReader]::Load([System.Xml.XmlNodeReader]::New($xaml))
$window.Left = [System.Windows.SystemParameters]::WorkArea.Width-$window.Width
$window.Top = 0
$message = $Window.FindName('Message')
# Close the window if it's double clicked
$window.Add_MouseDoubleClick({
$window.Hide()
})
$messageCount = 1
do {
if ((Get-Random -Minimum:0 -Maximum:100) -le 30) {
$messageString = "($messageCount) $(Get-Date -format 'HH:mm:ss')"
$message.Text = $messageString
Write-Host $messageString
$messageCount ++
$window.Show()
Start-Sleep -s:10
$window.Hide()
}
Start-Sleep -s:5
} while ($messageCount -le 5)
这部分有效,因为第一条消息弹出,10 秒后将隐藏。但是,双击隐藏不起作用,后续显示也不会发生。我知道正在满足标准,因为控制台会显示每条新的时间消息。
所以...
我的MouseDoubleClick 事件有什么问题,以及
什么是在第一次显示后保留消息?
【问题讨论】:
标签: wpf powershell popup