A Christmas Tree in WPK

  • Comments 4

Merry Christmas.  To celebrate the holiday, here’s a quick Christmas tree written in WPK (the WPF PowerShell Kit).  You can get WPK as part of the PowerShellPack (http://code.msdn.microsoft.com/PowerShellPack).

Here’s a screenshot:


and Here’s the script:

Import-Module WPK            
New-Polygon -Points {            
    # Start from the top            
    # Left Side of Tree            
    # Bottom of Tree            
    # Right Side of Tree            
    # Back to the top            
} -On_SizeChanged {            
    if ($_.PreviousSize.Width -eq 0 -and            
        $_.PreviousSize.Height -eq 0) {            
        $this.Resources.OriginalSize = $_.NewSize            
    } else {            
        $originalSize = $this.Resources.OriginalSize            
        $ScaleX = $_.NewSize.Width  /$originalSize.Width             
        $ScaleY = $_.NewSize.Height / $originalSize.Height             
        $this.RenderTransform = New-ScaleTransform -ScaleX $ScaleX -ScaleY $ScaleY            
} -BitmapEffect {             
    New-BevelBitmapEffect -BevelWidth 1            
} -Fill DarkGreen -AsJob                                    

It’s only about 30 lines, but this script has tons of Christmas goodies.  It shows an example of how to create any random polygon with a simple list of points, how to resize that polygon to whatever size the control need to be, and how to apply a quick bitmap effect to an image.

Hope this Helps,


Leave a Comment
  • Please add 8 and 6 and type the answer here:
  • Post
  • curse you, James!  Now I'll always see my mouse cursor as a white Christmas tree that's leaning to the left.

    Speaking of which, add a drop shadow! :)

  • James

    Does this EVER help !  NOW I'm getting a bad desire to do WPK.  I feel so... so... so NON ItPro.  I feel "DEVilish".

    I feel I am crossing to ... "The Dark Side"...

    Mmmm.... coookies :)

  • Hey guy's ..... happy christmas to all, I am celabraiting with my family, I am so happy about it, Marry christmas to all..............!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

  • Merry Christmas to you all from me.

Page 1 of 1 (4 items)

A Christmas Tree in WPK