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

所属分类: 脚本专栏 / PowerShell 阅读数: 1424
收藏 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交互式运行环境的几个小技巧

这篇文章主要介绍了PowerShell入门教程之高效使用PowerShell交互式运行环境的几个小技巧,本文也可以说是使用PowerShell的一些好习惯,需要的朋友可以参考下
收藏 0 赞 0 分享

PowerShell入门教程之Cmd命令与PowerShell命令相互调用的方法

这篇文章主要介绍了PowerShell入门教程之Cmd命令与PowerShell命令相互调用的方法,本文讲解了在Cmd命令中调用PowerShell命令、在PowerShell命令中调用Cmd命令的方法,需要的朋友可以参考下
收藏 0 赞 0 分享

PowerShell入门教程之远程操作运行PowerShell的方法

这篇文章主要介绍了PowerShell入门教程之远程操作运行PowerShell的方法,本文讲解了配置远程基础结构、执行远程操作等内容,需要的朋友可以参考下
收藏 0 赞 0 分享

PowerShell入门教程之PowerShell管道介绍

这篇文章主要介绍了PowerShell入门教程之PowerShell管道介绍,本文讲解了管道的作用,并列出了几个使用实例,需要的朋友可以参考下
收藏 0 赞 0 分享

PowerShell入门教程之函数、脚本、作用域介绍

这篇文章主要介绍了PowerShell入门教程之函数、脚本、作用域介绍,本文所讲内容都是PowerShell的基础知识,需要的朋友可以参考下
收藏 0 赞 0 分享

PowerShell入门教程之访问.Net程序集、COM和WMI实例

这篇文章主要介绍了PowerShell入门教程之访问.Net程序集、COM和WMI实例,本文讲解了PowerShell作为Windows平台的脱水语言来访问其它资源的例子,需要的朋友可以参考下
收藏 0 赞 0 分享

PowerShell入门教程之创建和使用配置文件实例

这篇文章主要介绍了PowerShell入门教程之创建和使用配置文件实例,PowerShell的配置文件都是些普通的PowerShell脚本文件,需要的朋友可以参考下
收藏 0 赞 0 分享

PowerShell入门教程之编写和使用脚本模块实例

这篇文章主要介绍了PowerShell入门教程之编写和使用脚本模块实例,本文讲解了模块、脚本模块、编写脚本模块、模块安装路径、模块文件夹等内容,需要的朋友可以参考下
收藏 0 赞 0 分享

WMI入门教程之什么是WMI?

这篇文章主要介绍了WMI入门教程之什么是WMI?WMI有一组API,我们可以使用VBScript、PowerShell脚本还是利用C#的来访问WMI的类库,需要的朋友可以参考下
收藏 0 赞 0 分享

WMI入门教程之怎么使用WMI?

这篇文章主要介绍了WMI入门教程之怎么使用WMI?本文讲解了在软件中、PowerShell中、.NET中使用WMI的例子,需要的朋友可以参考下
收藏 0 赞 0 分享
查看更多