PowerShell中调用WPF生成炫酷窗口实例

 更新时间:2015年03月26日 09:06:47   投稿:junjie  
这篇文章主要介绍了PowerShell中调用WPF生成炫酷窗口实例,本文直接给出运行效果和脚本源码,需要的朋友可以参考下

怎样在PowerShell中调用WPF,你知道,我也知道;怎样在PowerShell中将很长的.NET类型名称缩短成别名,你知道,我也知道。但是怎样将这两个知识点融汇贯通,写出一个优雅的DEMO,并且让你一眼就能看出,这就是WPF,不是别的,也许你以前就知道,而我直到今天才知道,有种相见恨晚的感觉。

先看一下炫酷的效果吧!

PowerShell之WPF炫酷

# Plik: 4_Demo_v3_Reflection.ps1
#requires -version 3
 
$Akceleratory =
  [PSObject].
  Assembly.
  GetType("System.Management.Automation.TypeAccelerators")
 
Add-Type -AssemblyName PresentationCore, PresentationFramework -PassThru |
  Where-Object IsPublic |
  ForEach-Object {
    $Class = $_
    try {
      $Akceleratory::Add($Class.Name,$Class)
    } catch {
      "Failed to add $($Class.Name) accelerator pointing to $($Class.FullName)"
    }
  }
 
[Window]@{
  OpacityMask = [DrawingBrush]@{
    Drawing = [DrawingGroup]@{
      Children = & {
        $Kolekcja = New-Object DrawingCollection
        $Kolekcja.Add([GeometryDrawing]@{
          Brush = 'Black'
          Geometry = [EllipseGeometry]@{
            radiusX = 0.48
            radiusY = 0.48
            Center = '0.5,0.5'
          }
        })
        $Kolekcja.Add([GeometryDrawing]@{
          Brush = 'Transparent'
          Geometry = [RectangleGeometry]@{
            Rect = '0,0,1,1'
          }
        })
        , $Kolekcja
      }
    }
  }
  Background = [LinearGradientBrush]@{
    Opacity = 0.5
    StartPoint = '0,0.5'
    Endpoint = '1,0.5'
    GradientStops = & {
      $Stopki = New-Object GradientStopCollection
      $Colors = 'Blue', 'Green'
        foreach ($i in 0..1) {
        $Stopki.Add(
          [GradientStop]@{
            Color = $Colors[$i]
            Offset = $i
          }
        )
      }
      , $Stopki
    }      
  }
  Width = 800
  Height = 400
  WindowStyle = 'None'
  AllowsTransparency = $true
  Effect = [DropShadowEffect]@{
    BlurRadius = 10
  }
  TopMost = $true
  Content = & {
    $Stos = [StackPanel]@{
      VerticalAlignment = 'Center'
      HorizontalAlignment = 'Center'
    }
 
    $Stos.AddChild(
      [Label]@{
        Content = 'PowerShell Rocks!'
        FontSize = 80
        FontFamily = 'Consolas'
        Foreground = 'White'
        Effect = [DropShadowEffect]@{
          BlurRadius = 5
        }
      }
    )
    , $Stos
  }
} | ForEach-Object {
  $_.Add_MouseLeftButtonDown({
    $this.DragMove()
  })
  $_.Add_MouseRightButtonDown({
    $this.Close()
  })
  $_.ShowDialog() | Out-Null
}


相关文章

  • 简单谈谈PowerShell 4.0中的新命令

    简单谈谈PowerShell 4.0中的新命令

    powershell 4.0都出来那么长时间了,相对于powershell 3.0,它的命令都改变了哪些,有哪些更新呢?下面我们就来详细谈谈其中的10个新命令
    2015-09-09
  • PowerShell中的加法运算详解

    PowerShell中的加法运算详解

    这篇文章主要介绍了PowerShell中的加法运算详解的相关资料,需要的朋友可以参考下
    2015-09-09
  • PowerShell小技巧之尝试ssh登录

    PowerShell小技巧之尝试ssh登录

    由于Linux登录大多是通过SSH的模式进行登录的,渗透测试时扫描到22端口监听有SSH,如果能有脚本可以基于字典对Linux进行用户名和密码的尝试,将会在渗透测试时起到很重要的作用。本文中将会向大家介绍如何通过PowerShell尝试Linux SSH登录。
    2014-10-10
  • Powershell中调用邮件客户端发送邮件的例子

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

    这篇文章主要介绍了Powershell中调用邮件客户端发送邮件的例子,需要的朋友可以参考下
    2014-05-05
  • 通过DNS TXT记录执行powershell

    通过DNS TXT记录执行powershell

    这篇文章主要介绍了通过DNS TXT记录执行powershell的相关资料,以及nishang的脚本使用,需要的朋友可以参考下
    2017-10-10
  • PowerShell 语音计算器实现代码

    PowerShell 语音计算器实现代码

    带中文发音功能的计算器程序,支持鼠标和小键盘输入,支持多种数值转人民币的相关资料
    2017-10-10
  • 了解Powershell中的Exit函数

    了解Powershell中的Exit函数

    这篇文章主要介绍了了解Powershell中的Exit函数,对exit的函数使用技巧上做了小结,并用实例说明了exit函数的使用,需要的朋友可以参考下
    2014-07-07
  • PowerShell中使用Get-ChildItem命令读取目录、文件列表使用例子和小技巧

    PowerShell中使用Get-ChildItem命令读取目录、文件列表使用例子和小技巧

    这篇文章主要介绍了PowerShell中使用Get-ChildItem命令读取目录、文件列表使用例子和小技巧,比如只读取目录列表的方法,只读取文件列表的方法,需要的朋友可以参考下
    2014-08-08
  • Windows Powershell 访问数组

    Windows Powershell 访问数组

    本文主要讲诉了windows powershell 从数组中选择多个元素,将数组逆序输出,给数组添加和删除元素,希望对大家理解powershell能有所帮助
    2014-09-09
  • Powershell小技巧之获取字符串的行数

    Powershell小技巧之获取字符串的行数

    这篇文章主要介绍了Powershell获取字符串的行数的小技巧,只要懂得了它的工作原理就能在多种场合使用。需要的朋友可以参考下
    2014-09-09

最新评论