Powershell演示WPF弹窗

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

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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
$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>
"@
Add-Type -assemblyName PresentationFramework
$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()

原文地址:Showing WPF Info Message

PowerShell 是一个由微软开发的任务自动化和配置管理框架,它包含了交互式命令行shell和脚本语言。在PowerShell演示设置命令行,通常涉及到自定义提示符、设置环境变量、配置执行策略以及其他一些与环境相关的配置。下面将介绍几个演示设置命令行的基本操作: 1. 自定义提示符:可以通过更改`$Host.UI.RawUI.WindowTitle`属性来自定义PowerShell窗口的标题。 ```powershell $Host.UI.RawUI.WindowTitle = "自定义PowerShell窗口标题" ``` 2. 设置环境变量:可以使用`[System.Environment]::SetEnvironmentVariable()`方法来设置环境变量。 ```powershell [System.Environment]::SetEnvironmentVariable("MY_VAR", "HelloWorld", "User") ``` 3. 配置执行策略:为了执行脚本,可能需要配置PowerShell的执行策略。在企业环境中,需要管理员权限才能更改执行策略。 ```powershell Set-ExecutionPolicy RemoteSigned ``` 这条命令设置了PowerShell的执行策略为RemoteSigned,意味着只允许运行本地脚本和已签名的远程脚本。 4. 显示当前日期和时间:可以使用以下命令在提示符中显示当前日期和时间。 ```powershell function prompt { Write-Host "[$(Get-Date -Format 'yyyy-MM-dd HH:mm:ss')] " -ForegroundColor Green -NoNewline return "> " } ``` 这样每次打开新的命令行窗口时,都会显示当前的时间。 5. 简化命令行:可以在用户的PowerShell配置文件`$PROFILE`中添加一些简写或者别名来简化常用命令。 ```powershell Set-Alias -Name ll -Value Get-ChildItem ``` 这样就可以使用`ll`来代替`Get-ChildItem`命令列当前目录的内容。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值