{"id":3281,"date":"2009-12-25T17:16:45","date_gmt":"2009-12-25T17:16:45","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/powershell\/2009\/12\/25\/a-christmas-tree-in-wpk\/"},"modified":"2019-02-18T13:06:04","modified_gmt":"2019-02-18T20:06:04","slug":"a-christmas-tree-in-wpk","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/powershell\/a-christmas-tree-in-wpk\/","title":{"rendered":"A Christmas Tree in WPK"},"content":{"rendered":"<p>Merry Christmas.&#160; To celebrate the holiday, here\u2019s a quick Christmas tree written in WPK (the WPF PowerShell Kit).&#160; You can get WPK as part of the PowerShellPack (<a href=\"http:\/\/code.msdn.microsoft.com\/PowerShellPack\">http:\/\/code.msdn.microsoft.com\/PowerShellPack<\/a>).<\/p>\n<p>Here\u2019s a screenshot:<\/p>\n<p><a href=\"https:\/\/msdnshared.blob.core.windows.net\/media\/TNBlogsFS\/BlogFileStorage\/blogs_msdn\/powershell\/WindowsLiveWriter\/AChristmasTreeinWPK_F2FB\/XmasTree.png\"><img decoding=\"async\" style=\"border-right-width: 0px;border-top-width: 0px;border-bottom-width: 0px;border-left-width: 0px\" title=\"XmasTree\" border=\"0\" alt=\"XmasTree\" src=\"https:\/\/msdnshared.blob.core.windows.net\/media\/TNBlogsFS\/BlogFileStorage\/blogs_msdn\/powershell\/WindowsLiveWriter\/AChristmasTreeinWPK_F2FB\/XmasTree_thumb.png\" width=\"195\" height=\"217\" \/><\/a> <\/p>\n<p>and Here\u2019s the script:<\/p>\n<pre class=\"PowerShellColorizedScript\"><span style=\"color: #0000ff\">Import-Module<\/span> <span style=\"color: #8a2be2\">WPK<\/span>\n<span style=\"color: #0000ff\">New-Polygon<\/span> <span style=\"color: #000080\">-Points<\/span> <span style=\"color: #000000\">{<\/span>\n    <span style=\"color: #006400\"># Start from the top<\/span>\n    <span style=\"color: #8b0000\">&quot;87.5,0&quot;<\/span>\n    <span style=\"color: #006400\"># Left Side of Tree<\/span>\n    <span style=\"color: #8b0000\">&quot;0,150&quot;<\/span>\n    <span style=\"color: #8b0000\">&quot;75,140&quot;<\/span>\n    <span style=\"color: #006400\"># Bottom of Tree<\/span>\n    <span style=\"color: #8b0000\">&quot;75,175&quot;<\/span>\n    <span style=\"color: #8b0000\">&quot;95,175&quot;<\/span>\n    <span style=\"color: #006400\"># Right Side of Tree<\/span>\n    <span style=\"color: #8b0000\">&quot;95,140&quot;<\/span>\n    <span style=\"color: #8b0000\">&quot;175,150&quot;<\/span>\n    <span style=\"color: #006400\"># Back to the top<\/span>\n    <span style=\"color: #8b0000\">&quot;87.5,0&quot;<\/span>\n<span style=\"color: #000000\">}<\/span> <span style=\"color: #000080\">-On_SizeChanged<\/span> <span style=\"color: #000000\">{<\/span>\n    <span style=\"color: #00008b\">if<\/span> <span style=\"color: #000000\">(<\/span><span style=\"color: #ff4500\">$_<\/span><span style=\"color: #a9a9a9\">.<\/span><span style=\"color: #000000\">PreviousSize<\/span><span style=\"color: #a9a9a9\">.<\/span><span style=\"color: #000000\">Width<\/span> <span style=\"color: #a9a9a9\">-eq<\/span> <span style=\"color: #800080\">0<\/span> <span style=\"color: #a9a9a9\">-and<\/span>\n        <span style=\"color: #ff4500\">$_<\/span><span style=\"color: #a9a9a9\">.<\/span><span style=\"color: #000000\">PreviousSize<\/span><span style=\"color: #a9a9a9\">.<\/span><span style=\"color: #000000\">Height<\/span> <span style=\"color: #a9a9a9\">-eq<\/span> <span style=\"color: #800080\">0<\/span><span style=\"color: #000000\">)<\/span> <span style=\"color: #000000\">{<\/span>\n        <span style=\"color: #ff4500\">$this<\/span><span style=\"color: #a9a9a9\">.<\/span><span style=\"color: #000000\">Resources<\/span><span style=\"color: #a9a9a9\">.<\/span><span style=\"color: #000000\">OriginalSize<\/span> <span style=\"color: #a9a9a9\">=<\/span> <span style=\"color: #ff4500\">$_<\/span><span style=\"color: #a9a9a9\">.<\/span><span style=\"color: #000000\">NewSize<\/span>\n    <span style=\"color: #000000\">}<\/span> <span style=\"color: #00008b\">else<\/span> <span style=\"color: #000000\">{<\/span>\n        <span style=\"color: #ff4500\">$originalSize<\/span> <span style=\"color: #a9a9a9\">=<\/span> <span style=\"color: #ff4500\">$this<\/span><span style=\"color: #a9a9a9\">.<\/span><span style=\"color: #000000\">Resources<\/span><span style=\"color: #a9a9a9\">.<\/span><span style=\"color: #000000\">OriginalSize<\/span>\n        <span style=\"color: #ff4500\">$ScaleX<\/span> <span style=\"color: #a9a9a9\">=<\/span> <span style=\"color: #ff4500\">$_<\/span><span style=\"color: #a9a9a9\">.<\/span><span style=\"color: #000000\">NewSize<\/span><span style=\"color: #a9a9a9\">.<\/span><span style=\"color: #000000\">Width<\/span>  <span style=\"color: #a9a9a9\">\/<\/span><span style=\"color: #ff4500\">$originalSize<\/span><span style=\"color: #a9a9a9\">.<\/span><span style=\"color: #000000\">Width<\/span>\n        <span style=\"color: #ff4500\">$ScaleY<\/span> <span style=\"color: #a9a9a9\">=<\/span> <span style=\"color: #ff4500\">$_<\/span><span style=\"color: #a9a9a9\">.<\/span><span style=\"color: #000000\">NewSize<\/span><span style=\"color: #a9a9a9\">.<\/span><span style=\"color: #000000\">Height<\/span> <span style=\"color: #a9a9a9\">\/<\/span> <span style=\"color: #ff4500\">$originalSize<\/span><span style=\"color: #a9a9a9\">.<\/span><span style=\"color: #000000\">Height<\/span>\n        <span style=\"color: #ff4500\">$this<\/span><span style=\"color: #a9a9a9\">.<\/span><span style=\"color: #000000\">RenderTransform<\/span> <span style=\"color: #a9a9a9\">=<\/span> <span style=\"color: #0000ff\">New-ScaleTransform<\/span> <span style=\"color: #000080\">-ScaleX<\/span> <span style=\"color: #ff4500\">$ScaleX<\/span> <span style=\"color: #000080\">-ScaleY<\/span> <span style=\"color: #ff4500\">$ScaleY<\/span>\n    <span style=\"color: #000000\">}<\/span>\n<span style=\"color: #000000\">}<\/span> <span style=\"color: #000080\">-BitmapEffect<\/span> <span style=\"color: #000000\">{<\/span>\n    <span style=\"color: #0000ff\">New-BevelBitmapEffect<\/span> <span style=\"color: #000080\">-BevelWidth<\/span> <span style=\"color: #800080\">1<\/span>\n<span style=\"color: #000000\">}<\/span> <span style=\"color: #000080\">-Fill<\/span> <span style=\"color: #8a2be2\">DarkGreen<\/span> <span style=\"color: #000080\">-AsJob<\/span>                                    <\/pre>\n<p>It\u2019s only about 30 lines, but this script has tons of Christmas goodies.&#160; 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.<\/p>\n<p>Hope this Helps,<\/p>\n<p>James<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Merry Christmas.&#160; To celebrate the holiday, here\u2019s a quick Christmas tree written in WPK (the WPF PowerShell Kit).&#160; You can get WPK as part of the PowerShellPack (http:\/\/code.msdn.microsoft.com\/PowerShellPack). Here\u2019s a screenshot: and Here\u2019s the script: Import-Module WPK New-Polygon -Points { # Start from the top &quot;87.5,0&quot; # Left Side of Tree &quot;0,150&quot; &quot;75,140&quot; # Bottom [&hellip;]<\/p>\n","protected":false},"author":600,"featured_media":13641,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[270,275,361],"class_list":["post-3281","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-powershell","tag-powershell-v2","tag-powershellpack","tag-wpk"],"acf":[],"blog_post_summary":"<p>Merry Christmas.&#160; To celebrate the holiday, here\u2019s a quick Christmas tree written in WPK (the WPF PowerShell Kit).&#160; You can get WPK as part of the PowerShellPack (http:\/\/code.msdn.microsoft.com\/PowerShellPack). Here\u2019s a screenshot: and Here\u2019s the script: Import-Module WPK New-Polygon -Points { # Start from the top &quot;87.5,0&quot; # Left Side of Tree &quot;0,150&quot; &quot;75,140&quot; # Bottom [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/posts\/3281","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/users\/600"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/comments?post=3281"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/posts\/3281\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/media\/13641"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/media?parent=3281"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/categories?post=3281"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/tags?post=3281"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}