Powershell使用WPF技术实现弹窗提示实例

所属分类: 脚本专栏 / PowerShell 阅读数: 1413
收藏 0 赞 0 分享

WPF (Windows Presentation Foundation) 技术能让你创建窗口和对话框。它的优势是在窗体设计时能与代码分开。

这里有个简单的显示弹出消息练习。这个消息是定义在XAML代码中它的实现类似HTML(但是请区分大小写)。你能轻松的调整字体大小,内容,颜色等等。不需要嵌入任何代码。

复制代码 代码如下:

$xaml = @"
<Window
 xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation'>

 <Border BorderThickness="20" BorderBrush="Yellow" CornerRadius="9" Background='Red'>
  <StackPanel>
   <Label FontSize="50" FontFamily='Stencil' Background='Red' Foreground='White' BorderThickness='0'>
    System will be rebooted in 15 minutes!
   </Label>

   <Label HorizontalAlignment="Center" FontSize="15" FontFamily='Consolas' Background='Red' Foreground='White' BorderThickness='0'>
    Worried about losing data? Talk to your friendly help desk representative and freely share your concerns!
   </Label>
  </StackPanel>
 </Border>
</Window>
"@

$reader = [System.XML.XMLReader]::Create([System.IO.StringReader] $xaml)
$window = [System.Windows.Markup.XAMLReader]::Load($reader)
$Window.AllowsTransparency = $True
$window.SizeToContent = 'WidthAndHeight'
$window.ResizeMode = 'NoResize'
$Window.Opacity = .7
$window.Topmost = $true
$window.WindowStartupLocation = 'CenterScreen'
$window.WindowStyle = 'None'
# show message for 5 seconds:
$null = $window.Show()
Start-Sleep -Seconds 5
$window.Close()

更多精彩内容其他人还在看

Powershell中调用邮件客户端发送邮件的例子

这篇文章主要介绍了Powershell中调用邮件客户端发送邮件的例子,需要的朋友可以参考下
收藏 0 赞 0 分享

PowerShell注册表操作命令总结

这篇文章主要介绍了PowerShell注册表操作命令总结,对访问注册表所需的所有命令做了一简要描述,需要的朋友可以参考下
收藏 0 赞 0 分享

Powershell使用WPF技术实现弹窗提示实例

这篇文章主要介绍了Powershell使用WPF技术实现弹窗提示实例,需要的朋友可以参考下
收藏 0 赞 0 分享

PowerShell中运行CMD命令的技巧总结(解决名称冲突和特殊字符等问题)

这篇文章主要介绍了PowerShell中运行CMD命令的技巧总结(解决名称冲突和特殊字符等问题),需要的朋友可以参考下
收藏 0 赞 0 分享

powershell操作word详解

这篇文章主要介绍了powershell操作word示例,需要的朋友可以参考下
收藏 0 赞 0 分享

PowerShell脚本性能优化技巧总结

这篇文章主要介绍了PowerShell脚本性能优化技巧总结,一些PowerShell脚本可能很容易消耗很多内存,或者运行太多时间,甚至兼而有之,本文会分享几个PowerShell小技巧来提高这一类脚本的性能,需要的朋友可以参考下
收藏 0 赞 0 分享

PowerShell把文件删除到回收站的方法

这篇文章主要介绍了PowerShell把文件删除到回收站的方法,需要的朋友可以参考下
收藏 0 赞 0 分享

Powershell批量给文件增加前辍实例

这篇文章主要介绍了Powershell批量给文件增加前辍实例,即Powershell批量修改文件名,文件名中统一设定一个带数字的前辍,需要的朋友可以参考下
收藏 0 赞 0 分享

PowerShell默认参数$PSDefaultParameterValues结合Out-File输出到日志文件

这篇文章主要介绍了PowerShell默认参数$PSDefaultParameterValues结合Out-File输出到日志文件实例,需要的朋友可以参考下
收藏 0 赞 0 分享

了解Powershell中的Exit函数

这篇文章主要介绍了了解Powershell中的Exit函数,对exit的函数使用技巧上做了小结,并用实例说明了exit函数的使用,需要的朋友可以参考下
收藏 0 赞 0 分享
查看更多