当前位置: 代码网 > it编程>前端脚本>Powershell > PowerShell中调用WPF生成炫酷窗口实例

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

2024年05月19日 Powershell 我要评论
怎样在powershell中调用wpf,你知道,我也知道;怎样在powershell中将很长的.net类型名称缩短成别名,你知道,我也知道。但是怎样将这两个知识点融汇贯通,写出一个优雅的demo,并且

怎样在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
}


(0)

相关文章:

版权声明:本文内容由互联网用户贡献,该文观点仅代表作者本人。本站仅提供信息存储服务,不拥有所有权,不承担相关法律责任。 如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 2386932994@qq.com 举报,一经查实将立刻删除。

发表评论

验证码:
Copyright © 2017-2025  代码网 保留所有权利. 粤ICP备2024248653号
站长QQ:2386932994 | 联系邮箱:2386932994@qq.com