<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Huddled Masses &#187; WPF</title>
	<atom:link href="http://joelbennett.net/tag/wpf/feed/" rel="self" type="application/rss+xml" />
	<link>http://joelbennett.net</link>
	<description>The internet home of Joel "Jaykul" Bennett...</description>
	<lastBuildDate>Fri, 27 Apr 2012 05:42:40 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
<cloud domain='joelbennett.net' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
		<item>
		<title>The Obligatory ShowUI Clock</title>
		<link>http://joelbennett.net/the-obligatory-showui-clock/</link>
		<comments>http://joelbennett.net/the-obligatory-showui-clock/#comments</comments>
		<pubDate>Tue, 19 Jul 2011 05:44:42 +0000</pubDate>
		<dc:creator>Joel 'Jaykul' Bennett</dc:creator>
				<category><![CDATA[Huddled]]></category>
		<category><![CDATA[Animation]]></category>
		<category><![CDATA[ShowUI]]></category>
		<category><![CDATA[WPF]]></category>

		<guid isPermaLink="false">http://huddledmasses.org/?p=1724</guid>
		<description><![CDATA[Well, it all started when Richard Siddaway posted his PowerShell Clock using raw XAML. Then Doug posted his ShowUI Clock, and after some back and forth on our ShowUI developer mailing list, James Brundage posted a video walkthrough of building his clock &#8230; Now I&#8217;ve dug an old clock of mine out of mothballs and [...]]]></description>
			<content:encoded><![CDATA[	<p>Well, it all started when Richard Siddaway posted his <a href="http://msmvps.com/blogs/richardsiddaway/archive/2011/07/07/a-powershell-clock.aspx">PowerShell Clock</a> using raw <span class="caps">XAML</span>. Then <a href="http://www.dougfinke.com/blog/index.php/2011/07/13/updated-hippy-dippy-powershell-clock-with-showui/">Doug posted his ShowUI Clock</a>, and after some back and forth on our ShowUI developer mailing list,  <a href="http://www.youtube.com/watch?v=Hqn-b2HMgSM">James Brundage posted a video walkthrough of building his clock</a> &#8230;</p>

	<p>Now I&#8217;ve dug an old clock of mine out of mothballs and updated it to run on ShowUI &#8212; I believe that I&#8217;ve never posted this script before, so I don&#8217;t feel bad at all doing so now, even though I actually wrote it last December (hey, look, I have a <a href="http://huddledmasses.org/images/PowerBoots/Gadget-SuperClock.png">screenshot against my bright red Christmas wallpaper to prove it</a> &#8212; totally random, I know).  Anyway, here&#8217;s the deal: this post was supposed to be written 6 months ago, about building fun UI Widgets in PowerShell, but I never got to it, because we started working on the PowerBoots + <span class="caps">WPK</span> merger we call ShowUI.  So here&#8217;s a fun little function for you:</p>

	<div class="posh code posh" style="font-family:monospace;"><br />
<span style="color: #666699; font-weight: bold;">function</span> <span style="color: #0066cc; font-style: italic;">New-<span style="font-style: normal;">UIWidget</span></span> <span style="color: #333;">&#123;</span><br />
<span style="color: #666699; font-weight: bold;">param</span><span style="color: #333;">&#40;</span><br />
&nbsp; &nbsp; <span style="color: #003366; font-weight: bold;"><span style="color: #333;">&#91;</span><span style="color: #003366; font-weight: bold;">ScriptBlock</span><span style="color: #333;">&#93;</span></span><span style="color: #660033; font-weight: bold;">$Content</span>,<br />
&nbsp; &nbsp; <span style="color: #003366; font-weight: bold;"><span style="color: #333;">&#91;</span>TimeSpan<span style="color: #333;">&#93;</span></span><span style="color: #660033; font-weight: bold;">$Interval</span> <span style="color: #66cc66;">=</span> <span style="color: #009900;">&quot;0:0:2&quot;</span>,<br />
&nbsp; &nbsp; <span style="color: #003366; font-weight: bold;"><span style="color: #333;">&#91;</span><span style="color: #003366; font-weight: bold;">ScriptBlock</span><span style="color: #333;">&#93;</span></span><span style="color: #660033; font-weight: bold;">$UpdateBlock</span>,<br />
&nbsp; &nbsp; <span style="color: #003366; font-weight: bold;"><span style="color: #333;">&#91;</span><span style="color: #666699; font-weight: bold;">Switch</span><span style="color: #333;">&#93;</span></span><span style="color: #660033; font-weight: bold;">$Show</span>, <span style="color: #003366; font-weight: bold;"><span style="color: #333;">&#91;</span><span style="color: #666699; font-weight: bold;">Switch</span><span style="color: #333;">&#93;</span></span><span style="color: #660033; font-weight: bold;">$AsJob</span><br />
<span style="color: #333;">&#41;</span><br />
<br />
<span style="color: #660033; font-weight: bold;">$WidgetValues</span> <span style="color: #66cc66;">=</span> @<span style="color: #333;">&#123;</span> <br />
&nbsp; &nbsp; AllowsTransparency <span style="color: #66cc66;">=</span> <span style="color: #660033; font-weight: bold;">$true</span><br />
&nbsp; &nbsp; WindowStyle <span style="color: #66cc66;">=</span> <span style="color: #009900;">&quot;None&quot;</span> <br />
&nbsp; &nbsp; ShowInTaskbar <span style="color: #66cc66;">=</span> <span style="color: #660033; font-weight: bold;">$true</span><br />
&nbsp; &nbsp; Background <span style="color: #66cc66;">=</span> <span style="color: #009900;">&quot;Transparent&quot;</span> <br />
&nbsp; &nbsp; On_MouseLeftButtonDown <span style="color: #66cc66;">=</span> <span style="color: #333;">&#123;</span> <span style="color: #660033; font-weight: bold;">$Window</span>.<span style="color: #003366;">DragMove</span><span style="color: #333;">&#40;</span><span style="color: #333;">&#41;</span> <span style="color: #333;">&#125;</span><br />
&nbsp; &nbsp; On_Closing <span style="color: #66cc66;">=</span> <span style="color: #333;">&#123;</span> <span style="color: #660033; font-weight: bold;">$Window</span>.<span style="color: #003366;">Resources</span>.<span style="color: #003366;">Timers</span>.<span style="color: #009900;">&quot;Clock&quot;</span>.<span style="color: #003366;">Stop</span><span style="color: #333;">&#40;</span><span style="color: #333;">&#41;</span> <span style="color: #333;">&#125;</span><br />
&nbsp; &nbsp; Tag <span style="color: #66cc66;">=</span> <span style="color: #660033; font-weight: bold;">$UpdateBlock</span>,<span style="color: #660033; font-weight: bold;">$Interval</span><br />
&nbsp; &nbsp; SizeToContent <span style="color: #66cc66;">=</span> <span style="color: #009900;">&quot;WidthAndHeight&quot;</span><br />
&nbsp; &nbsp; ResizeMode <span style="color: #66cc66;">=</span> <span style="color: #009900;">&quot;NoResize&quot;</span><br />
&nbsp; &nbsp; On_SourceInitialized <span style="color: #66cc66;">=</span> <span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #660033; font-weight: bold;">$Window</span>.<span style="color: #003366;">Resources</span>.<span style="color: #003366;">Timers</span>.<span style="color: #009900;">&quot;Clock&quot;</span> <span style="color: #66cc66;">=</span> <span style="color: #333;">&#40;</span><span style="color: #0066cc; font-style: italic;">New-<span style="font-style: normal;">Object</span></span> Windows.<span style="color: #003366;">Threading</span>.<span style="color: #003366;">DispatcherTimer</span><span style="color: #333;">&#41;</span>.<span style="color: #003366; font-weight: bold;">PSObject</span>.<span style="color: #003366;">BaseObject</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #660033; font-weight: bold;">$Window</span>.<span style="color: #003366;">Resources</span>.<span style="color: #003366;">Timers</span>.<span style="color: #009900;">&quot;Clock&quot;</span>.<span style="color: #003366;">Interval</span> <span style="color: #66cc66;">=</span> <span style="color: #660033; font-weight: bold;">$Window</span>.<span style="color: #003366;">Tag</span><span style="color: #333;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #333;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #660033; font-weight: bold;">$Window</span>.<span style="color: #003366;">Resources</span>.<span style="color: #003366;">Timers</span>.<span style="color: #009900;">&quot;Clock&quot;</span>.<span style="color: #003366;">Add_Tick</span><span style="color: #333;">&#40;</span> <span style="color: #660033; font-weight: bold;">$Window</span>.<span style="color: #003366;">Tag</span><span style="color: #333;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #333;">&#93;</span> <span style="color: #333;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #660033; font-weight: bold;">$Window</span>.<span style="color: #003366;">Resources</span>.<span style="color: #003366;">Timers</span>.<span style="color: #009900;">&quot;Clock&quot;</span>.<span style="color: #003366;">Tag</span> <span style="color: #66cc66;">=</span> <span style="color: #660033; font-weight: bold;">$Window</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #660033; font-weight: bold;">$Window</span>.<span style="color: #003366;">Resources</span>.<span style="color: #003366;">Timers</span>.<span style="color: #009900;">&quot;Clock&quot;</span>.<span style="color: #660033;">Start</span><span style="color: #333;">&#40;</span><span style="color: #333;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #660033; font-weight: bold;">$Window</span>.<span style="color: #003366;">Tag</span> <span style="color: #66cc66;">=</span> <span style="color: #660033; font-weight: bold;">$Null</span><br />
&nbsp; &nbsp; <span style="color: #333;">&#125;</span><br />
<span style="color: #333;">&#125;</span><br />
<br />
<span style="color: #0066cc; font-style: italic;">New-<span style="font-style: normal;">Window</span></span> @WidgetValues <span style="color: #000066;">-Content</span> <span style="color: #660033; font-weight: bold;">$Content</span> <span style="color: #000066;">-Show</span>:<span style="color: #660033; font-weight: bold;">$Show</span> <span style="color: #000066;">-AsJob</span>:<span style="color: #660033; font-weight: bold;">$AsJob</span><br />
<span style="color: #333;">&#125;</span><br />
&nbsp;</div>

	<p>That script is what I use to create little &#8220;gadget&#8221; style windows that are transparent, don&#8217;t show up on the taskbar, but are draggable, and have an automatic update based on a timer.  Now, this is a <strong>very</strong> simple version of the gadgets, without using our PowerShell &#8220;DataSource&#8221; or any data binding at all.  I intend to update this with more functionality one of these days, but this was enough to make my clock work. You can see that basically all it does is sets a bunch of parameters for the Window, including a <code>SourceInitialized</code> event handler, and all the stuff necessary to make it transparent and draggable.</p>

	<p>Now let me post the New-TargetClock funtion, which <strong>depends</strong> on that function, and we&#8217;ll get to explaining it a bit down below.  First, the screenshot, this is what it looks like (with a PowerShell window behind it, instead of that bright red wallpaper):</p>

	<p><img src="/images/ShowUI/TargetClock.png" alt="" /></p>

	<p>And then the actual function:</p>

	<div class="posh code posh" style="font-family:monospace;"><br />
<span style="color: #666699; font-weight: bold;">function</span> <span style="color: #0066cc; font-style: italic;">New-<span style="font-style: normal;">TargetClock</span></span> <span style="color: #333;">&#123;</span><br />
<span style="color: #666699; font-weight: bold;">param</span><span style="color: #333;">&#40;</span><span style="color: #003366; font-weight: bold;"><span style="color: #333;">&#91;</span><span style="color: #666699; font-weight: bold;">Switch</span><span style="color: #333;">&#93;</span></span><span style="color: #660033; font-weight: bold;">$ShowMarks</span><span style="color: #333;">&#41;</span><br />
<br />
<span style="color: #0066cc; font-style: italic;">New-<span style="font-style: normal;">UIWidget</span></span> <span style="color: #000066;">-AsJob</span> <span style="color: #000066;">-Content</span> <span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp; Grid <span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #660033; font-weight: bold;">$now</span> <span style="color: #66cc66;">=</span> <span style="color: #0066cc; font-style: italic;">Get-<span style="font-style: normal;">Date</span></span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #660033; font-weight: bold;">$Label</span> <span style="color: #66cc66;">=</span> @<span style="color: #333;">&#123;</span>HorizontalAlignment<span style="color: #66cc66;">=</span><span style="color: #009900;">&quot;Center&quot;</span>; VerticalAlignment<span style="color: #66cc66;">=</span><span style="color: #009900;">&quot;Top&quot;</span>;FontSize<span style="color: #66cc66;">=</span><span style="color: #cc66cc;">25</span>;ZIndex<span style="color: #66cc66;">=</span><span style="color: #cc66cc;">1</span><span style="color: #333;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;"># Hours</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; TextBlock <span style="color: #000066;">-Text</span> <span style="color: #660033;">H</span> <span style="color: #000066;">-Margin</span> <span style="color: #009900;">'0,-5,0,0'</span> <span style="color: #000066;">-FontWeight</span> ExtraBold <span style="color: #000066;">-Foreground</span> White @Label<br />
&nbsp; &nbsp; &nbsp; &nbsp; Ellipse <span style="color: #000066;">-Name</span> Hours <span style="color: #000066;">-Ov</span> el <span style="color: #000066;">-Fill</span> Transparent <span style="color: #000066;">-Stroke</span> Black `<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">-StrokeThickness</span> <span style="color: #cc66cc;">100</span> <span style="color: #000066;">-Width</span> <span style="color: #cc66cc;">350</span> <span style="color: #000066;">-Height</span> <span style="color: #cc66cc;">350</span> `<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">-StrokeDashArray</span> &nbsp;<span style="color: #cc66cc;">7.85</span>, <span style="color: #cc66cc;">7.85</span> &nbsp;<span style="color: #000066;">-Opacity</span> <span style="color: #cc66cc;">0.5</span> `<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">-StrokeDashOffset</span> $<span style="color: #333;">&#40;</span><span style="color: #cc66cc;">7.85</span> <span style="color: #66cc66;">-</span> <span style="color: #333;">&#40;</span><span style="color: #cc66cc;">7.85</span> <span style="color: #66cc66;">*</span> <span style="color: #333;">&#40;</span><span style="color: #333;">&#40;</span><span style="color: #333;">&#40;</span><span style="color: #660033; font-weight: bold;">$now</span>.<span style="color: #003366;">Hour</span> <span style="color: #66cc66;">%</span> <span style="color: #cc66cc;">12</span><span style="color: #333;">&#41;</span> <span style="color: #66cc66;">+</span> <span style="color: #333;">&#40;</span><span style="color: #660033; font-weight: bold;">$now</span>.<span style="color: #003366;">Minute</span><span style="color: #66cc66;">/</span><span style="color: #cc66cc;">60</span><span style="color: #333;">&#41;</span><span style="color: #333;">&#41;</span><span style="color: #66cc66;">/</span><span style="color: #cc66cc;">12</span><span style="color: #333;">&#41;</span><span style="color: #333;">&#41;</span><span style="color: #333;">&#41;</span> `<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">-RenderTransformOrigin</span> <span style="color: #009900;">&quot;0.5,0.5&quot;</span> <span style="color: #000066;">-RenderTransform</span> <span style="color: #333;">&#123;</span> RotateTransform <span style="color: #000066;">-Angle</span> <span style="color: #66cc66;">-</span><span style="color: #cc66cc;">90</span> <span style="color: #333;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #660033; font-weight: bold;">$animate</span> <span style="color: #66cc66;">=</span> DoubleAnimation <span style="color: #000066;">-To</span> <span style="color: #cc66cc;">0</span> <span style="color: #000066;">-Duration</span> <span style="color: #009900;">&quot;$(11 - ($now.Hour % 12)):$(59 - $now.Minute):$(60 - $now.Second)&quot;</span> &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #660033; font-weight: bold;">$el</span><span style="color: #333;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #333;">&#93;</span>.<span style="color: #003366;">BeginAnimation</span><span style="color: #333;">&#40;</span> <span style="color: #003366; font-weight: bold;"><span style="color: #333;">&#91;</span>System.<span style="color: #003366;">Windows</span>.<span style="color: #003366;">Shapes</span>.<span style="color: #003366;">Shape</span><span style="color: #333;">&#93;</span></span>::<span style="color: #003366;">StrokeDashOffsetProperty</span>, <span style="color: #660033; font-weight: bold;">$animate</span> <span style="color: #333;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;"># Minute</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; TextBlock <span style="color: #000066;">-Text</span> M &nbsp;<span style="color: #000066;">-Margin</span> <span style="color: #009900;">'0,20,0,0'</span> <span style="color: #000066;">-FontWeight</span> ExtraBold <span style="color: #000066;">-Foreground</span> White @Label<br />
&nbsp; &nbsp; &nbsp; &nbsp; Ellipse <span style="color: #000066;">-Name</span> Minutes <span style="color: #000066;">-Ov</span> el <span style="color: #000066;">-Fill</span> Transparent <span style="color: #000066;">-Stroke</span> Gray `<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">-StrokeThickness</span> <span style="color: #cc66cc;">75</span> &nbsp;<span style="color: #000066;">-Width</span> <span style="color: #cc66cc;">300</span> <span style="color: #000066;">-Height</span> <span style="color: #cc66cc;">300</span> `<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">-StrokeDashArray</span> &nbsp;<span style="color: #cc66cc;">9.43</span>, <span style="color: #cc66cc;">9.43</span> `<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">-StrokeDashOffset</span> $<span style="color: #333;">&#40;</span><span style="color: #cc66cc;">9.43</span> <span style="color: #66cc66;">-</span> <span style="color: #333;">&#40;</span><span style="color: #cc66cc;">9.43</span> <span style="color: #66cc66;">*</span> <span style="color: #333;">&#40;</span><span style="color: #333;">&#40;</span><span style="color: #660033; font-weight: bold;">$now</span>.<span style="color: #003366;">Minute</span><span style="color: #333;">&#41;</span> <span style="color: #66cc66;">+</span> <span style="color: #333;">&#40;</span><span style="color: #660033; font-weight: bold;">$now</span>.<span style="color: #003366;">Second</span><span style="color: #66cc66;">/</span><span style="color: #cc66cc;">60</span><span style="color: #333;">&#41;</span><span style="color: #333;">&#41;</span><span style="color: #66cc66;">/</span><span style="color: #cc66cc;">60</span><span style="color: #333;">&#41;</span><span style="color: #333;">&#41;</span> `<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">-RenderTransformOrigin</span> <span style="color: #009900;">&quot;0.5,0.5&quot;</span> <span style="color: #000066;">-RenderTransform</span> <span style="color: #333;">&#123;</span> RotateTransform <span style="color: #000066;">-Angle</span> <span style="color: #66cc66;">-</span><span style="color: #cc66cc;">90</span> <span style="color: #333;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #660033; font-weight: bold;">$animate</span> <span style="color: #66cc66;">=</span> DoubleAnimation <span style="color: #000066;">-To</span> <span style="color: #cc66cc;">0</span> <span style="color: #000066;">-Duration</span> <span style="color: #009900;">&quot;00:$(59 - $now.Minute):$(60 - $now.Second)&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #660033; font-weight: bold;">$el</span><span style="color: #333;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #333;">&#93;</span>.<span style="color: #003366;">BeginAnimation</span><span style="color: #333;">&#40;</span> <span style="color: #003366; font-weight: bold;"><span style="color: #333;">&#91;</span>System.<span style="color: #003366;">Windows</span>.<span style="color: #003366;">Shapes</span>.<span style="color: #003366;">Shape</span><span style="color: #333;">&#93;</span></span>::<span style="color: #003366;">StrokeDashOffsetProperty</span>, <span style="color: #660033; font-weight: bold;">$animate</span> <span style="color: #333;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;"># Seconds</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; TextBlock <span style="color: #000066;">-Text</span> S <span style="color: #000066;">-Margin</span> <span style="color: #009900;">'0,45,0,0'</span> <span style="color: #000066;">-FontWeight</span> ExtraBold <span style="color: #000066;">-Foreground</span> Gray @Label<br />
&nbsp; &nbsp; &nbsp; &nbsp; Ellipse <span style="color: #000066;">-Name</span> Seconds <span style="color: #000066;">-Ov</span> el <span style="color: #000066;">-Fill</span> Transparent <span style="color: #000066;">-Stroke</span> White `<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">-StrokeThickness</span> <span style="color: #cc66cc;">50</span> &nbsp;<span style="color: #000066;">-Width</span> <span style="color: #cc66cc;">250</span> <span style="color: #000066;">-Height</span> <span style="color: #cc66cc;">250</span> `<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">-StrokeDashArray</span> <span style="color: #cc66cc;">12.57</span>,<span style="color: #cc66cc;">12.57</span> `<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">-StrokeDashOffset</span> $<span style="color: #333;">&#40;</span><span style="color: #cc66cc;">12.57</span> <span style="color: #66cc66;">-</span> <span style="color: #333;">&#40;</span><span style="color: #cc66cc;">12.57</span> <span style="color: #66cc66;">*</span> <span style="color: #333;">&#40;</span><span style="color: #660033; font-weight: bold;">$now</span>.<span style="color: #003366;">Second</span><span style="color: #66cc66;">/</span><span style="color: #cc66cc;">60</span><span style="color: #333;">&#41;</span><span style="color: #333;">&#41;</span><span style="color: #333;">&#41;</span> `<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">-RenderTransformOrigin</span> <span style="color: #009900;">&quot;0.5,0.5&quot;</span> <span style="color: #000066;">-RenderTransform</span> <span style="color: #333;">&#123;</span> RotateTransform <span style="color: #000066;">-Angle</span> <span style="color: #66cc66;">-</span><span style="color: #cc66cc;">90</span> <span style="color: #333;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #660033; font-weight: bold;">$animate</span> <span style="color: #66cc66;">=</span> DoubleAnimation <span style="color: #000066;">-To</span> <span style="color: #cc66cc;">0</span> <span style="color: #000066;">-Duration</span> <span style="color: #009900;">&quot;00:00:$(60 - $now.Second)&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #660033; font-weight: bold;">$el</span><span style="color: #333;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #333;">&#93;</span>.<span style="color: #003366;">BeginAnimation</span><span style="color: #333;">&#40;</span> <span style="color: #003366; font-weight: bold;"><span style="color: #333;">&#91;</span>System.<span style="color: #003366;">Windows</span>.<span style="color: #003366;">Shapes</span>.<span style="color: #003366;">Shape</span><span style="color: #333;">&#93;</span></span>::<span style="color: #003366;">StrokeDashOffsetProperty</span>, <span style="color: #660033; font-weight: bold;">$animate</span> <span style="color: #333;">&#41;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">## These go in the center of the circles (notice the alignment)</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #660033; font-weight: bold;">$Centered</span> <span style="color: #66cc66;">=</span> @<span style="color: #333;">&#123;</span>HorizontalAlignment<span style="color: #66cc66;">=</span><span style="color: #009900;">&quot;Center&quot;</span>;VerticalAlignment<span style="color: #66cc66;">=</span><span style="color: #009900;">&quot;Center&quot;</span><span style="color: #333;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; StackPanel @Centered <span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; TextBlock <span style="color: #000066;">-Name</span> Time <span style="color: #000066;">-FontWeight</span> ExtraBold <span style="color: #000066;">-Foreground</span> Black <span style="color: #000066;">-FontSize</span> <span style="color: #cc66cc;">30</span> `<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">-Text</span> <span style="color: #660033; font-weight: bold;">$Now</span>.<span style="color: #003366;">ToString</span><span style="color: #333;">&#40;</span><span style="color: #009900;">&quot;h:mm&quot;</span><span style="color: #333;">&#41;</span> @Centered<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; TextBlock <span style="color: #000066;">-Name</span> Day <span style="color: #000066;">-FontWeight</span> Normal <span style="color: #000066;">-Foreground</span> Black <span style="color: #000066;">-FontSize</span> <span style="color: #cc66cc;">23</span> `<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">-Text</span> <span style="color: #660033; font-weight: bold;">$Now</span>.<span style="color: #003366;">DayOfWeek</span>.<span style="color: #003366;">ToString</span><span style="color: #333;">&#40;</span><span style="color: #333;">&#41;</span>.<span style="color: #003366;">ToUpper</span><span style="color: #333;">&#40;</span><span style="color: #333;">&#41;</span> @Centered<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; StackPanel <span style="color: #000066;">-Orientation</span> Horizontal @Centered <span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; TextBlock <span style="color: #000066;">-Name</span> Date <span style="color: #000066;">-FontWeight</span> ExtraBold <span style="color: #000066;">-Foreground</span> Black <span style="color: #000066;">-FontSize</span> <span style="color: #cc66cc;">18</span> `<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">-Text</span> <span style="color: #660033; font-weight: bold;">$Now</span>.<span style="color: #003366;">Day</span> <span style="color: #000066;">-Margin</span> <span style="color: #009900;">'0,0,5,0'</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; TextBlock <span style="color: #000066;">-Name</span> Month <span style="color: #000066;">-FontWeight</span> ExtraBold <span style="color: #000066;">-Foreground</span> White <span style="color: #000066;">-FontSize</span> <span style="color: #cc66cc;">18</span> `<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">-Text</span> <span style="color: #660033; font-weight: bold;">$Now</span>.<span style="color: #003366;">ToString</span><span style="color: #333;">&#40;</span><span style="color: #009900;">&quot;MMMM&quot;</span><span style="color: #333;">&#41;</span>.<span style="color: #003366;">ToUpper</span><span style="color: #333;">&#40;</span><span style="color: #333;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #333;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #333;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">## Hour marks</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666699; font-weight: bold;">if</span><span style="color: #333;">&#40;</span><span style="color: #660033; font-weight: bold;">$ShowMarks</span><span style="color: #333;">&#41;</span> <span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Ellipse <span style="color: #000066;">-Width</span> <span style="color: #cc66cc;">350</span> <span style="color: #000066;">-Height</span> <span style="color: #cc66cc;">350</span> <span style="color: #000066;">-StrokeThickness</span> <span style="color: #cc66cc;">5</span> <span style="color: #000066;">-Fill</span> Transparent <span style="color: #000066;">-Stroke</span> White <span style="color: #000066;">-StrokeDashArray</span> <span style="color: #cc66cc;">0.5</span>,<span style="color: #cc66cc;">17.6</span> <span style="color: #000066;">-RenderTransformOrigin</span> <span style="color: #009900;">&quot;0.5,0.5&quot;</span> <span style="color: #000066;">-RenderTransform</span> <span style="color: #333;">&#123;</span>RotateTransform <span style="color: #000066;">-Angle</span> <span style="color: #66cc66;">-</span><span style="color: #cc66cc;">90.5</span><span style="color: #333;">&#125;</span> <span style="color: #000066;">-Opacity</span> <span style="color: #cc66cc;">0.8</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Ellipse <span style="color: #000066;">-Width</span> <span style="color: #cc66cc;">160</span> <span style="color: #000066;">-Height</span> <span style="color: #cc66cc;">160</span> <span style="color: #000066;">-StrokeThickness</span> <span style="color: #cc66cc;">5</span> <span style="color: #000066;">-Fill</span> Transparent <span style="color: #000066;">-Stroke</span> Black <span style="color: #000066;">-StrokeDashArray</span> <span style="color: #cc66cc;">0.5</span>,<span style="color: #cc66cc;">7.62</span> <span style="color: #000066;">-RenderTransformOrigin</span> <span style="color: #009900;">&quot;0.5,0.5&quot;</span> <span style="color: #000066;">-RenderTransform</span> <span style="color: #333;">&#123;</span>RotateTransform <span style="color: #000066;">-Angle</span> <span style="color: #66cc66;">-</span><span style="color: #cc66cc;">90.5</span><span style="color: #333;">&#125;</span> <span style="color: #000066;">-Opacity</span> <span style="color: #cc66cc;">0.8</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #333;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #333;">&#125;</span><br />
<span style="color: #333;">&#125;</span> <span style="color: #000066;">-UpdateBlock</span> <span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #660033; font-weight: bold;">$children</span> <span style="color: #66cc66;">=</span> @<span style="color: #333;">&#123;</span><span style="color: #333;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #666699; font-weight: bold;">foreach</span><span style="color: #333;">&#40;</span><span style="color: #660033; font-weight: bold;">$child</span> <span style="color: #666699; font-weight: bold;">in</span> <span style="color: #0066cc; font-style: italic;">Get-<span style="font-style: normal;">ChildControl</span></span> <span style="color: #000066;">-Control</span> <span style="color: #660033; font-weight: bold;">$this</span>.<span style="color: #003366;">Tag</span><span style="color: #333;">&#41;</span><span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #660033; font-weight: bold;">$children</span>.<span style="color: #333;">&#40;</span><span style="color: #660033; font-weight: bold;">$child</span>.<span style="color: #003366;">Name</span><span style="color: #333;">&#41;</span> <span style="color: #66cc66;">=</span> <span style="color: #660033; font-weight: bold;">$child</span><br />
&nbsp; &nbsp; <span style="color: #333;">&#125;</span><br />
<br />
&nbsp; &nbsp;<span style="color: #660033; font-weight: bold;">$now</span> <span style="color: #66cc66;">=</span> <span style="color: #0066cc; font-style: italic;">Get-<span style="font-style: normal;">Date</span></span><br />
<br />
&nbsp; &nbsp; <span style="color: #666699; font-weight: bold;">if</span><span style="color: #333;">&#40;</span><span style="color: #660033; font-weight: bold;">$now</span>.<span style="color: #003366;">Second</span> <span style="color: #000066;">-eq</span> <span style="color: #cc66cc;">0</span><span style="color: #333;">&#41;</span> <span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666699; font-weight: bold;">if</span><span style="color: #333;">&#40;</span><span style="color: #660033; font-weight: bold;">$children</span>.<span style="color: #003366;">Seconds</span>.<span style="color: #003366;">Tag</span> <span style="color: #000066;">-ne</span> <span style="color: #660033; font-weight: bold;">$true</span><span style="color: #333;">&#41;</span> <span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #660033; font-weight: bold;">$children</span>.<span style="color: #003366;">Seconds</span>.<span style="color: #003366;">Tag</span> &nbsp;<span style="color: #66cc66;">=</span> <span style="color: #660033; font-weight: bold;">$true</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #660033; font-weight: bold;">$animate</span> <span style="color: #66cc66;">=</span> DoubleAnimation <span style="color: #000066;">-From</span> <span style="color: #660033; font-weight: bold;">$children</span>.<span style="color: #003366;">Seconds</span>.<span style="color: #003366;">StrokeDashArray</span><span style="color: #333;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #333;">&#93;</span> <span style="color: #000066;">-To</span> <span style="color: #cc66cc;">0</span> <span style="color: #000066;">-Duration</span> <span style="color: #009900;">'00:01'</span> <span style="color: #000066;">-RepeatBehavior</span> <span style="color: #333;">&#40;</span><span style="color: #003366; font-weight: bold;"><span style="color: #333;">&#91;</span>system.<span style="color: #003366;">windows</span>.<span style="color: #003366;">media</span>.<span style="color: #003366;">animation</span>.<span style="color: #003366;">RepeatBehavior</span><span style="color: #333;">&#93;</span></span>::<span style="color: #003366;">Forever</span><span style="color: #333;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #660033; font-weight: bold;">$children</span>.<span style="color: #003366;">Seconds</span>.<span style="color: #003366;">BeginAnimation</span><span style="color: #333;">&#40;</span> <span style="color: #003366; font-weight: bold;"><span style="color: #333;">&#91;</span>System.<span style="color: #003366;">Windows</span>.<span style="color: #003366;">Shapes</span>.<span style="color: #003366;">Shape</span><span style="color: #333;">&#93;</span></span>::<span style="color: #003366;">StrokeDashOffsetProperty</span>, <span style="color: #660033; font-weight: bold;">$animate</span> <span style="color: #333;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #333;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #333;">&#125;</span> <span style="color: #666699; font-weight: bold;">else</span> <span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #660033; font-weight: bold;">$children</span>.<span style="color: #003366;">Seconds</span>.<span style="color: #003366;">Tag</span> &nbsp;<span style="color: #66cc66;">=</span> <span style="color: #660033; font-weight: bold;">$false</span><br />
&nbsp; &nbsp; <span style="color: #333;">&#125;</span><br />
&nbsp; &nbsp;<br />
&nbsp; &nbsp; <span style="color: #666699; font-weight: bold;">if</span><span style="color: #333;">&#40;</span><span style="color: #660033; font-weight: bold;">$now</span>.<span style="color: #003366;">Minute</span> <span style="color: #000066;">-eq</span> <span style="color: #cc66cc;">0</span><span style="color: #333;">&#41;</span> <span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666699; font-weight: bold;">if</span><span style="color: #333;">&#40;</span><span style="color: #660033; font-weight: bold;">$children</span>.<span style="color: #003366;">Minutes</span>.<span style="color: #003366;">Tag</span> <span style="color: #000066;">-ne</span> <span style="color: #660033; font-weight: bold;">$true</span><span style="color: #333;">&#41;</span> <span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #660033; font-weight: bold;">$children</span>.<span style="color: #003366;">Minutes</span>.<span style="color: #003366;">Tag</span> <span style="color: #66cc66;">=</span> <span style="color: #660033; font-weight: bold;">$true</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #660033; font-weight: bold;">$animate</span> <span style="color: #66cc66;">=</span> DoubleAnimation <span style="color: #000066;">-From</span> <span style="color: #660033; font-weight: bold;">$children</span>.<span style="color: #003366;">Minutes</span>.<span style="color: #003366;">StrokeDashArray</span><span style="color: #333;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #333;">&#93;</span> <span style="color: #000066;">-To</span> <span style="color: #cc66cc;">0</span> <span style="color: #000066;">-Duration</span> <span style="color: #009900;">'01:00'</span> <span style="color: #000066;">-RepeatBehavior</span> <span style="color: #333;">&#40;</span><span style="color: #003366; font-weight: bold;"><span style="color: #333;">&#91;</span>system.<span style="color: #003366;">windows</span>.<span style="color: #003366;">media</span>.<span style="color: #003366;">animation</span>.<span style="color: #003366;">RepeatBehavior</span><span style="color: #333;">&#93;</span></span>::<span style="color: #003366;">Forever</span><span style="color: #333;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #660033; font-weight: bold;">$children</span>.<span style="color: #003366;">Minutes</span>.<span style="color: #003366;">BeginAnimation</span><span style="color: #333;">&#40;</span> <span style="color: #003366; font-weight: bold;"><span style="color: #333;">&#91;</span>System.<span style="color: #003366;">Windows</span>.<span style="color: #003366;">Shapes</span>.<span style="color: #003366;">Shape</span><span style="color: #333;">&#93;</span></span>::<span style="color: #003366;">StrokeDashOffsetProperty</span>, <span style="color: #660033; font-weight: bold;">$animate</span> <span style="color: #333;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #333;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #333;">&#125;</span> <span style="color: #666699; font-weight: bold;">else</span> <span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #660033; font-weight: bold;">$children</span>.<span style="color: #003366;">Minutes</span>.<span style="color: #003366;">Tag</span> &nbsp;<span style="color: #66cc66;">=</span> <span style="color: #660033; font-weight: bold;">$false</span><br />
&nbsp; &nbsp; <span style="color: #333;">&#125;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #666699; font-weight: bold;">if</span><span style="color: #333;">&#40;</span><span style="color: #660033; font-weight: bold;">$now</span>.<span style="color: #003366;">Hour</span> <span style="color: #000066;">-eq</span> <span style="color: #cc66cc;">12</span><span style="color: #333;">&#41;</span> <span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666699; font-weight: bold;">if</span><span style="color: #333;">&#40;</span><span style="color: #660033; font-weight: bold;">$children</span>.<span style="color: #003366;">Hours</span>.<span style="color: #003366;">Tag</span> <span style="color: #000066;">-ne</span> <span style="color: #660033; font-weight: bold;">$true</span><span style="color: #333;">&#41;</span> <span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #660033; font-weight: bold;">$children</span>.<span style="color: #003366;">Hours</span>.<span style="color: #003366;">Tag</span> &nbsp;<span style="color: #66cc66;">=</span> <span style="color: #660033; font-weight: bold;">$true</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #660033; font-weight: bold;">$animate</span> <span style="color: #66cc66;">=</span> DoubleAnimation <span style="color: #000066;">-From</span> <span style="color: #660033; font-weight: bold;">$children</span>.<span style="color: #003366;">Hours</span>.<span style="color: #003366;">StrokeDashArray</span><span style="color: #333;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #333;">&#93;</span> <span style="color: #000066;">-To</span> <span style="color: #cc66cc;">0</span> <span style="color: #000066;">-Duration</span> <span style="color: #009900;">'12:00'</span> <span style="color: #000066;">-RepeatBehavior</span> <span style="color: #333;">&#40;</span><span style="color: #003366; font-weight: bold;"><span style="color: #333;">&#91;</span>system.<span style="color: #003366;">windows</span>.<span style="color: #003366;">media</span>.<span style="color: #003366;">animation</span>.<span style="color: #003366;">RepeatBehavior</span><span style="color: #333;">&#93;</span></span>::<span style="color: #003366;">Forever</span><span style="color: #333;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #660033; font-weight: bold;">$children</span>.<span style="color: #003366;">Hours</span>.<span style="color: #003366;">BeginAnimation</span><span style="color: #333;">&#40;</span> <span style="color: #003366; font-weight: bold;"><span style="color: #333;">&#91;</span>System.<span style="color: #003366;">Windows</span>.<span style="color: #003366;">Shapes</span>.<span style="color: #003366;">Shape</span><span style="color: #333;">&#93;</span></span>::<span style="color: #003366;">StrokeDashOffsetProperty</span>, <span style="color: #660033; font-weight: bold;">$animate</span> <span style="color: #333;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #333;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #333;">&#125;</span> <span style="color: #666699; font-weight: bold;">else</span> <span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #660033; font-weight: bold;">$children</span>.<span style="color: #003366;">Hours</span>.<span style="color: #003366;">Tag</span> &nbsp;<span style="color: #66cc66;">=</span> <span style="color: #660033; font-weight: bold;">$false</span><br />
&nbsp; &nbsp; <span style="color: #333;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #660033; font-weight: bold;">$children</span>.<span style="color: #003366;">Time</span>.<span style="color: #003366;">Text</span> <span style="color: #66cc66;">=</span> <span style="color: #660033; font-weight: bold;">$Now</span>.<span style="color: #003366;">ToString</span><span style="color: #333;">&#40;</span><span style="color: #009900;">&quot;h:mm&quot;</span><span style="color: #333;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #660033; font-weight: bold;">$children</span>.<span style="color: #003366;">Day</span>.<span style="color: #003366;">Text</span> <span style="color: #66cc66;">=</span> <span style="color: #660033; font-weight: bold;">$Now</span>.<span style="color: #003366;">DayOfWeek</span>.<span style="color: #003366;">ToString</span><span style="color: #333;">&#40;</span><span style="color: #333;">&#41;</span>.<span style="color: #003366;">ToUpper</span><span style="color: #333;">&#40;</span><span style="color: #333;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #660033; font-weight: bold;">$children</span>.<span style="color: #003366;">Date</span>.<span style="color: #003366;">Text</span> <span style="color: #66cc66;">=</span> <span style="color: #660033; font-weight: bold;">$Now</span>.<span style="color: #003366;">Day</span><br />
&nbsp; &nbsp; <span style="color: #660033; font-weight: bold;">$children</span>.<span style="color: #003366;">Month</span>.<span style="color: #003366;">Text</span> <span style="color: #66cc66;">=</span> <span style="color: #660033; font-weight: bold;">$Now</span>.<span style="color: #003366;">ToString</span><span style="color: #333;">&#40;</span><span style="color: #009900;">&quot;MMMM&quot;</span><span style="color: #333;">&#41;</span>.<span style="color: #003366;">ToUpper</span><span style="color: #333;">&#40;</span><span style="color: #333;">&#41;</span><br />
<span style="color: #333;">&#125;</span><br />
<span style="color: #333;">&#125;</span><br />
&nbsp;</div>

	<p>What do you think of that?</p>

	<p>The clever part (which, believe me, took a <span class="caps">LOT</span> of experimenting), is that I&#8217;m creating a StrokeDashArray and animating the StrokeDashOffsetProperty in such a way that the &#8220;stroke&#8221; of the Ellipse (the circle of the clock) gets drawn slowly over time (very slowly, in the case of the hour &#8220;hand&#8221;).  Now, as you can see, I&#8217;m still setting up the animations by hand (I just didn&#8217;t convert the code to use <code>Start-Animation</code>), and in the UpdateBlock, I actually reset the animations if they&#8217;re at zero.  I can write more about this if people have questions, but it&#8217;s nearly 2:30am, so I&#8217;ll take questions tomorrow  <img src='http://joelbennett.net/wordpress/wp-includes/' alt=':)' class='wp-smiley' /> </p>]]></content:encoded>
			<wfw:commentRss>http://joelbennett.net/the-obligatory-showui-clock/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>WPF Window “Native” Behavior: Metro Window</title>
		<link>http://joelbennett.net/wpf-metro-windows/</link>
		<comments>http://joelbennett.net/wpf-metro-windows/#comments</comments>
		<pubDate>Fri, 05 Nov 2010 03:22:25 +0000</pubDate>
		<dc:creator>Joel 'Jaykul' Bennett</dc:creator>
				<category><![CDATA[Huddled]]></category>
		<category><![CDATA[Custom Chrome]]></category>
		<category><![CDATA[Metro]]></category>
		<category><![CDATA[PInvoke]]></category>
		<category><![CDATA[Windows 7]]></category>
		<category><![CDATA[WPF]]></category>

		<guid isPermaLink="false">http://huddledmasses.org/?p=1563</guid>
		<description><![CDATA[A couple of years ago I first introduced my native behaviors for WPF to support enhancing WPF applications with behaviors that require PInvoke or hooking the Window&#8217;s message processing loop: WndProc. You can read all about it on my previous posts, including the original implementations of my Snap To Screen Edges behavior, and my Custom [...]]]></description>
			<content:encoded><![CDATA[	<p>A couple of years ago I first introduced my <a href="http://huddledmasses.org/wpf-window-native-behaviors/">native behaviors for WPF</a> to support enhancing <span class="caps">WPF</span> applications with behaviors that require PInvoke or hooking the Window&#8217;s message processing loop: WndProc.  You can read all about it on my previous posts, including the original implementations of my <a href="http://huddledmasses.org/wpf-windows-that-snap-to-screen-edges/">Snap To Screen Edges</a> behavior, and my Custom Chrome for creating windows with buttons on the Aero glass frame like ribbon apps or all those new browsers &#8230;</p>

	<p>However, I&#8217;m writing today because I went back this week to revisit that project because I wanted a &#8220;Metro&#8221; style Window &#8212; basically, something like the Zune client window.</p>

	<p>As I was reviewing it, I discovered <a href="http://msdn.microsoft.com/en-us/library/system.windows.interactivity%28Expression.40%29.aspx">System.Windows.Interactivity</a> class which came out of Expression Blend, and includes the functionality of my NativeBehaviors attached property with regards to allowing you create new behaviors for <span class="caps">WPF</span> elements &#8230; and of course, despite being newer, their system has much broader support than mine  <img src='http://joelbennett.net/wordpress/wp-includes/' alt=';-)' class='wp-smiley' /> </p>

	<p>So anyway &#8230; long story short: I&#8217;ve rewritten my behaviors on top of <a href="http://msdn.microsoft.com/en-us/library/ff726531%28Expression.40%29.aspx">System.Windows.Interactivity.Behavior<T></a> and written a MetroWindow behavior that makes my PowerBoots application look roughly like this:</p>

	<a href="http://joelbennett.net/wordpress/wp-content/uploads/2010/11/PoshConsole_Metro.png"><img src="http://joelbennett.net/wordpress/wp-content/uploads/2010/11/PoshConsole_Metro-298x300.png" alt="PoshConsole with the MetroWindow behavior" title="PoshConsole_Metro" width="298" height="300" class="size-medium wp-image-1565" /></a>

	<p>I&#8217;m really pleased with the results, and while I was at it I finally fixed a weird glitch in the Snap-To behavior when using the Win+Left or Win+Right keys in Windows 7 to move the window docked from the left of one monitor to the right side of another (or vice versa), and of course this also includes the global hotkeys behavior, and my Quake-console behavior  <img src='http://joelbennett.net/wordpress/wp-includes/' alt=':)' class='wp-smiley' />  The code to make add the MetroWindow behavior along with the SnapTo would be just:</p>

	<div class="xaml code xaml" style="font-family:monospace;"><br />
&nbsp; &nbsp; &lt;i:Interaction.Behaviors&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &lt;huddled:MetroWindow CaptionHeight=&quot;58&quot; ButtonSize=&quot;20&quot; /&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &lt;huddled:SnapToBehavior SnapDistance=&quot;22&quot; SnapMargin=&quot;18&quot; /&gt;<br />
&nbsp; &nbsp; &lt;/i:Interaction.Behaviors&gt;<br />
&nbsp;</div>

	<p>I&#8217;ll write this up a bit more later when I&#8217;m ready to release PoshConsole and the revised Quake behavior, for now you&#8217;ll have to be content with the screenshots, unless you want to <a href="http://poshconsole.codeplex.com/SourceControl/list/changesets">grab source code</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://joelbennett.net/wpf-metro-windows/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PowerBoots 0.3 – The Faster Edition</title>
		<link>http://joelbennett.net/powerboots-0-3-the-faster-edition/</link>
		<comments>http://joelbennett.net/powerboots-0-3-the-faster-edition/#comments</comments>
		<pubDate>Sat, 19 Jun 2010 05:40:53 +0000</pubDate>
		<dc:creator>Joel 'Jaykul' Bennett</dc:creator>
				<category><![CDATA[Huddled]]></category>
		<category><![CDATA[PowerBoots]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Teaser]]></category>
		<category><![CDATA[WPF]]></category>

		<guid isPermaLink="false">http://huddledmasses.org/?p=1496</guid>
		<description><![CDATA[I&#8217;ve been working on a ton of new functionality for this next release of PowerBoots &#8230; and now that I&#8217;m getting close to ready to release, I thought it was time to work on the performance! Here&#8217;s a completely trivial example: WPK: Command : $boxes = 1..100 &#124; % { New-TextBox -Text Foo -FontFamily Consolas [...]]]></description>
			<content:encoded><![CDATA[	<p>I&#8217;ve been working on a ton of new functionality for this next release of PowerBoots &#8230; and now that I&#8217;m getting close to ready to release, I thought it was time to work on the performance! Here&#8217;s a completely trivial example:</p>

	<h3>WPK:</h3>

	<p>Command   : $boxes = 1..100 | % { New-TextBox -Text Foo -FontFamily Consolas -On_GotFocus { $_ } }<br />
Duration  : 5.25153s</p>

	<h3>Current PowerBoots 0.2:</h3>

	<p>Command   : $boxes = 1..100 | % { TextBox -Text Foo -FontFamily Consolas -On_GotFocus { $_ } }<br />
<strong>Average   : 9.40994s</strong></p>

	<p>You can see why I thought I should probably work on improving that. It was bad.</p>

	<h3>PowerBoots 0.3 yesterday:</h3>

	<p>Command   : $boxes = 1..100 | % { TextBox -Text Foo -FontFamily Consolas -On_GotFocus { $_ } }<br />
Duration  : 7.43874s</p>

	<h3>PowerBoots 0.3 tonight:</h3>

	<p>Command   : $boxes = 1..100 | % { TextBox -Text Foo -FontFamily Consolas -On_GotFocus { $_ } }<br />
<strong>Duration  : 0.34103s</strong></p>

	<p>Now, if you&#8217;re like me, you&#8217;re probably thinking I screwed up <em>something</em> and that TextBox isn&#8217;t actually getting created right &#8230;</p>

	<p><img src="http://joelbennett.net/images/PowerBoots/Boots-Performance-Boost.png" alt="" width="902" height="573" /></p>

	<p>Postscript: ran another test. A little more useful. I have 248 fonts on my system.  I have an &#8220;Samples&#8221; script which shows them all:</p>

	<div class="posh code posh" style="font-family:monospace;"><br />
<span style="color: #0066cc; font-style: italic;">New-<span style="font-style: normal;">BootsWindow</span></span> <span style="color: #333;">&#123;</span> ScrollViewer <span style="color: #333;">&#123;</span> TextBlock <span style="color: #009900;">&quot;Loading Fonts...&quot;</span> <span style="color: #000066;">-FontSize</span> <span style="color: #cc66cc;">62</span> <span style="color: #000066;">-FontFamily</span> SegoeUI <span style="color: #333;">&#125;</span> <span style="color: #333;">&#125;</span> <span style="color: #000066;">-Async</span> <span style="color: #000066;">-Passthru</span> <span style="color: #66cc66;">|</span> <br />
<span style="color: #0066cc; font-style: italic;">Invoke-<span style="font-style: normal;">BootsWindow</span></span> <span style="color: #000066;">-Script</span> <span style="color: #333;">&#123;</span> <br />
&nbsp; &nbsp;<span style="color: #660033; font-weight: bold;">$This</span>.<span style="color: #003366;">Content</span>.<span style="color: #003366;">Content</span> <span style="color: #66cc66;">=</span> $<span style="color: #333;">&#40;</span> <br />
&nbsp; &nbsp; &nbsp; <span style="color: #666699; font-weight: bold;">ForEach</span><span style="color: #333;">&#40;</span> <span style="color: #660033; font-weight: bold;">$font</span> <span style="color: #666699; font-weight: bold;">in</span> <span style="color: #003366; font-weight: bold;"><span style="color: #333;">&#91;</span>System.<span style="color: #003366;">Windows</span>.<span style="color: #003366;">Media</span>.<span style="color: #003366;">Fonts</span><span style="color: #333;">&#93;</span></span>::<span style="color: #003366;">SystemFontFamilies</span> <span style="color: #333;">&#41;</span> <span style="color: #333;">&#123;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;TextBlock <span style="color: #000066;">-FontFamily</span> <span style="color: #660033; font-weight: bold;">$font</span>.<span style="color: #003366;">Source</span> <span style="color: #000066;">-Text</span> <span style="color: #009900;">&quot;The Quick Brown Fox Jumps over the Lazy Dog&quot;</span> <span style="color: #000066;">-FontSize</span> <span style="color: #cc66cc;">18</span>; <span style="color: #0066cc; font-style: italic;">Write-<span style="font-style: normal;">Host</span></span> <span style="color: #660033; font-weight: bold;">$font</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #333;">&#125;</span><br />
&nbsp; &nbsp;<span style="color: #333;">&#41;</span> <span style="color: #66cc66;">|</span> StackPanel<br />
<span style="color: #333;">&#125;</span><br />
&nbsp;</div>

	<h3>Old PowerBoots:</h3>

	<p>Duration  : 19.39894s</p>

	<h3>New PowerBoots:</h3>

	<p>Duration  : 3.53100s</p>]]></content:encoded>
			<wfw:commentRss>http://joelbennett.net/powerboots-0-3-the-faster-edition/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Creating WPF UIs for PowerShell with PowerBoots and Visual Studio WPF Designer</title>
		<link>http://joelbennett.net/creating-wpf-uis-for-powershell-with-powerboots-and-visual-studio-wpf-designer/</link>
		<comments>http://joelbennett.net/creating-wpf-uis-for-powershell-with-powerboots-and-visual-studio-wpf-designer/#comments</comments>
		<pubDate>Fri, 30 Apr 2010 03:09:42 +0000</pubDate>
		<dc:creator>Joel 'Jaykul' Bennett</dc:creator>
				<category><![CDATA[Huddled]]></category>
		<category><![CDATA[PowerBoots]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[WPF]]></category>
		<category><![CDATA[XAML]]></category>

		<guid isPermaLink="false">http://huddledmasses.org/?p=1433</guid>
		<description><![CDATA[I&#8217;ve had several people ask me how PowerBoots compares to PrimalForms, or ask for a visual designer for PowerBoots. I usually answer something along the lines of the fact that Microsoft has already created a very good WPF/XAML designer in Visual Studio (including the free Express editions), particularly in 2010, so I don&#8217;t see why [...]]]></description>
			<content:encoded><![CDATA[	<p>I&#8217;ve had several people ask me how <a href="http://boots.codeplex.com/">PowerBoots</a> compares to PrimalForms, or ask for a visual designer for PowerBoots. I usually answer something along the lines of the fact that Microsoft has already created a very good WPF/<span class="caps">XAML</span> designer in Visual Studio (including the free Express editions), particularly in 2010, so I don&#8217;t see why I should duplicate their efforts.  However, up until now I haven&#8217;t written or published any sort of walk through about how to make that work &#8230; </p>

	<p>So crank up your <a href="http://msdn.com/express/">Visual Studio Express Edition</a> and make yourself some user interfaces!</p>

	<p>Basically, you just create a <span class="caps">WPF</span> project in C# or VB.Net or whatever &#8230; I chose to name my project &#8220;XamlForBoots&#8221; &#8212; your project will start off with an empty MainWindow.xaml file which will look something like this:</p>

	<a href="/wordpress/wp-content/uploads/2010/03/NewMainWindow.xaml_.png"><img src="/wordpress/wp-content/uploads/2010/03/NewMainWindow.xaml_-300x199.png" alt="This is what the Main Window looks like at first" title="NewMainWindow.xaml" width="300" height="199" class="size-medium wp-image-1434" /></a>

	<p>After you drag a few more controls onto the form, and you&#8217;ve created a complete user interface, you should delete the x:Class attribute.  You need to make sure you know the <em>name</em> of the controls you want to interact with, so you might end up with something like this (I used the property pane, which you can&#8217;t see in this shot, to name each textbox and the button):</p>

	<a href="/wordpress/wp-content/uploads/2010/04/FinishedMainWindow.xaml_.png"><img src="/wordpress/wp-content/uploads/2010/04/FinishedMainWindow.xaml_-300x212.png" alt="Once you&#039;ve dragged some controls onto it" title="FinishedMainWindow.xaml" width="300" height="212" class="size-medium wp-image-1439" /></a>

	<p>At this point, we&#8217;re ready to drop into PowerShell and write some script. Now &#8230; there is one catch here.  The first script I&#8217;m going to show you here is for <strong>PowerBoots 0.3</strong> (which will be the first release candidate for a gold 1.0 release, and will be out soon&#8482;). However, I&#8217;ll post below some code to make it work on the current release, but it requires an external function.</p>

	<p>So, in the next release, you can just do something like this:</p>

	<div class="posh code posh" style="font-family:monospace;"><span style="color: #0066cc; font-style: italic;">New-<span style="font-style: normal;">BootsWindow</span></span> <span style="color: #000066;">-FileTemplate</span> <span style="color: #660033; font-weight: bold;">$pwd</span>\MainWindow.<span style="color: #003366;">xaml</span> <span style="color: #000066;">-On_Loaded</span> <span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp;<span style="color: #0066cc; font-style: italic;">Register-<span style="font-style: normal;">BootsEvent</span></span> <span style="color: #000066;">-InputObject</span> <span style="color: #660033; font-weight: bold;">$Calculate</span> <span style="color: #000066;">-EventName</span> Click <span style="color: #000066;">-Action</span> <span style="color: #333;">&#123;</span> <br />
&nbsp; &nbsp; &nbsp; <span style="color: #660033; font-weight: bold;">$Total</span>.<span style="color: #003366;">Text</span> <span style="color: #66cc66;">=</span> <span style="color: #009900;">'${0:n2}'</span> <span style="color: #000066;">-f</span> <span style="color: #333;">&#40;</span><span style="color: #333;">&#40;</span><span style="color: #660033; font-weight: bold;">$Miles</span>.<span style="color: #003366;">Text</span> <span style="color: #000066;">-as</span> <span style="color: #003366; font-weight: bold;"><span style="color: #333;">&#91;</span><span style="color: #003366; font-weight: bold;">Double</span><span style="color: #333;">&#93;</span></span><span style="color: #333;">&#41;</span> <span style="color: #66cc66;">/</span> <span style="color: #333;">&#40;</span><span style="color: #660033; font-weight: bold;">$Mpg</span>.<span style="color: #003366;">Text</span> <span style="color: #000066;">-as</span> <span style="color: #003366; font-weight: bold;"><span style="color: #333;">&#91;</span><span style="color: #003366; font-weight: bold;">Double</span><span style="color: #333;">&#93;</span></span><span style="color: #333;">&#41;</span> <span style="color: #66cc66;">*</span> <span style="color: #333;">&#40;</span><span style="color: #660033; font-weight: bold;">$Cost</span>.<span style="color: #003366;">Text</span> <span style="color: #000066;">-as</span> <span style="color: #003366; font-weight: bold;"><span style="color: #333;">&#91;</span><span style="color: #003366; font-weight: bold;">Double</span><span style="color: #333;">&#93;</span></span><span style="color: #333;">&#41;</span><span style="color: #333;">&#41;</span><br />
&nbsp; &nbsp;<span style="color: #333;">&#125;</span><br />
<span style="color: #333;">&#125;</span></div>

	<p>The key thing you&#8217;re supposed to notice here is that the named controls in the <span class="caps">XAML</span> are automatically surfaced as variables in the event handlers, and all you have to do is write your logic and hook it up to the controls. We provide a <code>Register-BootsEvent</code> cmdlet which is like Register-ObjectEvent except that it executes the event handlers on the UI thread (so they can do things to the UI) instead of in a new runspace, but basically it&#8217;s like calling <code>Add_Click</code>. Of course, you <strong>can</strong> use Register-ObjectEvent if you just want to spin off PowerShell tasks that don&#8217;t read/write the UI.</p>

	<h3>Backwards compatibility</h3>

	<p>To get this to work in the current release, you need a function <code>Export-NamedControl</code> to create variables for each of those named controls as variables. Once you&#8217;ve defined that function, you can write code very much like I did before, but you have to <em>call Export-NamedControl yourself</em>, and you won&#8217;t have that Register-BootsEvent cmdlet. You don&#8217;t really need it for this anyway, so that&#8217;s not a big deal, at least in this case. Here&#8217;s the function. and the actual code to create the window.  You can just paste this into a script file:</p>

	<div class="posh code posh" style="font-family:monospace;"><span style="color: #666699; font-weight: bold;">function</span> global:<span style="color: #0066cc; font-style: italic;">Export-<span style="font-style: normal;">NamedControl</span></span> <span style="color: #333;">&#123;</span><br />
<span style="color: #333;">&#91;</span>CmdletBinding<span style="color: #333;">&#40;</span><span style="color: #333;">&#41;</span><span style="color: #333;">&#93;</span><br />
<span style="color: #666699; font-weight: bold;">param</span><span style="color: #333;">&#40;</span><br />
&nbsp; &nbsp;<span style="color: #333;">&#91;</span>Parameter<span style="color: #333;">&#40;</span>ValueFromPipeline<span style="color: #66cc66;">=</span><span style="color: #660033; font-weight: bold;">$true</span>, Position<span style="color: #66cc66;">=</span><span style="color: #cc66cc;">1</span>, Mandatory<span style="color: #66cc66;">=</span><span style="color: #660033; font-weight: bold;">$true</span><span style="color: #333;">&#41;</span><span style="color: #333;">&#93;</span><br />
&nbsp; &nbsp;<span style="color: #660033; font-weight: bold;">$Root</span> <span style="color: #66cc66;">=</span> <span style="color: #660033; font-weight: bold;">$BootsWindow</span><br />
<span style="color: #333;">&#41;</span><br />
<span style="color: #666699; font-weight: bold;">process</span> <span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp;<span style="color: #0066cc; font-style: italic;">Invoke-<span style="font-style: normal;">BootsWindow</span></span> <span style="color: #660033; font-weight: bold;">$Root</span> <span style="color: #333;">&#123;</span> <br />
&nbsp; &nbsp; &nbsp; <span style="color: #660033; font-weight: bold;">$control</span> <span style="color: #66cc66;">=</span> <span style="color: #660033; font-weight: bold;">$BootsWindow</span> <br />
&nbsp; &nbsp; &nbsp; <span style="color: #666699; font-weight: bold;">while</span><span style="color: #333;">&#40;</span><span style="color: #660033; font-weight: bold;">$control</span><span style="color: #333;">&#41;</span> <span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #660033; font-weight: bold;">$control</span> <span style="color: #66cc66;">=</span> <span style="color: #660033; font-weight: bold;">$control</span> <span style="color: #66cc66;">|</span> ForEach<span style="color: #66cc66;">-</span>Object <span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #660033; font-weight: bold;">$Element</span> <span style="color: #66cc66;">=</span> <span style="color: #660033; font-weight: bold;">$_</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666699; font-weight: bold;">if</span><span style="color: #333;">&#40;</span><span style="color: #66cc66;">!</span><span style="color: #660033; font-weight: bold;">$Element</span><span style="color: #333;">&#41;</span> <span style="color: #333;">&#123;</span> <span style="color: #666699; font-weight: bold;">return</span> <span style="color: #333;">&#125;</span><br />
&nbsp; &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066cc; font-style: italic;">Write-<span style="font-style: normal;">Verbose</span></span> <span style="color: #009900;">&quot;This $($Element.GetType().Name) is $Element&quot;</span><br />
&nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666699; font-weight: bold;">if</span><span style="color: #333;">&#40;</span><span style="color: #660033; font-weight: bold;">$Element</span>.<span style="color: #003366;">Name</span><span style="color: #333;">&#41;</span> <span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0066cc; font-style: italic;">Write-<span style="font-style: normal;">Verbose</span></span> <span style="color: #009900;">&quot;Defining $($Element.Name) = $Element&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0066cc; font-style: italic;">Set-<span style="font-style: normal;">Variable</span></span> <span style="color: #009900;">&quot;$($Element.Name)&quot;</span> <span style="color: #660033; font-weight: bold;">$Element</span> <span style="color: #000066;">-Scope</span> <span style="color: #cc66cc;">2</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #333;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">## Return all the child controls ...</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; @<span style="color: #333;">&#40;</span><span style="color: #660033; font-weight: bold;">$Element</span>.<span style="color: #003366;">Children</span><span style="color: #333;">&#41;</span> <span style="color: #66cc66;">+</span> @<span style="color: #333;">&#40;</span><span style="color: #660033; font-weight: bold;">$Element</span>.<span style="color: #003366;">Child</span><span style="color: #333;">&#41;</span> <span style="color: #66cc66;">+</span> @<span style="color: #333;">&#40;</span><span style="color: #660033; font-weight: bold;">$Element</span>.<span style="color: #003366;">Content</span><span style="color: #333;">&#41;</span> <span style="color: #66cc66;">+</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; @<span style="color: #333;">&#40;</span><span style="color: #660033; font-weight: bold;">$Element</span>.<span style="color: #003366;">Items</span><span style="color: #333;">&#41;</span> <span style="color: #66cc66;">+</span> @<span style="color: #333;">&#40;</span><span style="color: #660033; font-weight: bold;">$Element</span>.<span style="color: #003366;">Inlines</span><span style="color: #333;">&#41;</span> <span style="color: #66cc66;">+</span> @<span style="color: #333;">&#40;</span><span style="color: #660033; font-weight: bold;">$Element</span>.<span style="color: #003366;">Blocks</span><span style="color: #333;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #333;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #333;">&#125;</span><br />
&nbsp; &nbsp;<span style="color: #333;">&#125;</span><br />
<span style="color: #333;">&#125;</span><br />
<span style="color: #333;">&#125;</span><br />
<br />
<span style="color: #666666; font-style: italic;">####################################################################################################################</span><br />
<span style="color: #666666; font-style: italic;">## Create the window and hook the click. Make sure to use full paths</span><br />
<span style="color: #0066cc; font-style: italic;">New-<span style="font-style: normal;">BootsWindow</span></span> <span style="color: #333;">&#123;</span><span style="color: #333;">&#125;</span> <span style="color: #000066;">-FileTemplate</span> <span style="color: #660033; font-weight: bold;">$pwd</span>\MainWindow.<span style="color: #003366;">xaml</span> <span style="color: #000066;">-On_Loaded</span> <span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp;<span style="color: #0066cc; font-style: italic;">Export-<span style="font-style: normal;">NamedControl</span></span> <span style="color: #000066;">-Root</span> <span style="color: #660033; font-weight: bold;">$Args</span><span style="color: #333;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #333;">&#93;</span><br />
&nbsp; &nbsp;<span style="color: #660033; font-weight: bold;">$Calculate</span>.<span style="color: #003366;">Add_Click</span><span style="color: #333;">&#40;</span><span style="color: #333;">&#123;</span> <br />
&nbsp; &nbsp; &nbsp; <span style="color: #660033; font-weight: bold;">$Total</span>.<span style="color: #003366;">Text</span> <span style="color: #66cc66;">=</span> <span style="color: #009900;">'${0:n2}'</span> <span style="color: #000066;">-f</span> <span style="color: #333;">&#40;</span><span style="color: #333;">&#40;</span><span style="color: #660033; font-weight: bold;">$Miles</span>.<span style="color: #003366;">Text</span> <span style="color: #000066;">-as</span> <span style="color: #003366; font-weight: bold;"><span style="color: #333;">&#91;</span><span style="color: #003366; font-weight: bold;">Double</span><span style="color: #333;">&#93;</span></span><span style="color: #333;">&#41;</span> <span style="color: #66cc66;">/</span> <span style="color: #333;">&#40;</span><span style="color: #660033; font-weight: bold;">$Mpg</span>.<span style="color: #003366;">Text</span> <span style="color: #000066;">-as</span> <span style="color: #003366; font-weight: bold;"><span style="color: #333;">&#91;</span><span style="color: #003366; font-weight: bold;">Double</span><span style="color: #333;">&#93;</span></span><span style="color: #333;">&#41;</span> <span style="color: #66cc66;">*</span> <span style="color: #333;">&#40;</span><span style="color: #660033; font-weight: bold;">$Cost</span>.<span style="color: #003366;">Text</span> <span style="color: #000066;">-as</span> <span style="color: #003366; font-weight: bold;"><span style="color: #333;">&#91;</span><span style="color: #003366; font-weight: bold;">Double</span><span style="color: #333;">&#93;</span></span><span style="color: #333;">&#41;</span><span style="color: #333;">&#41;</span><br />
&nbsp; &nbsp;<span style="color: #333;">&#125;</span><span style="color: #333;">&#41;</span><br />
<span style="color: #333;">&#125;</span></div>

	<p>And in order to try <strong>my</strong> demo, you&#8217;re going to need that MainWindow.xaml file:</p>

	<div class="xml code xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Window</span> <span style="color: #000066;">xmlns</span>=<span style="color: #ff0000;">&quot;http://schemas.microsoft.com/winfx/2006/xaml/presentation&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">xmlns:x</span>=<span style="color: #ff0000;">&quot;http://schemas.microsoft.com/winfx/2006/xaml&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">Title</span>=<span style="color: #ff0000;">&quot;Trip Cost&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Grid<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Grid.RowDefinitions<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;RowDefinition</span> <span style="color: #000066;">Height</span>=<span style="color: #ff0000;">&quot;28&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;RowDefinition</span> <span style="color: #000066;">Height</span>=<span style="color: #ff0000;">&quot;28&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;RowDefinition</span> <span style="color: #000066;">Height</span>=<span style="color: #ff0000;">&quot;28&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;RowDefinition</span> <span style="color: #000066;">Height</span>=<span style="color: #ff0000;">&quot;28&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Grid.RowDefinitions<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Grid.ColumnDefinitions<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;ColumnDefinition</span> <span style="color: #000066;">Width</span>=<span style="color: #ff0000;">&quot;110&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;ColumnDefinition</span> <span style="color: #000066;">Width</span>=<span style="color: #ff0000;">&quot;*&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Grid.ColumnDefinitions<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Label</span> <span style="color: #000066;">Content</span>=<span style="color: #ff0000;">&quot;Miles&quot;</span> <span style="color: #000066;">VerticalAlignment</span>=<span style="color: #ff0000;">&quot;Top&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;TextBox</span> <span style="color: #000066;">Grid.Column</span>=<span style="color: #ff0000;">&quot;1&quot;</span> <span style="color: #000066;">Height</span>=<span style="color: #ff0000;">&quot;23&quot;</span> <span style="color: #000066;">Width</span>=<span style="color: #ff0000;">&quot;200&quot;</span> <span style="color: #000066;">Name</span>=<span style="color: #ff0000;">&quot;miles&quot;</span> <span style="color: #000066;">HorizontalAlignment</span>=<span style="color: #ff0000;">&quot;Stretch&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Label</span> <span style="color: #000066;">Grid.Row</span>=<span style="color: #ff0000;">&quot;1&quot;</span> <span style="color: #000066;">Content</span>=<span style="color: #ff0000;">&quot;Miles per Gallon&quot;</span> <span style="color: #000066;">VerticalAlignment</span>=<span style="color: #ff0000;">&quot;Top&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;TextBox</span> <span style="color: #000066;">Grid.Column</span>=<span style="color: #ff0000;">&quot;1&quot;</span> <span style="color: #000066;">Grid.Row</span>=<span style="color: #ff0000;">&quot;1&quot;</span> <span style="color: #000066;">Height</span>=<span style="color: #ff0000;">&quot;23&quot;</span> <span style="color: #000066;">Width</span>=<span style="color: #ff0000;">&quot;200&quot;</span> <span style="color: #000066;">HorizontalAlignment</span>=<span style="color: #ff0000;">&quot;Stretch&quot;</span> <span style="color: #000066;">Name</span>=<span style="color: #ff0000;">&quot;mpg&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Label</span> <span style="color: #000066;">Grid.Row</span>=<span style="color: #ff0000;">&quot;2&quot;</span> <span style="color: #000066;">Content</span>=<span style="color: #ff0000;">&quot;Cost per Gallon&quot;</span> &nbsp;<span style="color: #000066;">VerticalAlignment</span>=<span style="color: #ff0000;">&quot;Top&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;TextBox</span> <span style="color: #000066;">Grid.Column</span>=<span style="color: #ff0000;">&quot;1&quot;</span> <span style="color: #000066;">Grid.Row</span>=<span style="color: #ff0000;">&quot;2&quot;</span> <span style="color: #000066;">Height</span>=<span style="color: #ff0000;">&quot;23&quot;</span> <span style="color: #000066;">Width</span>=<span style="color: #ff0000;">&quot;200&quot;</span> <span style="color: #000066;">HorizontalAlignment</span>=<span style="color: #ff0000;">&quot;Stretch&quot;</span> <span style="color: #000066;">Name</span>=<span style="color: #ff0000;">&quot;cost&quot;</span> &nbsp;<span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Button</span> <span style="color: #000066;">Name</span>=<span style="color: #ff0000;">&quot;calculate&quot;</span> <span style="color: #000066;">Grid.Row</span>=<span style="color: #ff0000;">&quot;3&quot;</span> <span style="color: #000066;">Content</span>=<span style="color: #ff0000;">&quot;_Calculate&quot;</span> <span style="color: #000066;">HorizontalAlignment</span>=<span style="color: #ff0000;">&quot;Center&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;TextBlock</span> <span style="color: #000066;">Grid.Column</span>=<span style="color: #ff0000;">&quot;1&quot;</span> <span style="color: #000066;">Grid.Row</span>=<span style="color: #ff0000;">&quot;3&quot;</span> <span style="color: #000066;">Height</span>=<span style="color: #ff0000;">&quot;23&quot;</span> <span style="color: #000066;">Width</span>=<span style="color: #ff0000;">&quot;200&quot;</span> <span style="color: #000066;">HorizontalAlignment</span>=<span style="color: #ff0000;">&quot;Stretch&quot;</span> <span style="color: #000066;">Name</span>=<span style="color: #ff0000;">&quot;total&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Grid<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Window<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></div>]]></content:encoded>
			<wfw:commentRss>http://joelbennett.net/creating-wpf-uis-for-powershell-with-powerboots-and-visual-studio-wpf-designer/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>WPF in PowerShell: PowerBoots 0.2</title>
		<link>http://joelbennett.net/wpf-in-powershell-powerboots-02/</link>
		<comments>http://joelbennett.net/wpf-in-powershell-powerboots-02/#comments</comments>
		<pubDate>Thu, 18 Jun 2009 04:14:54 +0000</pubDate>
		<dc:creator>Joel 'Jaykul' Bennett</dc:creator>
				<category><![CDATA[Huddled]]></category>
		<category><![CDATA[PowerBoots]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[WPF]]></category>

		<guid isPermaLink="false">http://huddledmasses.org/?p=1183</guid>
		<description><![CDATA[I&#8217;ve finally given over trying to improve PowerBoots for this iteration of development, and in between setting up the ScriptingGames.PoshCode site and releasing the PoshCode software on the main PoshCode.org site (it&#8217;s coming, I promise), I decided to take a few minutes and release this lates PowerBoots, and it&#8217;s a ground-breaking release, if I do [...]]]></description>
			<content:encoded><![CDATA[	<p>I&#8217;ve finally given over trying to improve PowerBoots for this iteration of development, and in between setting up the <a href="http://scriptinggames.poshcode.org">ScriptingGames.PoshCode</a> site and releasing the PoshCode software on the main PoshCode.org site (it&#8217;s coming, I promise), I decided to take a few minutes and release this lates PowerBoots, and it&#8217;s a <a href="http://powerboots.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=28954">ground-breaking release</a>, if I do say so myself!</p>

	<h3>PowerShell 1.0 Compatibility</h3>

	<p>There are three huge changes in this release, actually. But the biggest one is that <em>most</em> of the functionality works in the released version of PowerShell 1.0!  There are still a few glitches and bugs when it&#8217;s running in 1.0, but I&#8217;ve decided it&#8217;s past time I just release it and let you start using it!  If you use it on 1.0, please let me know if you run into anything weird, or problems you can&#8217;t figure out workarounds for.</p>

	<h3>Cached Script Functions!</h3>

	<p>The second biggest change is that all of the functions are now cached. The first time it&#8217;s loaded, PowerBoots actually writes out a few hundred scripts files into a &#8220;Functions&#8221; subfolder, and from then on, they&#8217;re only loaded when they&#8217;re used &#8212; saving you <em>a lot</em> of time at startup, and <em>a lot</em> of memory.  Additionally, when you load in additional controls, such as the <a href="http://www.visifire.com/">Visifire <span class="caps">WPF</span> chart controls</a>, those functions are cached permanently too, so you never even have to manually load the assembly again!</p>

	<h3>Dependency Properties</h3>

	<p>A few people have asked over the last few months about how to <a href="http://huddledmasses.org/powerboots-and-attached-properties/">set attached properties and dependency properties in <span class="caps">WPF</span> from PowerShell</a>, so in this release I&#8217;ve included full support for these in a way that will, I hope, simply work so well it will boggle your mind  <img src='http://joelbennett.net/wordpress/wp-includes/' alt=':)' class='wp-smiley' />  All you have to do to tell a control, for instance, to be in the 3rd column of a grid is to just pass <code>Button &#34;Click Me&#34; -&#34;Grid:Column&#34; 2</code> &#8230; it&#8217;s <span class="caps">THAT</span> simple. In fact, for properties that have unique names, you don&#8217;t even have to specify the type, just the name, like <code>-Row 3</code> to specify the grid row.</p>

	<h3>Regression and Backwards Compatibility </h3>

	<p>Of course, the downside of these changes is that some of the syntax has changed a little bit. All scripts and event handlers (ie: click handlers for <span class="caps">WPF</span> Buttons) are run from the <strong>dll</strong> module scope in PowerShell 2 (the global scope in PowerShell 1), which means that they can&#8217;t access &#8220;script&#8221; scope variables from your scripts (which ends up meaning you have to declare a lot of things global that you could leave in script scope before).  Just to be clear on the quality of this release: once we have ironed out the minor problems we&#8217;re having with PowerShell 1.0 in a way that I&#8217;m comfortable with, I expect to push the version number up and release an 1.0 Release Candidate, barring any major issues.</p>

	<p>In order to help with the transition, I&#8217;ve included a Samples.ps1 script which has 28 sample scripts in it (mostly from the original <a href="http://huddledmasses.org/powerboots-tutorial-walkthrough/">Tutorial Walk-through</a>, which I will update soon).  I&#8217;ve updated each of them to work with this release, in both PowerShell 1 and PowerShell 2 (which means they&#8217;re almost all written in PowerShell 1 syntax), so you can use them as good examples of how to get things done!</p>

	<p>Please use the Discussions Forum and Issue Tracker on <a href="http://boots.CodePlex.org">the CodePlex site</a> to post any problems you have, and I&#8217;ll try to write up a few more posts describing changes and differences in the next couple of weeks.</p>

<h6 class="zemanta-related-title">Related articles by Zemanta</h6><ul class="zemanta-article-ul"><li class="zemanta-article-ul-li"><a href="http://huddledmasses.org/powerboots-loading-xaml-windows-in-powershell-10-or-20/">PowerBoots: Loading <span class="caps">XAML</span> Windows in PowerShell 1.0 or 2.0</a> (huddledmasses.org)</li><li class="zemanta-article-ul-li"><a href="http://huddledmasses.org/powerboots-now-multi-threaded/">PowerBoots: PowerShell GUIs are now multi-threading</a> (huddledmasses.org)</li><li class="zemanta-article-ul-li"><a href="http://huddledmasses.org/pingmonitor-interactive-wpf-uis-from-powershell-10-or-20/">PingMonitor: interactive <span class="caps">WPF</span> UIs from PowerShell (1.0 or 2.0)</a> (huddledmasses.org)</li></ul>

<div class="zemanta-pixie"><a class="zemanta-pixie-a" href="http://reblog.zemanta.com/zemified/3373c251-af5f-4875-a3fa-7f0c2581d019/" title="Reblog this post [with Zemanta]"><img class="zemanta-pixie-img" src="http://img.zemanta.com/reblog_e.png?x-id=3373c251-af5f-4875-a3fa-7f0c2581d019" alt="Reblog this post [with Zemanta]" /></a><span class="zem-script more-related pretty-attribution"><script type="text/javascript" src="http://static.zemanta.com/readside/loader.js" defer="defer"></script></span></div>]]></content:encoded>
			<wfw:commentRss>http://joelbennett.net/wpf-in-powershell-powerboots-02/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>PowerBoots: The tutorial walkthrough</title>
		<link>http://joelbennett.net/powerboots-tutorial-walkthrough/</link>
		<comments>http://joelbennett.net/powerboots-tutorial-walkthrough/#comments</comments>
		<pubDate>Thu, 02 Apr 2009 16:21:13 +0000</pubDate>
		<dc:creator>Joel 'Jaykul' Bennett</dc:creator>
				<category><![CDATA[Huddled]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[GUI]]></category>
		<category><![CDATA[PowerBoots]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[PowerTips]]></category>
		<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[WalkThrough]]></category>
		<category><![CDATA[WPF]]></category>

		<guid isPermaLink="false">http://huddledmasses.org/?p=963</guid>
		<description><![CDATA[Updated to PowerBoots 0.1 An introduction to PowerBoots Please excuse me if I start by just copying the basic ideas of the Shoes Tutorial, but I figured that since PowerBoots is inspired by Shoes, that was as good a place as any to start. PowerBoots (or just &#8220;Boots&#8221;) is a PowerShell 2.0 module with functions [...]]]></description>
			<content:encoded><![CDATA[	<h3> <img src='http://joelbennett.net/wordpress/wp-includes/' alt='[new]' class='wp-smiley' />  Updated to PowerBoots 0.1</h3>

	<h2>An introduction to PowerBoots</h2>

	<p>Please excuse me if I start by just copying the basic ideas of the <a href="http://shoooes.net/tutorial/">Shoes Tutorial</a>, but I figured that since PowerBoots is inspired by Shoes, that was as good a place as any to start.  PowerBoots (or just &#8220;Boots&#8221;) is a PowerShell 2.0 module with functions for writing Windows Presentation Framework (<span class="caps">WPF</span>) applications in the PowerShell scripting language.  You should get <a href="http://boots.CodePlex.com">the latest version of PowerBoots</a> before continuing, and install it by putting the &#8220;PowerBoots&#8221; folder in one of your &#8220;Modules&#8221; folders (list them by typing <code>$Env:PSMODULEPATH</code> in PowerShell v2). </p>

	<p><del>Don&#8217;t forget to start PowerShell.exe with the <span class="caps">STA</span> parameter</del> (This is no longer required in PowerBoots 0.1).</p>

	<p>Did I hear someone ask <strong>what <em>is</em> WPF?</strong> It was introduced as part of .Net 3.0 (and vastly improved in .Net 3.5), so you can expect to find it preinstalled on computers from Vista on, and of course you can download and install it on XP if it&#8217;s not already installed.  The only thing you really need to know about <span class="caps">WPF</span> for the purposes of this tutorial is that it is <strong>the</strong> new <span class="caps">GUI</span> toolkit for .Net, and that it is container based &#8212; you put elements into other elements to control the layout, rather like <span class="caps">HTML</span> and Java Swing&#8230; you can <strong>pick up the rest as we go along</strong>.</p>

	<h2>A simple Boots program</h2>

	<p><img src="http://huddledmasses.org/images/PowerBoots/PowerBoots1.png" class="float-right-block" alt="" width="144" height="86" /></p>

	<div class="posh code posh" style="font-family:monospace;"><br />
<span style="color: #0066cc; font-style: italic;">New-<span style="font-style: normal;">BootsWindow</span></span> <span style="color: #000066;">-SizeToContent</span> WidthAndHeight <span style="color: #000066;">-Content</span> <span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp;Button <span style="color: #000066;">-Content</span> <span style="color: #009900;">&quot;Push Me&quot;</span> <br />
<span style="color: #333;">&#125;</span><br />
&nbsp;</div>

	<p>I&#8217;ve recently <strong>changed</strong> this first example to pass a script block to the content instead of using parentheses, because although PowerBoots supports running in an <span class="caps">MTA</span> PowerShell host, the only UI-creation command that is MTA-safe is the New-BootsWindow command. All of the &#8220;new&#8221; functions must then be inside of a scriptblock which is passed to the New-BootsWindow cmdlet and executed on that <span class="caps">STA</span> thread. You can use parenthesis ( and ) as a container instead, but that requires the host to be in <span class="caps">STA</span> threading mode (run: PowerShell -<span class="caps">STA</span>) so the controls can be created:</p>

	<div class="posh code posh" style="font-family:monospace;"><br />
<span style="color: #0066cc; font-style: italic;">New-<span style="font-style: normal;">BootsWindow</span></span> <span style="color: #000066;">-SizeToContent</span> WidthAndHeight <span style="color: #000066;">-Content</span> <span style="color: #333;">&#40;</span> <br />
&nbsp; &nbsp;Button <span style="color: #000066;">-Content</span> <span style="color: #009900;">&quot;Push Me&quot;</span><br />
<span style="color: #333;">&#41;</span><br />
&nbsp;</div>

	<p>This first example is a bit uglier than the Shoes syntax, so lets see if we can&#8217;t clean it up some. The <code>-Content</code> parameter is positional, so the first non-named argument you pass will be used for that. The same is true for the -Children parameter of panels, and in fact, each of the other similar parameters: Items, Blocks, and Inlines.</p>

	<p>We have used a function <code>New-BootsWindow</code> which has an alias <code>Boots</code>. Boots takes all the same parameters as the <code>Window</code> function mentioned previously, but it uses slightly more useful defaults, and has a few other major benefits as well, the first of which is that it automatically &#8220;shows&#8221; the window, and the second is that it supports an <code>-Async</code> parameter which allows the window to come out in a new thread so that you can continue using PowerShell while the window remains alive and responsive.  There is one catch: New-BootsWindow <em>cannot</em> take it&#8217;s content on the pipeline (the <em>old function</em>, now renamed &#8220;Out-BootsWindow&#8221; can take pipeline content, but is a script function, and requires -<span class="caps">STA</span> mode) &#8212; you have to specify it as a ScriptBlock. So now that we know this, we can rewrite our first example like this:</p>

	<div class="posh code posh" style="font-family:monospace;"><br />
Boots <span style="color: #333;">&#123;</span> Button <span style="color: #009900;">&quot;Push Me&quot;</span> <span style="color: #333;">&#125;</span><br />
&nbsp;</div>

	<p>Just for the record, the simplest Boots program would just be a simple popup dialog to put some text in a Window, like:  <code>Boots { $msg }</code> &#8230;</p>

	<h2>We can put controls in a stack</h2>

	<p><img src="http://huddledmasses.org/images/PowerBoots/PowerBoots2.png" class="float-right-block" alt="" width="156" height="128" /></p>

	<div class="posh code posh" style="font-family:monospace;"><br />
Boots <span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp;StackPanel <span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; Button <span style="color: #009900;">&quot;A bed of clams&quot;</span><br />
&nbsp; &nbsp; &nbsp; Button <span style="color: #009900;">&quot;A coalition of cheetas&quot;</span><br />
&nbsp; &nbsp; &nbsp; Button <span style="color: #009900;">&quot;A gulp of swallows&quot;</span><br />
&nbsp; &nbsp;<span style="color: #333;">&#125;</span><br />
<span style="color: #333;">&#125;</span><br />
&nbsp;</div>

	<p>StackPanels are awesome. So are WrapPanels.  Try that code with a WrapPanel instead of a StackPanel and see what the difference is.  This brings up another point: those positional parameters we mentioned earlier: Content, Children, Items, Blocks, and Inlines, are also set to accept the value from the pipeline.  Not only that, but they are intelligent about whether or not the content model accepts multiple items! So we can actually rewrite that script like this, and get the same results:</p>

	<div class="posh code posh" style="font-family:monospace;"><br />
Boots <span style="color: #333;">&#123;</span> <span style="color: #009900;">&quot;A bed of clams&quot;</span>, <span style="color: #009900;">&quot;A coalition of cheetas&quot;</span>, <span style="color: #009900;">&quot;A gulp of swallows&quot;</span> <span style="color: #66cc66;">|</span> Button <span style="color: #66cc66;">|</span> StackPanel <span style="color: #333;">&#125;</span><br />
&nbsp;</div>

	<p>Now we&#8217;re really onto something! <span id="more-963"></span> For most of the rest of these examples, I&#8217;m going to stick with the former syntax, because with the indenting and parenthesis, it&#8217;s much easier for you to follow, especially if you&#8217;re not already familiar with <span class="caps">WPF</span>.  For instance, check out what this does:</p>

	<div class="posh code posh" style="font-family:monospace;"><br />
Boots <span style="color: #333;">&#123;</span> <span style="color: #009900;">&quot;A bed of clams&quot;</span>, <span style="color: #009900;">&quot;A coalition of cheetas&quot;</span>, <span style="color: #009900;">&quot;A gulp of swallows&quot;</span> <span style="color: #66cc66;">|</span> StackPanel <span style="color: #66cc66;">|</span> Button <span style="color: #333;">&#125;</span><br />
&nbsp;</div>

	<h2>Ok, lets see some formatting</h2>

	<p><img src="http://huddledmasses.org/images/PowerBoots/PowerBoots3.png" class="float-right-block" alt="" width="174" height="152" /></p>

	<p>To scoot the buttons out from the edge we can use margins or padding: margins go on the outside of containers, padding goes on the inside.</p>

	<div class="posh code posh" style="font-family:monospace;"><br />
Boots <span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp;StackPanel <span style="color: #000066;">-Margin</span> <span style="color: #cc66cc;">5</span> <span style="color: #000066;">-Background</span> Pink $<span style="color: #333;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; Button <span style="color: #000066;">-Margin</span> <span style="color: #cc66cc;">2</span> <span style="color: #009900;">&quot;A bed of clams&quot;</span><br />
&nbsp; &nbsp; &nbsp; Button <span style="color: #000066;">-Margin</span> <span style="color: #cc66cc;">2</span> <span style="color: #009900;">&quot;A coalition of cheetas&quot;</span><br />
&nbsp; &nbsp; &nbsp; Button <span style="color: #000066;">-Margin</span> <span style="color: #cc66cc;">2</span> <span style="color: #009900;">&quot;A gulp of swallows&quot;</span><br />
&nbsp; &nbsp;<span style="color: #333;">&#41;</span><br />
<span style="color: #333;">&#125;</span><br />
<br />
<span style="color: #666666; font-style: italic;">## Or, on one line:</span><br />
<br />
Boots <span style="color: #333;">&#123;</span> <span style="color: #009900;">&quot;A bed of clams&quot;</span>, <span style="color: #009900;">&quot;A coalition of cheetas&quot;</span>, <span style="color: #009900;">&quot;A gulp of swallows&quot;</span> <span style="color: #66cc66;">|</span><br />
&nbsp; &nbsp;Button <span style="color: #000066;">-Margin</span> <span style="color: #cc66cc;">2</span> <span style="color: #66cc66;">|</span> StackPanel <span style="color: #000066;">-Margin</span> <span style="color: #cc66cc;">5</span> <span style="color: #000066;">-Background</span> Pink <span style="color: #333;">&#125;</span><br />
&nbsp;</div>

	<p>So you see, the pink background is on the StackPanel, which has a (white) margin around it.  If you wanted the whole background of the window to be pink, you would need to set the background of the Window instead of the StackPanel.</p>

	<h2>Time for some artwork</h2>

	<p><img src="http://huddledmasses.org/images/PowerBoots/PowerBoots4.png" class="float-right-block" alt="" width="176" height="164" /></p>

	<div class="posh code posh" style="font-family:monospace;"><br />
Boots <span style="color: #333;">&#123;</span> Ellipse <span style="color: #000066;">-Width</span> <span style="color: #cc66cc;">60</span> <span style="color: #000066;">-Height</span> <span style="color: #cc66cc;">80</span> <span style="color: #000066;">-Margin</span> <span style="color: #009900;">&quot;20,10,60,20&quot;</span> <span style="color: #000066;">-Fill</span> Black <span style="color: #333;">&#125;</span><br />
&nbsp;</div>

	<p>In Boots, everything always starts out white, and you must position things based on the container. You can see that the Margin can be specified as a single value as in the previous example, or as separate values for Left, Top, Right, Bottom.  Oddly, to satisfy PowerShell&#8217;s type-casting, you have to quote them so they&#8217;re a single comma-separated string, instead of four separate values.</p>

	<h2>Some more advanced drawing</h2>

	<p><img src="http://huddledmasses.org/images/PowerBoots/PowerBoots5.png" class="float-right-block" alt="" width="148" height="158" /></p>

	<div class="posh code posh" style="font-family:monospace;"><br />
Boots <span style="color: #333;">&#123;</span><br />
Canvas <span style="color: #000066;">-Height</span> <span style="color: #cc66cc;">100</span> <span style="color: #000066;">-Width</span> <span style="color: #cc66cc;">100</span> <span style="color: #000066;">-Children</span> $<span style="color: #333;">&#40;</span><br />
&nbsp; &nbsp;Rectangle <span style="color: #000066;">-Margin</span> <span style="color: #009900;">&quot;10,10,0,0&quot;</span> <span style="color: #000066;">-Width</span> <span style="color: #cc66cc;">45</span> <span style="color: #000066;">-Height</span> <span style="color: #cc66cc;">45</span> <span style="color: #000066;">-Stroke</span> Purple <span style="color: #000066;">-StrokeThickness</span> <span style="color: #cc66cc;">2</span> <span style="color: #000066;">-Fill</span> Red<br />
&nbsp; &nbsp;Polygon <span style="color: #000066;">-Stroke</span> Pink <span style="color: #000066;">-StrokeThickness</span> <span style="color: #cc66cc;">2</span> <span style="color: #000066;">-Fill</span> DarkRed <span style="color: #000066;">-Points</span> <span style="color: #009900;">&quot;10,60&quot;</span>, <span style="color: #009900;">&quot;50,60&quot;</span>, <span style="color: #009900;">&quot;50,50&quot;</span>, <span style="color: #009900;">&quot;65,65&quot;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #009900;">&quot;50,80&quot;</span>, <span style="color: #009900;">&quot;50,70&quot;</span>, <span style="color: #009900;">&quot;10,70&quot;</span>, <span style="color: #009900;">&quot;10,60&quot;</span> <br />
<span style="color: #333;">&#41;</span> <span style="color: #333;">&#125;</span><br />
&nbsp;</div>

	<p>We use a Canvas for this because it can contain multiple items which are all absolutely positioned.  Unlike other containers, it doesn&#8217;t automatically expand to contain it&#8217;s children, so you typically have to set it&#8217;s size.</p>

	<p>We also have to set the Stroke and Fill.  These are the two colors that make up every object, if we don&#8217;t set them, they default to white. The StrokeThickness controls the line thickness.  Notice that we positioned the Rectangle by using the <code>Margin</code>, and positioned the arrow, which we built using a Polygon, based purely on the x,y coordinates of the points.  The available shapes are Ellipse, Line, Path, Polygon, Polyline, and Rectangle.  You can, of course, make any shape you want to with the Polygon.</p>

	<p>There are other more advanced shapes available in external libraries, and we can even do 3D, use gradient or image fills&#8230;</p>

	<h3>We can even get images straight off the web</h3>

	<div class="posh code posh" style="font-family:monospace;"><br />
Boots <span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp;Image <span style="color: #000066;">-Source</span> http:<span style="color: #66cc66;">//</span>huddledmasses.<span style="color: #003366;">org</span><span style="color: #66cc66;">/</span>images<span style="color: #66cc66;">/</span>PowerBoots<span style="color: #66cc66;">/</span>IMG_3298.<span style="color: #003366;">jpg</span> <span style="color: #000066;">-MaxWidth</span> <span style="color: #cc66cc;">400</span> <span style="color: #66cc66;">|</span> <br />
<span style="color: #333;">&#125;</span> <span style="color: #000066;">-Title</span> <span style="color: #009900;">&quot;Now those are some powerful boots!&quot;</span> <span style="color: #000066;">-Async</span><br />
&nbsp;</div>

	<p><img src="http://huddledmasses.org/images/PowerBoots/PowerBoots6.png" class="float-right-block" alt="" width="436" height="730" /></p>

	<p>Boots loads the image on a background thread, and caches it in memory, so the window will show up and be responsive while you&#8217;re waiting for the image, and because we&#8217;ve specified <code>-Async</code>, you can actually continue using PowerShell while the image loads. Note: it will load much faster the second time you run that script.  <img src='http://joelbennett.net/wordpress/wp-includes/' alt=';)' class='wp-smiley' /> </p>

<h3 style="clear: both;">Typography</h3>

	<p>PowerBoots doesn&#8217;t try to create a full set of typography-specific top-level elements the way Shoes does, because we are based on <span class="caps">WPF</span>, which has a far more powerful typography system available than any we&#8217;ve ever used.  So instead of having a bunch of named elements like banner, and title, and caption, and para and whatnot, we have controls based on how much text you want to put in them, and how much formatting you want to apply: Label is simplest, TextBlock supports limited text formattings, and FlowDocument supports full rich content. And of course, Hyperlink supports clicking  <img src='http://joelbennett.net/wordpress/wp-includes/' alt=';)' class='wp-smiley' /> </p>

	<p><img src="http://huddledmasses.org/images/PowerBoots/PowerBoots7.png" class="float-right-block" alt="" width="466" height="202" /></p>

	<p>For the typography elements, the content model changes a bit.  There are basically two types: Inline and Block elements. The <a href="http://msdn.microsoft.com/en-us/library/bb613554.aspx">TextBlock Content Model</a> is similar to that of a FlowDocument, it is actually a type-restricted &#8220;Items&#8221; container.  Instead of being able to have <em>anything</em> as content, it can only contain <a href="http://msdn.microsoft.com/en-us/library/system.windows.documents.inline.aspx">Inline</a> flow content elements such as <a href="http://msdn.microsoft.com/en-us/library/system.windows.documents.anchoredblock.aspx">AnchoredBlock</a>, <a href="http://msdn.microsoft.com/en-us/library/system.windows.documents.bold.aspx">Bold</a>, <a href="http://msdn.microsoft.com/en-us/library/system.windows.documents.hyperlink.aspx">Hyperlink</a>, <a href="http://msdn.microsoft.com/en-us/library/system.windows.documents.inlineuicontainer.aspx">InlineUIContainer</a>, <a href="http://msdn.microsoft.com/en-us/library/system.windows.documents.italic.aspx">Italic</a>, <a href="http://msdn.microsoft.com/en-us/library/system.windows.documents.linebreak.aspx">LineBreak</a>, <a href="http://msdn.microsoft.com/en-us/library/system.windows.documents.run.aspx">Run</a>, <a href="http://msdn.microsoft.com/en-us/library/system.windows.documents.span.aspx">Span</a>, and <a href="http://msdn.microsoft.com/en-us/library/system.windows.documents.underline.aspx">Underline</a>, and it will create a run automatically if you just put a text string in it. </p>

	<div class="posh code posh" style="font-family:monospace;"><br />
Boots <span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp;StackPanel <span style="color: #000066;">-Margin</span> <span style="color: #cc66cc;">10</span> <span style="color: #000066;">-Children</span> $<span style="color: #333;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; TextBlock <span style="color: #009900;">&quot;A Question&quot;</span> <span style="color: #000066;">-FontSize</span> <span style="color: #cc66cc;">42</span> <span style="color: #000066;">-FontWeight</span> Bold <span style="color: #000066;">-Foreground</span> <span style="color: #009900;">&quot;#FF0088&quot;</span> <br />
&nbsp; &nbsp; &nbsp; TextBlock <span style="color: #000066;">-FontSize</span> <span style="color: #cc66cc;">24</span> <span style="color: #000066;">-Inlines</span> $<span style="color: #333;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Bold <span style="color: #009900;">&quot;Q. &quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #009900;">&quot;Are you starting to dig &quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Hyperlink <span style="color: #009900;">&quot;PowerBoots?&quot;</span> <span style="color: #000066;">-NavigateUri</span> http:<span style="color: #66cc66;">//</span>huddledmasses.<span style="color: #003366;">org</span><span style="color: #66cc66;">/</span>tag<span style="color: #66cc66;">/</span>powerboots<span style="color: #66cc66;">/</span> `<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">-On_RequestNavigate</span> <span style="color: #333;">&#123;</span> <span style="color: #003366; font-weight: bold;"><span style="color: #333;">&#91;</span>Diagnostics.<span style="color: #666699; font-weight: bold;">Process</span><span style="color: #333;">&#93;</span></span>::<span style="color: #660033;">Start</span><span style="color: #333;">&#40;</span> <span style="color: #660033; font-weight: bold;">$this</span>.<span style="color: #003366;">NavigateUri</span> <span style="color: #333;">&#41;</span> <span style="color: #333;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #333;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; TextBlock <span style="color: #000066;">-FontSize</span> <span style="color: #cc66cc;">16</span> <span style="color: #000066;">-Inlines</span> $<span style="color: #333;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Span <span style="color: #000066;">-FontSize</span> <span style="color: #cc66cc;">24</span> <span style="color: #000066;">-FontWeight</span> Bold <span style="color: #000066;">-Inlines</span> <span style="color: #009900;">&quot;A. &quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #009900;">&quot;Leave me alone, I'm hacking here!&quot;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #333;">&#41;</span><br />
<span style="color: #333;">&#41;</span><br />
<span style="color: #333;">&#125;</span><br />
&nbsp;</div>

	<p>Note: If you want support for the full <a href="http://msdn.microsoft.com/en-us/library/aa970909.aspx">document model</a> (which allows Paragraphs and Lists), you need to use a <a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.flowdocumentreader.aspx">FlowDocumentReader</a>, <a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.flowdocumentpageviewer.aspx">FlowDocumentPageViewer</a>, <a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.richtextbox.aspx">RichTextBox</a>, or a <a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.flowdocumentscrollviewer.aspx">FlowDocumentScrollViewer</a> ... there&#8217;s lots more information about those <a href="http://msdn.microsoft.com/en-us/library/aa970909.aspx">on msdn</a>.</p>

	<h3>Events</h3>

	<p>If you were paying attention to that previous example, you&#8217;ll notice we just introduced event handling. Event handlers in PowerBoots are specified in much the same way that Properties are.  Their parameter names always start with &#8220;On_&#8221; and they take a script block.  The Hyperlink element in a <span class="caps">WPF</span> window doesn&#8217;t automatically open a browser (because you can use it to change &#8220;pages&#8221; in a <span class="caps">WPF</span> application), so to make simple web links work, you have to handle the &#8220;RequestNavigate&#8221; event as shown above.</p>

	<p><img src="http://huddledmasses.org/images/PowerBoots/PowerBoots8.png" class="float-right-block" alt="" width="202" height="76" /></p>

	<p>In order to update your user interface when an event triggers, you&#8217;ll need to have a variable that points at the control(s) you want to affect.  You get a <code>$this</code> variable for free which points at the object that caused the event (eg: the Hyperlink in our previous example), but otherwise you need to handle this yourself. You can do that one of two ways: you can set a variable the way you normally would, and then use the variable in the form, or you can specify the variable name using the <code>-OutVariable</code> parameter.  Personally I prefer the latter, as it messes up the flow of code less, but it has the downside that the output variable is always an array, even when there&#8217;s only one item.</p>

	<div class="posh code posh" style="font-family:monospace;"><br />
Boots <span style="color: #333;">&#123;</span> <br />
&nbsp; &nbsp;<span style="color: #660033; font-weight: bold;">$global</span>:Count <span style="color: #66cc66;">=</span> <span style="color: #cc66cc;">0</span><br />
&nbsp; &nbsp;WrapPanel &nbsp;$<span style="color: #333;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; Button <span style="color: #009900;">&quot;Push Me&quot;</span> <span style="color: #000066;">-On_Click</span> <span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #660033; font-weight: bold;">$global</span>:Count<span style="color: #66cc66;">++</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #660033; font-weight: bold;">$label</span>.<span style="color: #003366;">Content</span> <span style="color: #66cc66;">=</span> <span style="color: #009900;">&quot;You clicked the button ${global:Count} times!&quot;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #333;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #660033; font-weight: bold;">$script</span>:label <span style="color: #66cc66;">=</span> Label <span style="color: #009900;">&quot;Nothing pushed so far&quot;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #660033; font-weight: bold;">$label</span> <span style="color: #666666; font-style: italic;"># You have to actually write-output the label</span><br />
&nbsp; &nbsp;<span style="color: #333;">&#41;</span><br />
<span style="color: #333;">&#125;</span> <span style="color: #000066;">-Title</span> <span style="color: #009900;">&quot;Test App&quot;</span> <span style="color: #000066;">-On_Closing</span> <span style="color: #333;">&#123;</span> <span style="color: #660033; font-weight: bold;">$global</span>:BootsOutput <span style="color: #66cc66;">=</span> <span style="color: #660033; font-weight: bold;">$global</span>:Count; <span style="color: #660033;">rm</span> variable:Count <span style="color: #333;">&#125;</span><br />
&nbsp;</div>

	<p>I&#8217;ve made these examples slightly more complicated than they had to be to demonstrate some best practices.  When the Window is closed, the Out-Boots function returns the $BootsOutput variable &#8212; so if you want to <strong>output</strong> something from your gui, you need to set that variable.  You can, of course, access global scope variables using the scope prefix <code>$global:variableName</code>, so you can set many different variables which you read later in your script.  The catch is, sometimes the variables <em>have</em> to be explicitly set to script or even global scope in order to refer to the same variable in all of the event handlers&#8230;</p>

	<p><img src="http://huddledmasses.org/images/PowerBoots/PowerBoots9.png" class="float-right-block" alt="" width="260" height="84" /></p>

	<p>However, if you want to have this block of code actually <strong>output</strong> something into the pipeline, you&#8217;ll always want to use the <code>$BootsOutput</code> variable.  You can do that directly, the way the example above does, or you can simply use Write-Output! Inside the Out-Boots function, he Write-Output cmdlet just appends to the $BootsOutput variable &#8230; so it works pretty much exactly the way you would expect it to.</p>

	<div class="posh code posh" style="font-family:monospace;"><br />
Boots <span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp;WrapPanel <span style="color: #000066;">-On_Load</span> <span style="color: #333;">&#123;</span> <span style="color: #660033; font-weight: bold;">$Count</span> <span style="color: #66cc66;">=</span> <span style="color: #cc66cc;">0</span> <span style="color: #333;">&#125;</span> $<span style="color: #333;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; Button <span style="color: #009900;">&quot;Push Me&quot;</span> <span style="color: #000066;">-On_Click</span> <span style="color: #333;">&#123;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0066cc; font-style: italic;">Write-<span style="font-style: normal;">Output</span></span> <span style="color: #333;">&#40;</span><span style="color: #66cc66;">++</span><span style="color: #660033; font-weight: bold;">$count</span><span style="color: #333;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #666666; font-style: italic;"># You have to use array notation ...</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #660033; font-weight: bold;">$block</span><span style="color: #333;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #333;">&#93;</span>.<span style="color: #003366;">Inlines</span>.<span style="color: #660033;">Clear</span><span style="color: #333;">&#40;</span><span style="color: #333;">&#41;</span>; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #660033; font-weight: bold;">$block</span><span style="color: #333;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #333;">&#93;</span>.<span style="color: #003366;">Inlines</span>.<span style="color: #003366;">Add</span><span style="color: #333;">&#40;</span><span style="color: #009900;">&quot;You clicked the button $count times!&quot;</span><span style="color: #333;">&#41;</span> <br />
&nbsp; &nbsp; &nbsp; <span style="color: #333;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; TextBlock <span style="color: #009900;">&quot;Nothing pushed so far&quot;</span> <span style="color: #000066;">-OutVariable</span> script:block <span style="color: #000066;">-VerticalAlignment</span> Center<br />
&nbsp; &nbsp;<span style="color: #333;">&#41;</span><br />
<span style="color: #333;">&#125;</span><br />
&nbsp;</div>

	<p>The first example outputs <strong>just</strong> the count of how many times you clicked.  The second outputs a series of numbers from 1 to however many times you click.  It&#8217;s your choice of how to work with it.</p>

	<h3>We can have fun with colors</h3>

	<p><img src="http://huddledmasses.org/images/PowerBoots/PowerBoots10.png" class="float-right-block" alt="" width="318" height="286" /></p>

	<p>Boots gives you access to all the capabilities of the Windows Presentation Framework, but in some cases that comes at a cost, because we haven&#8217;t simplified their composability.  So we have RadialGradientBrush and LinearGradientBrush, but you have to specify the GradientStops etc &#8230;</p>

	<div class="posh code posh" style="font-family:monospace;"><br />
Boots <span style="color: #000066;">-Background</span> <span style="color: #333;">&#40;</span><br />
&nbsp; &nbsp;RadialGradientBrush $<span style="color: #333;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; GradientStop <span style="color: #000066;">-Offset</span> <span style="color: #cc66cc;">0</span> <span style="color: #000066;">-Color</span> <span style="color: #009900;">&quot;#F00&quot;</span><br />
&nbsp; &nbsp; &nbsp; GradientStop <span style="color: #000066;">-Offset</span> <span style="color: #cc66cc;">1</span> <span style="color: #000066;">-Color</span> <span style="color: #009900;">&quot;#F90&quot;</span><br />
&nbsp; &nbsp;<span style="color: #333;">&#41;</span><br />
<span style="color: #333;">&#41;</span> <span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp;Label <span style="color: #009900;">&quot;Boots&quot;</span> <span style="color: #000066;">-HorizontalAlignment</span> Center `<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">-VerticalAlignment</span> Center `<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">-Foreground</span> White <span style="color: #000066;">-Margin</span> <span style="color: #cc66cc;">80</span> `<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">-FontWeight</span> Bold &nbsp;<span style="color: #000066;">-FontSize</span> <span style="color: #cc66cc;">40</span><br />
<span style="color: #333;">&#125;</span><br />
&nbsp;</div>

	<p>We also have</p>

	<h3>So what does an InputBox look like?</h3>

	<p><img src="http://huddledmasses.org/images/PowerBoots/PowerBoots11.png" class="float-right-block" title="PowerBoots11.png" alt="PowerBoots11.png" width="260" height="86" /></p>

	<p>Well, the simplest possible input box is just a TextBox, with the Width set (if you don&#8217;t set the Width, a TextBox will adjust to fit it&#8217;s contents, which can be really distracting).  All you need to do is this:</p>

	<div class="posh code posh" style="font-family:monospace;"><br />
Boots <span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp;TextBox <span style="color: #000066;">-Width</span> <span style="color: #cc66cc;">220</span> <br />
<span style="color: #333;">&#125;</span> <span style="color: #000066;">-Title</span> <span style="color: #009900;">&quot;Enter your name&quot;</span> <span style="color: #000066;">-On_Close</span> <span style="color: #333;">&#123;</span> <br />
&nbsp; &nbsp;<span style="color: #0066cc; font-style: italic;">Write-<span style="font-style: normal;">Output</span></span> <span style="color: #660033; font-weight: bold;">$BootsWindow</span>.<span style="color: #003366;">Content</span>.<span style="color: #003366;">Text</span> <br />
<span style="color: #333;">&#125;</span> <br />
&nbsp;</div>

	<p><img src="http://huddledmasses.org/images/PowerBoots/PowerBoots12.png" class="float-right-block" title="PowerBoots12.png" alt="PowerBoots12.png" width="200" height="76" /></p>

	<p>Of course, the problem with that is that it pops up this rather confusing window, when what we really wanted was a prompt, and an &#8220;Ok&#8221; button, and some event handling to make the thing behave the way we expect it to.  So lets try our first complicated form. </p>

	<p>I&#8217;ll warn you ahead of time of one thing I&#8217;m going to do here. I&#8217;m using the &#8220;Border&#8221; element to apply a colored border to the StackPanel (because it doesn&#8217;t have it&#8217;s own border parameters), but then I&#8217;m also using the WindowStyle and AllowsTransparency properties to remove the normal window chrome, creating the bare little popup you see in the screenshot. I handle the mouse down event on the main window to allow the user to drag the window around by clicking anywhere on it (except in the TextBox or on the Button, of course). Now it looks slick, and &#8212;you know&#8212; it works!</p>

	<div class="posh code posh" style="font-family:monospace;"><br />
<span style="color: #666699; font-weight: bold;">function</span> <span style="color: #0066cc; font-style: italic;">Get-<span style="font-style: normal;">BootsInput</span></span> <span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp;<span style="color: #666699; font-weight: bold;">Param</span><span style="color: #333;">&#40;</span><span style="color: #003366; font-weight: bold;"><span style="color: #333;">&#91;</span><span style="color: #003366; font-weight: bold;">string</span><span style="color: #333;">&#93;</span></span><span style="color: #660033; font-weight: bold;">$Prompt</span> <span style="color: #66cc66;">=</span> <span style="color: #009900;">&quot;Please enter your name:&quot;</span><span style="color: #333;">&#41;</span><br />
&nbsp; &nbsp;<br />
&nbsp; &nbsp;<span style="color: #0066cc; font-style: italic;">Remove-<span style="font-style: normal;">Variable</span></span> textBox <span style="color: #000066;">-ErrorAction</span> SilentlyContinue<br />
&nbsp; &nbsp;Boots <span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; Border <span style="color: #000066;">-BorderThickness</span> <span style="color: #cc66cc;">4</span> <span style="color: #000066;">-BorderBrush</span> <span style="color: #009900;">&quot;#BE8&quot;</span> <span style="color: #000066;">-Background</span> <span style="color: #009900;">&quot;#EFC&quot;</span> <span style="color: #333;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;StackPanel <span style="color: #000066;">-Margin</span> <span style="color: #cc66cc;">10</span> &nbsp;$<span style="color: #333;">&#40;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Label <span style="color: #660033; font-weight: bold;">$Prompt</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; StackPanel <span style="color: #000066;">-Orientation</span> Horizontal $<span style="color: #333;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;TextBox <span style="color: #000066;">-OutVariable</span> global:textbox <span style="color: #000066;">-Width</span> <span style="color: #cc66cc;">150</span> <span style="color: #000066;">-On_KeyDown</span> <span style="color: #333;">&#123;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666699; font-weight: bold;">if</span><span style="color: #333;">&#40;</span><span style="color: #660033; font-weight: bold;">$_</span>.<span style="color: #003366;">Key</span> <span style="color: #000066;">-eq</span> <span style="color: #009900;">&quot;Return&quot;</span><span style="color: #333;">&#41;</span> <span style="color: #333;">&#123;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0066cc; font-style: italic;">Write-<span style="font-style: normal;">Output</span></span> <span style="color: #660033; font-weight: bold;">$textbox</span><span style="color: #333;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #333;">&#93;</span>.<span style="color: #003366;">Text</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #660033; font-weight: bold;">$BootsWindow</span>.<span style="color: #003366;">Close</span><span style="color: #333;">&#40;</span><span style="color: #333;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #333;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #333;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Button <span style="color: #009900;">&quot;Ok&quot;</span> <span style="color: #000066;">-On_Click</span> <span style="color: #333;">&#123;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066cc; font-style: italic;">Write-<span style="font-style: normal;">Output</span></span> <span style="color: #660033; font-weight: bold;">$textbox</span><span style="color: #333;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #333;">&#93;</span>.<span style="color: #003366;">Text</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #660033; font-weight: bold;">$BootsWindow</span>.<span style="color: #003366;">Close</span><span style="color: #333;">&#40;</span><span style="color: #333;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #333;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #333;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #333;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #333;">&#41;</span><br />
&nbsp; &nbsp;<span style="color: #333;">&#125;</span> <span style="color: #000066;">-On_Load</span> <span style="color: #333;">&#123;</span> <span style="color: #660033; font-weight: bold;">$textbox</span><span style="color: #333;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #333;">&#93;</span>.<span style="color: #003366;">Focus</span><span style="color: #333;">&#40;</span><span style="color: #333;">&#41;</span> <span style="color: #333;">&#125;</span> `<br />
&nbsp; &nbsp;<span style="color: #000066;">-WindowStyle</span> None <span style="color: #000066;">-AllowsTransparency</span> <span style="color: #660033; font-weight: bold;">$true</span> `<br />
&nbsp; &nbsp;<span style="color: #000066;">-On_PreviewMouseLeftButtonDown</span> <span style="color: #333;">&#123;</span> <br />
&nbsp; &nbsp; &nbsp; <span style="color: #666699; font-weight: bold;">if</span><span style="color: #333;">&#40;</span><span style="color: #660033; font-weight: bold;">$_</span>.<span style="color: #003366;">Source</span> <span style="color: #000066;">-notmatch</span> <span style="color: #009900;">&quot;.*\.(TextBox|Button)&quot;</span><span style="color: #333;">&#41;</span> <br />
&nbsp; &nbsp; &nbsp; <span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #660033; font-weight: bold;">$BootsWindow</span>.<span style="color: #003366;">DragMove</span><span style="color: #333;">&#40;</span><span style="color: #333;">&#41;</span> <br />
&nbsp; &nbsp; &nbsp; <span style="color: #333;">&#125;</span><br />
&nbsp; &nbsp;<span style="color: #333;">&#125;</span><br />
<span style="color: #333;">&#125;</span><br />
&nbsp;</div>

	<p>Hopefully you can follow that, although it&#8217;s obviously over the top  <img src='http://joelbennett.net/wordpress/wp-includes/' alt=':)' class='wp-smiley' /> . We handle the KeyDown event on the TextBox (if the Key is the Return key), and we also handle the click on the Button.  In both cases, we&#8217;ll write out the text that was entered, and use the special $BootsWindow variable to close the window.  We also handle the Load event for the window, to make sure the focus is on the TextBox, so you can just start typing.</p>

	<h3>A final example</h3>

	<p><img src="http://huddledmasses.org/images/PowerBoots/PowerBoots13.png" class="float-right-block" title="PowerBoots13.png" alt="PowerBoots13.png" width="248" height="740" /></p>

	<p>I&#8217;ve got quite a few more examples I want to show off in part two of this tutorial, but to get you thinking about ways to integrate this with your routine tasks, and give you some ideas of what you can do with what you know already, let me give you this example of browsing photos, with a visual indication of how big the image file is. Of course, the point is that you could be visualizing, you know &#8230; anything.</p>

	<div class="posh code posh" style="font-family:monospace;"><br />
<span style="color: #0066cc; font-style: italic;">add-<span style="font-style: normal;">type</span></span> <span style="color: #000066;">-Assembly</span> System.<span style="color: #003366;">Windows</span>.<span style="color: #003366;">Forms</span> &nbsp;<span style="color: #666666; font-style: italic;"># To get the Double-Click time</span><br />
<br />
<span style="color: #666699; font-weight: bold;">function</span> <span style="color: #0066cc; font-style: italic;">New-<span style="font-style: normal;">GraphLabel</span></span> <span style="color: #333;">&#123;</span><br />
<span style="color: #333;">&#91;</span>CmdletBinding<span style="color: #333;">&#40;</span><span style="color: #333;">&#41;</span><span style="color: #333;">&#93;</span><br />
&nbsp; &nbsp;<span style="color: #666699; font-weight: bold;">PARAM</span> <span style="color: #333;">&#40;</span> <br />
&nbsp; &nbsp; &nbsp; <span style="color: #333;">&#91;</span>Parameter<span style="color: #333;">&#40;</span>Position<span style="color: #66cc66;">=</span><span style="color: #cc66cc;">0</span><span style="color: #333;">&#41;</span><span style="color: #333;">&#93;</span><span style="color: #003366; font-weight: bold;"><span style="color: #333;">&#91;</span><span style="color: #003366; font-weight: bold;">String</span><span style="color: #333;">&#93;</span></span><span style="color: #660033; font-weight: bold;">$Label</span> <span style="color: #66cc66;">=</span> <span style="color: #009900;">&quot;Name&quot;</span>, <br />
&nbsp; &nbsp; &nbsp; <span style="color: #333;">&#91;</span>Parameter<span style="color: #333;">&#40;</span>Position<span style="color: #66cc66;">=</span><span style="color: #cc66cc;">1</span><span style="color: #333;">&#41;</span><span style="color: #333;">&#93;</span><span style="color: #003366; font-weight: bold;"><span style="color: #333;">&#91;</span><span style="color: #003366; font-weight: bold;">String</span><span style="color: #333;">&#93;</span></span><span style="color: #660033; font-weight: bold;">$Value</span> <span style="color: #66cc66;">=</span> <span style="color: #009900;">&quot;Length&quot;</span>, <br />
&nbsp; &nbsp; &nbsp; <span style="color: #333;">&#91;</span>Parameter<span style="color: #333;">&#40;</span>Position<span style="color: #66cc66;">=</span><span style="color: #cc66cc;">2</span><span style="color: #333;">&#41;</span><span style="color: #333;">&#93;</span><span style="color: #003366; font-weight: bold;"><span style="color: #333;">&#91;</span><span style="color: #003366; font-weight: bold;">ScriptBlock</span><span style="color: #333;">&#93;</span></span><span style="color: #660033; font-weight: bold;">$DoubleClickAction</span> <span style="color: #66cc66;">=</span> <span style="color: #660033; font-weight: bold;">$null</span>, <br />
&nbsp; &nbsp; &nbsp; <span style="color: #333;">&#91;</span>Parameter<span style="color: #333;">&#40;</span><span style="color: #333;">&#41;</span><span style="color: #333;">&#93;</span><span style="color: #003366; font-weight: bold;"><span style="color: #333;">&#91;</span><span style="color: #003366; font-weight: bold;">Int</span><span style="color: #333;">&#93;</span></span><span style="color: #660033; font-weight: bold;">$max</span> <span style="color: #66cc66;">=</span> <span style="color: #660033; font-weight: bold;">$null</span>, <br />
&nbsp; &nbsp; &nbsp; <span style="color: #333;">&#91;</span>Parameter<span style="color: #333;">&#40;</span><span style="color: #333;">&#41;</span><span style="color: #333;">&#93;</span><span style="color: #003366; font-weight: bold;"><span style="color: #333;">&#91;</span><span style="color: #003366; font-weight: bold;">Int</span><span style="color: #333;">&#93;</span></span><span style="color: #660033; font-weight: bold;">$width</span> <span style="color: #66cc66;">=</span> <span style="color: #cc66cc;">200</span>, <br />
&nbsp; &nbsp; &nbsp; <span style="color: #333;">&#91;</span>Parameter<span style="color: #333;">&#40;</span><span style="color: #333;">&#41;</span><span style="color: #333;">&#93;</span><span style="color: #003366; font-weight: bold;"><span style="color: #333;">&#91;</span><span style="color: #003366; font-weight: bold;">double</span><span style="color: #333;">&#93;</span></span><span style="color: #660033; font-weight: bold;">$margin</span> <span style="color: #66cc66;">=</span> <span style="color: #cc66cc;">2</span>,<br />
&nbsp; &nbsp; &nbsp; <span style="color: #333;">&#91;</span>Parameter<span style="color: #333;">&#40;</span><span style="color: #333;">&#41;</span><span style="color: #333;">&#93;</span><span style="color: #003366; font-weight: bold;"><span style="color: #333;">&#91;</span><span style="color: #003366; font-weight: bold;">Int</span><span style="color: #333;">&#93;</span></span><span style="color: #660033; font-weight: bold;">$DoubleClickTime</span> <span style="color: #66cc66;">=</span> $<span style="color: #333;">&#40;</span><span style="color: #003366; font-weight: bold;"><span style="color: #333;">&#91;</span>System.<span style="color: #003366;">Windows</span>.<span style="color: #003366;">Forms</span>.<span style="color: #003366;">SystemInformation</span><span style="color: #333;">&#93;</span></span>::<span style="color: #003366;">DoubleClickTime</span><span style="color: #333;">&#41;</span>,<br />
&nbsp; &nbsp; &nbsp; <span style="color: #333;">&#91;</span>Parameter<span style="color: #333;">&#40;</span>ValueFromPipeline<span style="color: #66cc66;">=</span><span style="color: #660033; font-weight: bold;">$true</span><span style="color: #333;">&#41;</span><span style="color: #333;">&#93;</span><span style="color: #333;">&#91;</span>Alias<span style="color: #333;">&#40;</span><span style="color: #009900;">&quot;IO&quot;</span><span style="color: #333;">&#41;</span><span style="color: #333;">&#93;</span><span style="color: #003366; font-weight: bold;"><span style="color: #333;">&#91;</span><span style="color: #003366; font-weight: bold;">PSObject</span><span style="color: #333;">&#91;</span><span style="color: #333;">&#93;</span><span style="color: #333;">&#93;</span></span><span style="color: #660033; font-weight: bold;">$InputObject</span><br />
&nbsp; &nbsp;<span style="color: #333;">&#41;</span><br />
&nbsp; &nbsp;<span style="color: #666699; font-weight: bold;">BEGIN</span> <span style="color: #333;">&#123;</span> <span style="color: #660033; font-weight: bold;">$maxx</span> <span style="color: #66cc66;">=</span> <span style="color: #660033; font-weight: bold;">$max</span> <span style="color: #333;">&#125;</span><br />
&nbsp; &nbsp;<span style="color: #666699; font-weight: bold;">PROCESS</span> <span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #666699; font-weight: bold;">if</span><span style="color: #333;">&#40;</span><span style="color: #66cc66;">!</span><span style="color: #660033; font-weight: bold;">$maxx</span><span style="color: #333;">&#41;</span><span style="color: #333;">&#123;</span> <span style="color: #660033; font-weight: bold;">$maxx</span><span style="color: #66cc66;">=</span>@<span style="color: #333;">&#40;</span><span style="color: #660033; font-weight: bold;">$InputObject</span><span style="color: #333;">&#41;</span><span style="color: #333;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #333;">&#93;</span>.<span style="color: #660033; font-weight: bold;">$Value</span> <span style="color: #333;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; <span style="color: #666699; font-weight: bold;">foreach</span><span style="color: #333;">&#40;</span><span style="color: #660033; font-weight: bold;">$io</span> <span style="color: #666699; font-weight: bold;">in</span> <span style="color: #660033; font-weight: bold;">$InputObject</span><span style="color: #333;">&#41;</span> <span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #666666; font-style: italic;">## This is the core part of the script ...</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #666666; font-style: italic;">## For each input, generate a grid panel with a label and a rectangle in the background</span><br />
&nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;GridPanel <span style="color: #000066;">-tag</span> @<span style="color: #333;">&#123;</span>item<span style="color: #66cc66;">=</span><span style="color: #660033; font-weight: bold;">$io</span>; action<span style="color: #66cc66;">=</span><span style="color: #660033; font-weight: bold;">$DoubleClickAction</span><span style="color: #333;">&#125;</span> <span style="color: #000066;">-width</span> <span style="color: #660033; font-weight: bold;">$Width</span> <span style="color: #000066;">-margin</span> <span style="color: #660033; font-weight: bold;">$margin</span> $<span style="color: #333;">&#40;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Label <span style="color: #660033; font-weight: bold;">$io</span>.<span style="color: #660033; font-weight: bold;">$Label</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Rectangle <span style="color: #000066;">-HorizontalAlignment</span> Left <span style="color: #000066;">-Fill</span> <span style="color: #009900;">&quot;#9F00&quot;</span> `<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">-Width</span> <span style="color: #333;">&#40;</span><span style="color: #660033; font-weight: bold;">$Width</span> <span style="color: #66cc66;">*</span> <span style="color: #333;">&#40;</span><span style="color: #660033; font-weight: bold;">$io</span>.<span style="color: #009900;">&quot;$Value&quot;</span> <span style="color: #66cc66;">/</span> <span style="color: #660033; font-weight: bold;">$maxx</span><span style="color: #333;">&#41;</span><span style="color: #333;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #333;">&#41;</span> <span style="color: #000066;">-On_MouseLeftButtonDown</span> <span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666699; font-weight: bold;">if</span><span style="color: #333;">&#40;</span><span style="color: #660033; font-weight: bold;">$this</span>.<span style="color: #003366;">Tag</span>.<span style="color: #003366;">Action</span><span style="color: #333;">&#41;</span> <span style="color: #333;">&#123;</span> <span style="color: #666666; font-style: italic;"># They passed in a doubleclick action, so lets handle it</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #666699; font-weight: bold;">if</span><span style="color: #333;">&#40;</span><span style="color: #660033; font-weight: bold;">$global</span>:ClickTime <span style="color: #000066;">-and</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #333;">&#40;</span><span style="color: #003366; font-weight: bold;"><span style="color: #333;">&#91;</span>DateTime<span style="color: #333;">&#93;</span></span>::<span style="color: #003366;">Now</span> <span style="color: #66cc66;">-</span> <span style="color: #660033; font-weight: bold;">$ClickTime</span><span style="color: #333;">&#41;</span>.<span style="color: #003366;">TotalMilliseconds</span> <span style="color: #000066;">-lt</span> <span style="color: #660033; font-weight: bold;">$global</span>:DoubleClickTime<span style="color: #333;">&#41;</span> <span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;"># We invoke the scriptblock </span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;"># and pass it the original input object </span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;"># and the grid panel object</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&amp;</span><span style="color: #660033; font-weight: bold;">$This</span>.<span style="color: #003366;">Tag</span>.<span style="color: #003366;">Action</span> <span style="color: #660033; font-weight: bold;">$this</span>.<span style="color: #003366;">Tag</span>.<span style="color: #003366;">Item</span> <span style="color: #660033; font-weight: bold;">$this</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #333;">&#125;</span> <span style="color: #666699; font-weight: bold;">else</span> <span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #660033; font-weight: bold;">$global</span>:ClickTime <span style="color: #66cc66;">=</span> <span style="color: #003366; font-weight: bold;"><span style="color: #333;">&#91;</span>DateTime<span style="color: #333;">&#93;</span></span>::<span style="color: #003366;">Now</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #333;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #333;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #333;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #333;">&#125;</span><br />
&nbsp; &nbsp;<span style="color: #333;">&#125;</span><br />
<span style="color: #333;">&#125;</span><br />
<br />
<span style="color: #0066cc; font-style: italic;">Set-<span style="font-style: normal;">Alias</span></span> GraphLabel <span style="color: #0066cc; font-style: italic;">New-<span style="font-style: normal;">GraphLabel</span></span><br />
<br />
<span style="color: #666666; font-style: italic;">## Example 1: list of processes with most RAM usage</span><br />
<span style="color: #666666; font-style: italic;">## DoubleClickAction is `kill`</span><br />
Boots <span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp;<span style="color: #660033;">ps</span> <span style="color: #66cc66;">|</span> <span style="color: #660033;">sort</span> PM <span style="color: #000066;">-Desc</span> <span style="color: #66cc66;">|</span> <span style="color: #660033;">Select</span> <span style="color: #000066;">-First</span> <span style="color: #cc66cc;">20</span> <span style="color: #66cc66;">|</span> <br />
&nbsp; &nbsp; &nbsp; GraphLabel ProcessName PM <span style="color: #333;">&#123;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #660033;">Kill</span> <span style="color: #660033; font-weight: bold;">$Args</span><span style="color: #333;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #333;">&#93;</span>.<span style="color: #003366;">Id</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #660033; font-weight: bold;">$global</span>:panel<span style="color: #333;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #333;">&#93;</span>.<span style="color: #003366;">Children</span>.<span style="color: #003366;">Remove</span><span style="color: #333;">&#40;</span><span style="color: #660033; font-weight: bold;">$Args</span><span style="color: #333;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #333;">&#93;</span><span style="color: #333;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #333;">&#125;</span> <span style="color: #66cc66;">|</span> <br />
&nbsp; &nbsp;StackPanel <span style="color: #000066;">-ov</span> global:panel<br />
<span style="color: #333;">&#125;</span><br />
<span style="color: #666666; font-style: italic;">## Example 2: list of images, with file size indicated</span><br />
<span style="color: #666666; font-style: italic;">## DoubleClickAction is `open`</span><br />
Boots <span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp;<span style="color: #660033;">ls</span> ~<span style="color: #66cc66;">/</span>Pictures<span style="color: #66cc66;">/</span> <span style="color: #000066;">-recurse</span> <span style="color: #000066;">-Include</span> <span style="color: #66cc66;">*</span>.<span style="color: #003366;">jpg</span> <span style="color: #66cc66;">|</span> <span style="color: #660033;">Sort</span> Length <span style="color: #000066;">-Desc</span> <span style="color: #66cc66;">|</span> <span style="color: #66cc66;">%</span> <span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #666699; font-weight: bold;">if</span><span style="color: #333;">&#40;</span><span style="color: #66cc66;">!</span><span style="color: #660033; font-weight: bold;">$Max</span><span style="color: #333;">&#41;</span><span style="color: #333;">&#123;</span><span style="color: #660033; font-weight: bold;">$Max</span><span style="color: #66cc66;">=</span><span style="color: #660033; font-weight: bold;">$_</span>.<span style="color: #003366;">Length</span><span style="color: #333;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; StackPanel <span style="color: #000066;">-Width</span> <span style="color: #cc66cc;">200</span> <span style="color: #000066;">-Margin</span> <span style="color: #cc66cc;">5</span> $<span style="color: #333;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Image <span style="color: #000066;">-Source</span> <span style="color: #660033; font-weight: bold;">$_</span>.<span style="color: #003366;">FullName</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;GraphLabel Name Length <span style="color: #000066;">-Max</span> <span style="color: #660033; font-weight: bold;">$Max</span> <span style="color: #000066;">-IO</span> <span style="color: #660033; font-weight: bold;">$_</span> <span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003366; font-weight: bold;"><span style="color: #333;">&#91;</span>Diagnostics.<span style="color: #666699; font-weight: bold;">Process</span><span style="color: #333;">&#93;</span></span>::<span style="color: #660033;">Start</span><span style="color: #333;">&#40;</span> <span style="color: #660033; font-weight: bold;">$args</span><span style="color: #333;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #333;">&#93;</span>.<span style="color: #003366;">FullName</span> <span style="color: #333;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #333;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #333;">&#41;</span> <br />
&nbsp; &nbsp;<span style="color: #333;">&#125;</span> <span style="color: #66cc66;">|</span> WrapPanel <br />
<span style="color: #333;">&#125;</span> <span style="color: #000066;">-Width</span> <span style="color: #cc66cc;">800</span><br />
&nbsp;</div>

	<p>Notice that I had to manually handle the concept of a double click, because StackPanels don&#8217;t have a Click or DoubleClick event, just MouseDown and MouseUp.  I could have stuck the stackpanel into something that does, but there&#8217;s really no need.  Also, the <code>[Diagnostics.Process]::Start</code> is the equivalent of typing the name into the run dialog.  I&#8217;m just <em>executing</em> the jpg, which makes it open in the default editor.  It&#8217;s just a sample, after all.</p>

	<h3>End note</h3>

	<p>The current version of Boots does not add threading support, which means that when you run something through Boots, execution of your script stops until the window is closed.  You can get around this somewhat in <a href="http://huddledmasses.org/wpf-from-powershell-updating-windows/">various different ways</a>, but future releases <em>will</em> support running the <span class="caps">WPF</span> window in a separate thread, and even communicating to it &#8230; at the expense of a slightly different syntax. If you need that functionality, feel free to let me know &#8230; I could use some motivation.</p>

	<p>I hope you&#8217;ve enjoyed this tour through PowerBoots, and will be able to start applying it for fun and profit.</p>]]></content:encoded>
			<wfw:commentRss>http://joelbennett.net/powerboots-tutorial-walkthrough/feed/</wfw:commentRss>
		<slash:comments>14</slash:comments>
		</item>
		<item>
		<title>PowerBoots: Loading XAML Windows in PowerShell 1.0 or 2.0</title>
		<link>http://joelbennett.net/powerboots-loading-xaml-windows-in-powershell-10-or-20/</link>
		<comments>http://joelbennett.net/powerboots-loading-xaml-windows-in-powershell-10-or-20/#comments</comments>
		<pubDate>Fri, 13 Feb 2009 07:20:07 +0000</pubDate>
		<dc:creator>Joel 'Jaykul' Bennett</dc:creator>
				<category><![CDATA[Huddled]]></category>
		<category><![CDATA[Design]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[PowerBoots]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Scripting]]></category>
		<category><![CDATA[UserInterface]]></category>
		<category><![CDATA[WPF]]></category>
		<category><![CDATA[XAML]]></category>

		<guid isPermaLink="false">http://huddledmasses.org/?p=1059</guid>
		<description><![CDATA[Awhile back I wrote a series of posts about WPF From PowerShell From PowerShell&#8221; which were about how you could load XAML in previous PowerShell 2 CTPs to create WPF user interfaces &#8230; a few people have mentioned loading XAML in PowerBoots, and a couple of people have posted other samples showing XAML even since [...]]]></description>
			<content:encoded><![CDATA[	<p>Awhile back I wrote a series of posts about <a href="http://huddledmasses.org/?s=&#34;WPF"><span class="caps">WPF</span> From PowerShell</a> From PowerShell&#8221; which were about how you could load <span class="caps">XAML</span> in previous PowerShell 2 CTPs to create <span class="caps">WPF</span> user interfaces &#8230; a few people have mentioned loading <span class="caps">XAML</span> in <a href="http://boots.CodePlex.com">PowerBoots</a>, and a couple of people have posted other samples showing <span class="caps">XAML</span> even since I published the most recent release, so I figure it&#8217;s time to point out that you really can load that <span class="caps">XAML</span> into Boots, and get all the threading and other support.  </p>

	<p>Just for fun, I&#8217;m going to rehash an earlier post about <a href="http://huddledmasses.org/wpf-from-powershell-updating-windows/">updating windows</a> to show how you can go about this using PowerBoots, and hopefully show that it&#8217;s a little easier (and a lot more async).  Compare and contrast the code in this article with that one, just for fun.</p>

	<h2>This works with any version of PowerShell</h2>

	<p>Unlike the original article, most this code (except where explicitly mentioned) works on either PowerShell v2 with PowerBoots, or PowerShell 1.0 with <strong>PoshWPF</strong>, a snapin that is part of the PowerBoots module but is also released separately&#8230; Also, unlike those previous posts, this does <em>not</em> require you to be running PowerShell.exe with the -<span class="caps">STA</span> switch, since the New-BootsWindow cmdlet takes care of threading for us.</p>

<span id="more-1059"></span>

	<h3>The simple splash screen</h3>

	<div class="posh code posh" style="font-family:monospace;"><br />
<span style="color: #660033; font-weight: bold;">$Splash</span> <span style="color: #66cc66;">=</span> <span style="color: #0066cc; font-style: italic;">New-<span style="font-style: normal;">BootsWindow</span></span> <span style="color: #000066;">-Async</span> <span style="color: #000066;">-Passthru</span> <span style="color: #000066;">-SourceTemplate</span> @<span style="color: #009900;">&quot;<br />
&lt;window xmlns=&quot;</span>http:<span style="color: #66cc66;">//</span>schemas.<span style="color: #003366;">microsoft</span>.<span style="color: #003366;">com</span><span style="color: #66cc66;">/</span>winfx<span style="color: #66cc66;">/</span><span style="color: #cc66cc;">2006</span><span style="color: #66cc66;">/</span>xaml<span style="color: #66cc66;">/</span>presentation<span style="color: #009900;">&quot; <br />
&nbsp; &nbsp; &nbsp; &nbsp; windowstyle=&quot;</span>None<span style="color: #009900;">&quot; allowstransparency=&quot;</span>True<span style="color: #009900;">&quot; opacity=&quot;</span><span style="color: #cc66cc;">0.8</span><span style="color: #009900;">&quot; <br />
&nbsp; &nbsp; &nbsp; &nbsp; topmost=&quot;</span>True<span style="color: #009900;">&quot; sizetocontent=&quot;</span>WidthAndHeight<span style="color: #009900;">&quot; <br />
&nbsp; &nbsp; &nbsp; &nbsp; windowstartuplocation=&quot;</span>CenterOwner<span style="color: #009900;">&quot; showintaskbar=&quot;</span>False<span style="color: #009900;">&quot;&gt;<br />
&nbsp; &nbsp;&lt;img source=&quot;</span>http:<span style="color: #66cc66;">//</span>dilbert.<span style="color: #003366;">com</span><span style="color: #66cc66;">/</span>dyn<span style="color: #66cc66;">/</span>str_strip<span style="color: #66cc66;">/</span>000000000<span style="color: #66cc66;">/</span>00000000<span style="color: #66cc66;">/</span>0000000<span style="color: #66cc66;">/</span>000000<span style="color: #66cc66;">/</span><span style="color: #cc66cc;">40000</span><span style="color: #66cc66;">/</span><span style="color: #cc66cc;">1000</span><span style="color: #66cc66;">/</span><span style="color: #cc66cc;">200</span><span style="color: #66cc66;">/</span><span style="color: #cc66cc;">41215</span><span style="color: #66cc66;">/</span>41215.<span style="color: #003366;">strip</span>.<span style="color: #003366;">print</span>.<span style="color: #003366;">gif</span><span style="color: #009900;">&quot; <br />
&nbsp; &nbsp; &nbsp; &nbsp; height=&quot;</span><span style="color: #cc66cc;">177</span><span style="color: #009900;">&quot;&gt;<br />
&lt;/window&gt;<br />
&quot;</span>@ <span style="color: #000066;">-Content</span> <span style="color: #333;">&#123;</span><span style="color: #660033; font-weight: bold;">$Args</span><span style="color: #333;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #333;">&#93;</span>.<span style="color: #003366;">Content</span><span style="color: #333;">&#125;</span> <span style="color: #000066;">-On_MouseDown</span> <span style="color: #333;">&#123;</span> <span style="color: #660033; font-weight: bold;">$this</span>.<span style="color: #003366;">DragMove</span><span style="color: #333;">&#40;</span><span style="color: #333;">&#41;</span> <span style="color: #333;">&#125;</span><br />
<span style="color: #666666; font-style: italic;"># Imagine this is your script, working ...</span><br />
<span style="color: #0066cc; font-style: italic;">Start-<span style="font-style: normal;">Sleep</span></span> <span style="color: #cc66cc;">3</span><br />
<span style="color: #666666; font-style: italic;"># And now you're done, and want to close it</span><br />
<span style="color: #0066cc; font-style: italic;">Invoke-<span style="font-style: normal;">BootsWindow</span></span> <span style="color: #660033; font-weight: bold;">$Splash</span> <span style="color: #333;">&#123;</span> <span style="color: #660033; font-weight: bold;">$Splash</span>.<span style="color: #003366;">Close</span><span style="color: #333;">&#40;</span><span style="color: #333;">&#41;</span> <span style="color: #333;">&#125;</span></div>

	<p>This is, of course, not a great example of why you would want to use <span class="caps">XAML</span>, since it reads virtually the same as it would if you wrote it in PowerBoots (if you were on PowerShell v2):</p>

	<div class="posh code posh" style="font-family:monospace;"><br />
<span style="color: #666666; font-style: italic;">## This requires PowerBoots which is (as of this writing) is still v2 only...</span><br />
<span style="color: #660033; font-weight: bold;">$window</span> <span style="color: #66cc66;">=</span> Boots <span style="color: #000066;">-Async</span> <span style="color: #000066;">-Passthru</span> &nbsp;<span style="color: #000066;">-Content</span> <span style="color: #333;">&#123;</span> <br />
&nbsp; &nbsp;Image <span style="color: #000066;">-Height</span> <span style="color: #cc66cc;">177</span> <span style="color: #000066;">-Source</span> http:<span style="color: #66cc66;">//</span>dilbert.<span style="color: #003366;">com</span><span style="color: #66cc66;">/</span>dyn<span style="color: #66cc66;">/</span>str_strip<span style="color: #66cc66;">/</span>000000000<span style="color: #66cc66;">/</span>00000000<span style="color: #66cc66;">/</span>0000000<span style="color: #66cc66;">/</span>000000<span style="color: #66cc66;">/</span><span style="color: #cc66cc;">40000</span><span style="color: #66cc66;">/</span><span style="color: #cc66cc;">1000</span><span style="color: #66cc66;">/</span><span style="color: #cc66cc;">200</span><span style="color: #66cc66;">/</span><span style="color: #cc66cc;">41215</span><span style="color: #66cc66;">/</span>41215.<span style="color: #003366;">strip</span>.<span style="color: #003366;">print</span>.<span style="color: #003366;">gif</span><br />
<span style="color: #333;">&#125;</span> <span style="color: #000066;">-WindowStyle</span> None <span style="color: #000066;">-AllowsTransparency</span> <span style="color: #660033; font-weight: bold;">$True</span> <span style="color: #000066;">-Opacity</span> <span style="color: #cc66cc;">0.8</span> <span style="color: #000066;">-Topmost</span> <span style="color: #660033; font-weight: bold;">$True</span> <span style="color: #000066;">-WindowStartupLocation</span> CenterOwner <span style="color: #000066;">-ShowInTaskbar</span> <span style="color: #660033; font-weight: bold;">$False</span> <span style="color: #000066;">-On_MouseDown</span> <span style="color: #333;">&#123;</span> <span style="color: #660033; font-weight: bold;">$this</span>.<span style="color: #003366;">DragMove</span><span style="color: #333;">&#40;</span><span style="color: #333;">&#41;</span> <span style="color: #333;">&#125;</span><br />
<br />
<span style="color: #666666; font-style: italic;"># Imagine this is your script, working ...</span><br />
<span style="color: #0066cc; font-style: italic;">Start-<span style="font-style: normal;">Sleep</span></span> <span style="color: #cc66cc;">3</span><br />
<span style="color: #666666; font-style: italic;"># And now you're done, and want to close it</span><br />
<span style="color: #0066cc; font-style: italic;">Invoke-<span style="font-style: normal;">BootsWindow</span></span> <span style="color: #660033; font-weight: bold;">$Splash</span> <span style="color: #333;">&#123;</span> <span style="color: #660033; font-weight: bold;">$Splash</span>.<span style="color: #003366;">Close</span><span style="color: #333;">&#40;</span><span style="color: #333;">&#41;</span> <span style="color: #333;">&#125;</span></div>

	<p>The big difference, of course, is that this is fully aync, so unlike the splash screen in the original post, we don&#8217;t have to do any tricks to get it to render, and we are able to add a MouseDown handler so you can drag the splash screen around while you wait for it to go away&#8230;</p>

	<h2>And now, for something completely different</h2>

	<p>Let&#8217;s skip over the very useful information I already wrote about the properties you can set on the &#8220;Window&#8221; object in <span class="caps">WPF</span> (all of which are parameters to New-BootsWindow, by the way) and cut straight to the second example &#8230; I&#8217;ve tweaked an old <span class="caps">WPF</span> sample I had and ported it to PowerShell, <em>and now, adapted it for PoshWpf</em> ... the <a href="http://huddledmasses.org/wpf-from-powershell-updating-windows/clock/" rel="attachment wp-att-528">xaml file is here</a> and I&#8217;ll show you the code just as soon as you take a look at the screenshot (trust me, the code will make more sense if you&#8217;ve seen the output):</p>

	<p><img src="http://huddledmasses.org/images/2008-05-09_0029.png" title="A clock, with working CPU and RAM bars" alt="A clock, with working CPU and RAM bars" width="783" height="312" /></p>

	<p>So basically, the UI is defined in a href=&#8216;http://HuddledMasses.org/wpf-from-powershell-updating-windows/clock/&#8217; rel=&#8216;attachment wp-att-528&#8217;&gt;that xaml file, and all we need to do in the script is update the time, update the <span class="caps">CPU</span> bar, and update the <span class="caps">RAM</span> bar&#8230;</p>

	<h3>Please notice the content block</h3>

	<p>PowerBoots passes the window object itself into the content scriptblock, and the content block <strong>must</strong> output the content you want in the window. Of course, if you&#8217;re loading a fully defined window in <span class="caps">XAML</span>, you don&#8217;t want to change the Window&#8217;s content, but you have to return something, so you should just return &#8230; the content that&#8217;s already in the window. Ie: <code>$Args[0].Content</code></p>

	<p>One other point, for those of you who are going to become <span class="caps">XAML</span> masters. In PowerBoots you can define just the styles and templates as resources in a separate <span class="caps">XAML</span> file which you can load with the <code>Add-BootsTemplate</code>, and then you can still create the UI in <span class="caps">XAML</span> or useing PowerBoots syntax.  In my case, this <span class="caps">XAML</span> was edited  using <a href="http://www.kaxaml.com/">kaxaml</a> (it could have been Expression Blend, or Visual Studio), and kaxaml doesn&#8217;t make it easy to separate out resource files, so I just left it all in one file:</p>

	<div class="posh code posh" style="font-family:monospace;"><br />
<span style="color: #0066cc; font-style: italic;">Write-<span style="font-style: normal;">Host</span></span> <span style="color: #009900;">&quot;Initializing Performance Counters, please have patience&quot;</span> <span style="color: #000066;">-fore</span> Cyan<br />
<span style="color: #666666; font-style: italic;">### Import PoshWpf module</span><br />
<span style="color: #0066cc; font-style: italic;">Import-<span style="font-style: normal;">Module</span></span> PowerBoots<br />
<span style="color: #666666; font-style: italic;">### Or, on v1:</span><br />
<span style="color: #666666; font-style: italic;"># Add-PSSnapin PoshWpf</span><br />
<br />
<span style="color: #660033; font-weight: bold;">$script</span>:cpu <span style="color: #66cc66;">=</span> <span style="color: #0066cc; font-style: italic;">new-<span style="font-style: normal;">object</span></span> System.<span style="color: #003366;">Diagnostics</span>.<span style="color: #003366;">PerformanceCounter</span> <span style="color: #009900;">&quot;Processor&quot;</span>, <span style="color: #009900;">&quot;% Processor Time&quot;</span>, <span style="color: #009900;">&quot;_Total&quot;</span><br />
<span style="color: #660033; font-weight: bold;">$script</span>:ram <span style="color: #66cc66;">=</span> <span style="color: #0066cc; font-style: italic;">new-<span style="font-style: normal;">object</span></span> System.<span style="color: #003366;">Diagnostics</span>.<span style="color: #003366;">PerformanceCounter</span> <span style="color: #009900;">&quot;Memory&quot;</span>, <span style="color: #009900;">&quot;Available KBytes&quot;</span><br />
<br />
<span style="color: #666666; font-style: italic;">## get initial values, because the counters don't work until the second call</span><br />
<span style="color: #660033; font-weight: bold;">$null</span> <span style="color: #66cc66;">=</span> <span style="color: #660033; font-weight: bold;">$script</span>:cpu.<span style="color: #003366;">NextValue</span><span style="color: #333;">&#40;</span><span style="color: #333;">&#41;</span><br />
<span style="color: #660033; font-weight: bold;">$null</span> <span style="color: #66cc66;">=</span> <span style="color: #660033; font-weight: bold;">$script</span>:ram.<span style="color: #003366;">NextValue</span><span style="color: #333;">&#40;</span><span style="color: #333;">&#41;</span><br />
<span style="color: #660033; font-weight: bold;">$script</span>:maxram <span style="color: #66cc66;">=</span> <span style="color: #333;">&#40;</span><span style="color: #660033;">gwmi</span> Win32_OperatingSystem<span style="color: #333;">&#41;</span>.<span style="color: #003366;">TotalVisibleMemorySize</span><br />
<br />
<span style="color: #0066cc; font-style: italic;">Write-<span style="font-style: normal;">Host</span></span> <span style="color: #009900;">&quot;Loading XAML window...&quot;</span> <span style="color: #000066;">-fore</span> Cyan<br />
<span style="color: #666666; font-style: italic;">## Load the XAML and show the window. It won't be updating itself yet...</span><br />
<span style="color: #660033; font-weight: bold;">$clock</span> <span style="color: #66cc66;">=</span> <span style="color: #0066cc; font-style: italic;">New-<span style="font-style: normal;">BootsWindow</span></span> <span style="color: #000066;">-Async</span> <span style="color: #000066;">-Passthru</span> <span style="color: #000066;">-Content</span> <span style="color: #333;">&#123;</span> <span style="color: #660033; font-weight: bold;">$Args</span><span style="color: #333;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #333;">&#93;</span>.<span style="color: #003366;">Content</span> <br />
<span style="color: #333;">&#125;</span> <span style="color: #000066;">-FileTemplate</span> <span style="color: #009900;">&quot;C:\Users\Joel\Documents\WindowsPowerShell\Scripts\Demo\clock.xaml&quot;</span> <br />
<br />
<span style="color: #666666; font-style: italic;">## Create a script block which will update the UI by changing the Resources!</span><br />
<span style="color: #660033; font-weight: bold;">$counter</span> <span style="color: #66cc66;">=</span> <span style="color: #cc66cc;">0</span>;<br />
<span style="color: #660033; font-weight: bold;">$updateBlock</span> <span style="color: #66cc66;">=</span> <span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp;<span style="color: #666666; font-style: italic;"># Update the clock</span><br />
&nbsp; &nbsp;<span style="color: #660033; font-weight: bold;">$clock</span>.<span style="color: #003366;">Resources</span><span style="color: #333;">&#91;</span><span style="color: #009900;">&quot;Time&quot;</span><span style="color: #333;">&#93;</span> <span style="color: #66cc66;">=</span> <span style="color: #003366; font-weight: bold;"><span style="color: #333;">&#91;</span>DateTime<span style="color: #333;">&#93;</span></span>::<span style="color: #003366;">Now</span>.<span style="color: #003366;">ToString</span><span style="color: #333;">&#40;</span><span style="color: #009900;">&quot;hh:MM.ss&quot;</span><span style="color: #333;">&#41;</span><br />
<br />
&nbsp; &nbsp;<span style="color: #666666; font-style: italic;"># We only want to update the counters at most once a second</span><br />
&nbsp; &nbsp;<span style="color: #666666; font-style: italic;"># Otherwise their values are invalid and ...</span><br />
&nbsp; &nbsp;<span style="color: #666666; font-style: italic;"># The CPU counter fluctuates from 0 to the real number</span><br />
&nbsp; &nbsp;<span style="color: #666699; font-weight: bold;">if</span><span style="color: #333;">&#40;</span> <span style="color: #660033; font-weight: bold;">$counter</span><span style="color: #66cc66;">++</span> <span style="color: #000066;">-eq</span> <span style="color: #cc66cc;">4</span> <span style="color: #333;">&#41;</span> <span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #660033; font-weight: bold;">$counter</span> <span style="color: #66cc66;">=</span> <span style="color: #cc66cc;">0</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;"># Update the CPU counter with the absolute value and the percentage</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #660033; font-weight: bold;">$cu</span> <span style="color: #66cc66;">=</span> <span style="color: #660033; font-weight: bold;">$cpu</span>.<span style="color: #003366;">NextValue</span><span style="color: #333;">&#40;</span><span style="color: #333;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #660033; font-weight: bold;">$clock</span>.<span style="color: #003366;">Resources</span>.<span style="color: #003366;">CpuP</span> <span style="color: #66cc66;">=</span> <span style="color: #333;">&#40;</span><span style="color: #660033; font-weight: bold;">$cu</span> <span style="color: #66cc66;">/</span> <span style="color: #cc66cc;">100</span><span style="color: #333;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #660033; font-weight: bold;">$clock</span>.<span style="color: #003366;">Resources</span>.<span style="color: #003366;">Cpu</span> <span style="color: #66cc66;">=</span> <span style="color: #009900;">&quot;{0:0.0}%&quot;</span> <span style="color: #000066;">-f</span> <span style="color: #660033; font-weight: bold;">$cu</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;"># Update the RAM counter with the absolute value and the percentage</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #660033; font-weight: bold;">$rm</span> <span style="color: #66cc66;">=</span> <span style="color: #660033; font-weight: bold;">$ram</span>.<span style="color: #003366;">NextValue</span><span style="color: #333;">&#40;</span><span style="color: #333;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #660033; font-weight: bold;">$clock</span>.<span style="color: #003366;">Resources</span>.<span style="color: #003366;">RamP</span> <span style="color: #66cc66;">=</span> <span style="color: #333;">&#40;</span><span style="color: #660033; font-weight: bold;">$rm</span> <span style="color: #66cc66;">/</span> <span style="color: #660033; font-weight: bold;">$maxram</span><span style="color: #333;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #660033; font-weight: bold;">$clock</span>.<span style="color: #003366;">Resources</span>.<span style="color: #003366;">Ram</span> <span style="color: #66cc66;">=</span> <span style="color: #009900;">&quot;{0:0.00}Mb&quot;</span> <span style="color: #000066;">-f</span> <span style="color: #333;">&#40;</span><span style="color: #660033; font-weight: bold;">$rm</span><span style="color: #66cc66;">/</span>1MB<span style="color: #333;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #333;">&#125;</span><br />
<span style="color: #333;">&#125;</span><br />
<br />
<span style="color: #666666; font-style: italic;">## Now we need to call that scriptblock on a timer. That's easy, but it</span><br />
<span style="color: #666666; font-style: italic;">## must be done on the window's thread, so we use Invoke-BootsWindow.</span><br />
<span style="color: #666666; font-style: italic;">## Notice the first argument is the window we want to run the script in</span><br />
<span style="color: #0066cc; font-style: italic;">Invoke-<span style="font-style: normal;">BootsWindow</span></span> <span style="color: #660033; font-weight: bold;">$clock</span> <span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp;<span style="color: #666666; font-style: italic;">## We'll create a timer</span><br />
&nbsp; &nbsp;<span style="color: #660033; font-weight: bold;">$global</span>:timer <span style="color: #66cc66;">=</span> <span style="color: #0066cc; font-style: italic;">new-<span style="font-style: normal;">object</span></span> System.<span style="color: #003366;">Windows</span>.<span style="color: #003366;">Threading</span>.<span style="color: #003366;">DispatcherTimer</span><br />
&nbsp; &nbsp;<span style="color: #666666; font-style: italic;">## Which will fire 4 times every second</span><br />
&nbsp; &nbsp;<span style="color: #660033; font-weight: bold;">$timer</span>.<span style="color: #003366;">Interval</span> <span style="color: #66cc66;">=</span> <span style="color: #003366; font-weight: bold;"><span style="color: #333;">&#91;</span>TimeSpan<span style="color: #333;">&#93;</span></span><span style="color: #009900;">&quot;0:0:0.25&quot;</span><br />
&nbsp; &nbsp;<span style="color: #666666; font-style: italic;">## And will invoke the $updateBlock</span><br />
&nbsp; &nbsp;<span style="color: #660033; font-weight: bold;">$timer</span>.<span style="color: #003366;">Add_Tick</span><span style="color: #333;">&#40;</span> <span style="color: #660033; font-weight: bold;">$updateBlock</span> <span style="color: #333;">&#41;</span><br />
&nbsp; &nbsp;<span style="color: #666666; font-style: italic;">## Now start the timer running</span><br />
&nbsp; &nbsp;<span style="color: #660033; font-weight: bold;">$timer</span>.<span style="color: #660033;">Start</span><span style="color: #333;">&#40;</span><span style="color: #333;">&#41;</span><br />
<span style="color: #333;">&#125;</span><br />
<br />
<span style="color: #666666; font-style: italic;">## And just like that, the $UpdateBlock is running 4x a second</span><br />
<span style="color: #666666; font-style: italic;">## and the clock is working. &nbsp;Pretty cool, right?</span><br />
<span style="color: #666666; font-style: italic;">## what's really cool is ... we still have full control in the console</span><br />
<span style="color: #666666; font-style: italic;">## so we can add these events afterward:</span><br />
<br />
<span style="color: #666666; font-style: italic;">## If we wanted to, say, handle mouse events to let you drag the window or close it ...</span><br />
<span style="color: #0066cc; font-style: italic;">Invoke-<span style="font-style: normal;">BootsWindow</span></span> <span style="color: #660033; font-weight: bold;">$clock</span> <span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp;<span style="color: #660033; font-weight: bold;">$clock</span>.<span style="color: #003366;">Add_MouseLeftButtonDown</span><span style="color: #333;">&#40;</span> <span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #660033; font-weight: bold;">$_</span>.<span style="color: #003366;">Handled</span> <span style="color: #66cc66;">=</span> <span style="color: #660033; font-weight: bold;">$true</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #660033; font-weight: bold;">$clock</span>.<span style="color: #003366;">DragMove</span><span style="color: #333;">&#40;</span><span style="color: #333;">&#41;</span> <span style="color: #666666; font-style: italic;"># WPF Magic!</span><br />
&nbsp; &nbsp;<span style="color: #333;">&#125;</span> <span style="color: #333;">&#41;</span><br />
&nbsp; &nbsp;<span style="color: #660033; font-weight: bold;">$clock</span>.<span style="color: #003366;">Add_MouseRightButtonDown</span><span style="color: #333;">&#40;</span> <span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #660033; font-weight: bold;">$_</span>.<span style="color: #003366;">Handled</span> <span style="color: #66cc66;">=</span> <span style="color: #660033; font-weight: bold;">$true</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #660033; font-weight: bold;">$timer</span>.<span style="color: #003366;">Stop</span><span style="color: #333;">&#40;</span><span style="color: #333;">&#41;</span> &nbsp;<span style="color: #666666; font-style: italic;"># we'd like to stop that timer now, thanks.</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #660033; font-weight: bold;">$clock</span>.<span style="color: #003366;">Close</span><span style="color: #333;">&#40;</span><span style="color: #333;">&#41;</span> <span style="color: #666666; font-style: italic;"># and close the windows</span><br />
&nbsp; &nbsp;<span style="color: #333;">&#125;</span> <span style="color: #333;">&#41;</span><br />
<span style="color: #333;">&#125;</span><br />
&nbsp;</div>

	<h2>So, meet Register-BootsEvent</h2>

	<p>If you&#8217;ve read the previous PowerBoots articles, you know that you can specify events as parameters to the PowerBoots functions, like <code>-On_Click</code> or <code>-On_MouseLeftButtonDown</code>, but in the case where you&#8217;re loading <span class="caps">XAML</span>, you can&#8217;t specify events in the <span class="caps">XAML</span> (WPF&#8217;s XamlReader won&#8217;t read <span class="caps">XAML</span> with events on it, or even with the <code>Class</code> specified, because you can&#8217;t use the associated code file anyway).  </p>

	<p>In any case, what I&#8217;m adding to the next version of PowerBoots/PoshWpf are two functions: </p>

	<ol>
		<li>Find-BootsControl takes a boots window and the <strong>Name</strong> of a control, and will (try to) find the named control. Of course, for that to work, you need to know the name of the control (your best bet is to name it yourself, but in the next version I may also issue names for elements as they are created if you don&#8217;t specify the name).</li>
	</ol>
	<ol>
		<li>Register-BootsEvent takes either a control, OR a boots window and control name, plus an event name and a ScriptBlock.  If you pass the window and name, it calls Find-BootsControl to find the control; once it has a control, it registers the ScriptBlock as a handler for the specified event.</li>
	</ol>

	<p>For now, both of these require that you&#8217;ve assigned a name to the control, but I&#8217;m working on setting things up so controls would be automatically named (based on their type, as with the old WinForms designer: like Button1, Button2, etc.), or allowing an XPath-like selection without named controls. In any case, this will work nicely for generating event handlers for <span class="caps">WPF</span> imported from <span class="caps">XAML</span>, and you can even specify the element directly (ie: if you don&#8217;t specify the -Name parameter, the event will be hooked on whatever element you pass in) so that last block of code can be written like this in the next release:</p>

	<div class="posh code posh" style="font-family:monospace;"><br />
<span style="color: #666666; font-style: italic;">## If we wanted to, say, handle mouse events to let you drag the window or close it ...</span><br />
<span style="color: #0066cc; font-style: italic;">Register-<span style="font-style: normal;">BootsEvent</span></span> <span style="color: #660033; font-weight: bold;">$clock</span> <span style="color: #000066;">-Event</span> MouseLeftButtonDown <span style="color: #000066;">-Action</span> <span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp;<span style="color: #660033; font-weight: bold;">$_</span>.<span style="color: #003366;">Handled</span> <span style="color: #66cc66;">=</span> <span style="color: #660033; font-weight: bold;">$true</span><br />
&nbsp; &nbsp;<span style="color: #660033; font-weight: bold;">$this</span>.<span style="color: #003366;">DragMove</span><span style="color: #333;">&#40;</span><span style="color: #333;">&#41;</span> <span style="color: #666666; font-style: italic;"># WPF Magic!</span><br />
<span style="color: #333;">&#125;</span><br />
<span style="color: #0066cc; font-style: italic;">Register-<span style="font-style: normal;">BootsEvent</span></span> <span style="color: #660033; font-weight: bold;">$clock</span> <span style="color: #000066;">-Event</span> MouseRightButtonDown <span style="color: #000066;">-Action</span> <span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp;<span style="color: #660033; font-weight: bold;">$_</span>.<span style="color: #003366;">Handled</span> <span style="color: #66cc66;">=</span> <span style="color: #660033; font-weight: bold;">$true</span><br />
&nbsp; &nbsp;<span style="color: #660033; font-weight: bold;">$timer</span>.<span style="color: #003366;">Stop</span><span style="color: #333;">&#40;</span><span style="color: #333;">&#41;</span> &nbsp;<span style="color: #666666; font-style: italic;"># we'd like to stop that timer now, thanks.</span><br />
&nbsp; &nbsp;<span style="color: #660033; font-weight: bold;">$this</span>.<span style="color: #003366;">Close</span><span style="color: #333;">&#40;</span><span style="color: #333;">&#41;</span> <span style="color: #666666; font-style: italic;"># and close the windows</span><br />
<span style="color: #333;">&#125;</span><br />
&nbsp;</div>]]></content:encoded>
			<wfw:commentRss>http://joelbennett.net/powerboots-loading-xaml-windows-in-powershell-10-or-20/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>PowerBoots and Attached Properties</title>
		<link>http://joelbennett.net/powerboots-and-attached-properties/</link>
		<comments>http://joelbennett.net/powerboots-and-attached-properties/#comments</comments>
		<pubDate>Sun, 08 Feb 2009 05:53:49 +0000</pubDate>
		<dc:creator>Joel 'Jaykul' Bennett</dc:creator>
				<category><![CDATA[Huddled]]></category>
		<category><![CDATA[Attached Properties]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[PowerBoots]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Scripting]]></category>
		<category><![CDATA[Syntax]]></category>
		<category><![CDATA[WPF]]></category>

		<guid isPermaLink="false">http://huddledmasses.org/?p=1055</guid>
		<description><![CDATA[WPF uses a concept called &#8220;Attached Properties&#8221; to handle certain things, like when you put controls into a DockPanel. Basically, anything you put inside a DockPanel has a property &#8220;Dock&#8221; which you can set &#8230; but because the property is actually defined by the DockPanel, it doesn&#8217;t show up in PowerBoots, so you can&#8217;t just [...]]]></description>
			<content:encoded><![CDATA[	<p><span class="caps">WPF</span> uses a concept called &#8220;Attached Properties&#8221; to handle certain things, like when you put controls into a DockPanel. Basically, anything you put inside a DockPanel has a property &#8220;Dock&#8221; which you can set &#8230; but because the property is actually defined by the DockPanel, it doesn&#8217;t show up in PowerBoots, so you can&#8217;t just say <code>-Dock &#34;Bottom&#34;</code> when you create the child items &#8230; at least, not yet.</p>

	<p>I&#8217;m still thinking about the best way for me to expose this in PowerBoots, because the problem is that attached properties can get attached several ways, and not just on direct children of an element. So I wanted to show you a way that you can do it <em>for now</em> so you can at least use the DockPanel effectively:</p>

	<div class="posh code posh" style="font-family:monospace;">Boots <span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp;DockPanel <span style="color: #000066;">-LastChildFill</span> <span style="color: #660033; font-weight: bold;">$true</span> <span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; DockPanel <span style="color: #000066;">-LastChildFill</span> <span style="color: #660033; font-weight: bold;">$true</span> <span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Button <span style="color: #009900;">&quot;OK&quot;</span> <span style="color: #000066;">-Padding</span> <span style="color: #009900;">&quot;2,0,2,0&quot;</span> <span style="color: #66cc66;">|</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ForEach<span style="color: #66cc66;">-</span>Object <span style="color: #333;">&#123;</span> <span style="color: #660033; font-weight: bold;">$_</span>.<span style="color: #003366;">SetValue</span><span style="color: #333;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #003366; font-weight: bold;"><span style="color: #333;">&#91;</span>System.<span style="color: #003366;">Windows</span>.<span style="color: #003366;">Controls</span>.<span style="color: #003366;">DockPanel</span><span style="color: #333;">&#93;</span></span>::<span style="color: #003366;">DockProperty</span>, <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #003366; font-weight: bold;"><span style="color: #333;">&#91;</span>System.<span style="color: #003366;">Windows</span>.<span style="color: #003366;">Controls</span>.<span style="color: #003366;">Dock</span><span style="color: #333;">&#93;</span></span>::<span style="color: #003366;">Right</span><span style="color: #333;">&#41;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #660033; font-weight: bold;">$_</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #333;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;TextBox <span style="color: #000066;">-HorizontalAlignment</span> Stretch<br />
&nbsp; &nbsp; &nbsp; <span style="color: #333;">&#125;</span> <span style="color: #66cc66;">|</span> ForEach<span style="color: #66cc66;">-</span>Object <span style="color: #333;">&#123;</span> <span style="color: #660033; font-weight: bold;">$_</span>.<span style="color: #003366;">SetValue</span><span style="color: #333;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #003366; font-weight: bold;"><span style="color: #333;">&#91;</span>System.<span style="color: #003366;">Windows</span>.<span style="color: #003366;">Controls</span>.<span style="color: #003366;">DockPanel</span><span style="color: #333;">&#93;</span></span>::<span style="color: #003366;">DockProperty</span>, <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #003366; font-weight: bold;"><span style="color: #333;">&#91;</span>System.<span style="color: #003366;">Windows</span>.<span style="color: #003366;">Controls</span>.<span style="color: #003366;">Dock</span><span style="color: #333;">&#93;</span></span>::<span style="color: #003366;">Bottom</span><span style="color: #333;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #660033; font-weight: bold;">$_</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #333;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; TextBox <span style="color: #000066;">-AcceptsReturn</span> <span style="color: #660033; font-weight: bold;">$true</span> <span style="color: #000066;">-minWidth</span> <span style="color: #cc66cc;">300</span> <span style="color: #000066;">-minHeight</span> <span style="color: #cc66cc;">200</span><br />
&nbsp; &nbsp;<span style="color: #333;">&#125;</span><br />
<span style="color: #333;">&#125;</span></div>

	<h2>A better way &#8230;</h2>

	<p>Here&#8217;s what I&#8217;m thinking about for the next release of PowerBoots (you can take this and use it now, if you like it, but I&#8217;m really looking for, uhm &#8230; better ideas).  Basically, I have written a function: <code>Set-AttachedProperty</code>, which takes an attached property and a value, and passes through the element on the pipeline. You may want to use this in conjunction with the module I published awhile back for creating type accelerators, because it lets you run a line like this:</p>

	<div class="posh code posh" style="font-family:monospace;"><span style="color: #0066cc; font-style: italic;">Add-<span style="font-style: normal;">Accelerator</span></span> DockPanel System.<span style="color: #003366;">Windows</span>.<span style="color: #003366;">Controls</span>.<span style="color: #003366;">DockPanel</span></div>

	<p>Which will let you substitute <code>[DockPanel]</code> for <code>[System.Windows.Controls.DockPanel]</code> &#8230; and of course, you can use it for all the types you want to use attached properties from, and it&#8217;s a real lifesaver if you need to use a bunch of them.  Of course, in this particular example, we really only need to use a single attached property, so it&#8217;s enough to define that property ahead of time:</p>

	<div class="posh code posh" style="font-family:monospace;"><span style="color: #660033; font-weight: bold;">$DockProperty</span> <span style="color: #66cc66;">=</span> <span style="color: #003366; font-weight: bold;"><span style="color: #333;">&#91;</span>System.<span style="color: #003366;">Windows</span>.<span style="color: #003366;">Controls</span>.<span style="color: #003366;">DockPanel</span><span style="color: #333;">&#93;</span></span>::<span style="color: #003366;">DockProperty</span></div>

	<p>Then you can use the <code>Set-AttachedProperty</code> function through an alias <code>sap</code>, and rewrite that huge block above like this:</p>

	<div class="posh code posh" style="font-family:monospace;">Boots <span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp;DockPanel <span style="color: #000066;">-LastChildFill</span> <span style="color: #660033; font-weight: bold;">$true</span> <span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; DockPanel <span style="color: #000066;">-LastChildFill</span> <span style="color: #660033; font-weight: bold;">$true</span> <span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Button <span style="color: #009900;">&quot;OK&quot;</span> <span style="color: #000066;">-Padding</span> <span style="color: #009900;">&quot;2,0,2,0&quot;</span> <span style="color: #66cc66;">|</span> sap <span style="color: #660033; font-weight: bold;">$DockProperty</span> Right<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;TextBox <span style="color: #000066;">-HorizontalAlignment</span> Stretch<br />
&nbsp; &nbsp; &nbsp; <span style="color: #333;">&#125;</span> <span style="color: #66cc66;">|</span> sap <span style="color: #660033; font-weight: bold;">$DockProperty</span> Bottom<br />
&nbsp; &nbsp; &nbsp; TextBox <span style="color: #000066;">-AcceptsReturn</span> <span style="color: #660033; font-weight: bold;">$true</span> <span style="color: #000066;">-minWidth</span> <span style="color: #cc66cc;">300</span> <span style="color: #000066;">-minHeight</span> <span style="color: #cc66cc;">200</span><br />
&nbsp; &nbsp;<span style="color: #333;">&#125;</span><br />
<span style="color: #333;">&#125;</span></div>

	<p>Pretty slick, right? And it will even print out the list of values in the error message if you invoke it with an invalid value against an enum property like dock:  <code>sap $DockProperty &#34;&#34;</code> &#8230; The problem I have with it is that you have to predefine your <code>$DockProperty</code> variable, and you can&#8217;t just define it against the root class.  So I&#8217;m trying to find a way to tweak the dynamic property generation to make it so that the pipe into <code>| sap $DockProperty Bottom</code>  can just be a parameter to the original element: <code>-Dock Bottom</code> &#8230; if I can&#8217;t find that, in the worst case scenario, I&#8217;ll just add an -AttachedProperties parameter with a hashtable of $DockProperty,&#8220;Bottom&#8221; or something &#8230; <em>what do you think?</em>  </p>

	<p>In any case, here&#8217;s the sap function, for now, and remember to use it as part of the pipeline:</p>

	<div class="posh code posh" style="font-family:monospace;"><br />
<span style="color: #666699; font-weight: bold;">function</span> <span style="color: #0066cc; font-style: italic;">Set-<span style="font-style: normal;">AttachedProperty</span></span> <span style="color: #333;">&#123;</span><br />
<span style="color: #333;">&#91;</span>CmdletBinding<span style="color: #333;">&#40;</span><span style="color: #333;">&#41;</span><span style="color: #333;">&#93;</span><br />
<span style="color: #666699; font-weight: bold;">PARAM</span><span style="color: #333;">&#40;</span><br />
&nbsp; &nbsp;<span style="color: #333;">&#91;</span>Parameter<span style="color: #333;">&#40;</span>Position<span style="color: #66cc66;">=</span><span style="color: #cc66cc;">0</span>,Mandatory<span style="color: #66cc66;">=</span><span style="color: #660033; font-weight: bold;">$true</span><span style="color: #333;">&#41;</span><br />
&nbsp; &nbsp;<span style="color: #003366; font-weight: bold;"><span style="color: #333;">&#91;</span>System.<span style="color: #003366;">Windows</span>.<span style="color: #003366;">DependencyProperty</span><span style="color: #333;">&#93;</span></span><br />
&nbsp; &nbsp;<span style="color: #660033; font-weight: bold;">$Property</span><br />
,<br />
&nbsp; &nbsp;<span style="color: #333;">&#91;</span>Parameter<span style="color: #333;">&#40;</span>Mandatory<span style="color: #66cc66;">=</span><span style="color: #660033; font-weight: bold;">$true</span>,ValueFromPipeline<span style="color: #66cc66;">=</span><span style="color: #660033; font-weight: bold;">$true</span><span style="color: #333;">&#41;</span><br />
&nbsp; &nbsp;<span style="color: #660033; font-weight: bold;">$Element</span><br />
<span style="color: #333;">&#41;</span><br />
<span style="color: #666699; font-weight: bold;">DYNAMICPARAM</span> <span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp;<span style="color: #660033; font-weight: bold;">$paramDictionary</span> <span style="color: #66cc66;">=</span> <span style="color: #0066cc; font-style: italic;">new-<span style="font-style: normal;">object</span></span> System.<span style="color: #003366;">Management</span>.<span style="color: #003366;">Automation</span>.<span style="color: #003366;">RuntimeDefinedParameterDictionary</span><br />
&nbsp; &nbsp;<span style="color: #660033; font-weight: bold;">$Param1</span> <span style="color: #66cc66;">=</span> <span style="color: #0066cc; font-style: italic;">new-<span style="font-style: normal;">object</span></span> System.<span style="color: #003366;">Management</span>.<span style="color: #003366;">Automation</span>.<span style="color: #003366;">RuntimeDefinedParameter</span><br />
&nbsp; &nbsp;<span style="color: #660033; font-weight: bold;">$Param1</span>.<span style="color: #003366;">Name</span> <span style="color: #66cc66;">=</span> <span style="color: #009900;">&quot;Value&quot;</span><br />
&nbsp; &nbsp;<span style="color: #666666; font-style: italic;"># $Param1.Attributes.Add( (New-ParameterAttribute -Position 1) )</span><br />
&nbsp; &nbsp;<span style="color: #660033; font-weight: bold;">$Param1</span>.<span style="color: #003366;">Attributes</span>.<span style="color: #003366;">Add</span><span style="color: #333;">&#40;</span> <span style="color: #333;">&#40;</span><span style="color: #0066cc; font-style: italic;">New-<span style="font-style: normal;">Object</span></span> System.<span style="color: #003366;">Management</span>.<span style="color: #003366;">Automation</span>.<span style="color: #003366;">ParameterAttribute</span> <span style="color: #000066;">-Property</span> @<span style="color: #333;">&#123;</span> Position <span style="color: #66cc66;">=</span> <span style="color: #cc66cc;">1</span> <span style="color: #333;">&#125;</span><span style="color: #333;">&#41;</span> <span style="color: #333;">&#41;</span><br />
&nbsp; &nbsp;<span style="color: #660033; font-weight: bold;">$Param1</span>.<span style="color: #003366;">ParameterType</span> <span style="color: #66cc66;">=</span> <span style="color: #660033; font-weight: bold;">$Property</span>.<span style="color: #003366;">PropertyType</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp;<span style="color: #660033; font-weight: bold;">$paramDictionary</span>.<span style="color: #003366;">Add</span><span style="color: #333;">&#40;</span><span style="color: #009900;">&quot;Value&quot;</span>, <span style="color: #660033; font-weight: bold;">$Param1</span><span style="color: #333;">&#41;</span><br />
&nbsp; &nbsp;<br />
&nbsp; &nbsp;<span style="color: #666699; font-weight: bold;">return</span> <span style="color: #660033; font-weight: bold;">$paramDictionary</span><br />
<span style="color: #333;">&#125;</span><br />
<span style="color: #666699; font-weight: bold;">PROCESS</span> <span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp;<span style="color: #660033; font-weight: bold;">$Element</span>.<span style="color: #003366;">SetValue</span><span style="color: #333;">&#40;</span><span style="color: #660033; font-weight: bold;">$Property</span>, <span style="color: #660033; font-weight: bold;">$Param1</span>.<span style="color: #003366;">Value</span><span style="color: #333;">&#41;</span><br />
&nbsp; &nbsp;<span style="color: #660033; font-weight: bold;">$Element</span><br />
<span style="color: #333;">&#125;</span><br />
<span style="color: #333;">&#125;</span><br />
<br />
<span style="color: #0066cc; font-style: italic;">New-<span style="font-style: normal;">Alias</span></span> sap <span style="color: #0066cc; font-style: italic;">Set-<span style="font-style: normal;">AttachedProperty</span></span><br />
&nbsp;</div>]]></content:encoded>
			<wfw:commentRss>http://joelbennett.net/powerboots-and-attached-properties/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PowerBoots: PowerShell GUIs are now multi-threading</title>
		<link>http://joelbennett.net/powerboots-now-multi-threaded/</link>
		<comments>http://joelbennett.net/powerboots-now-multi-threaded/#comments</comments>
		<pubDate>Sat, 07 Feb 2009 23:21:24 +0000</pubDate>
		<dc:creator>Joel 'Jaykul' Bennett</dc:creator>
				<category><![CDATA[Huddled]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[DSL]]></category>
		<category><![CDATA[GUIs]]></category>
		<category><![CDATA[PowerBoots]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Scripting]]></category>
		<category><![CDATA[User Interface]]></category>
		<category><![CDATA[Visifire]]></category>
		<category><![CDATA[WPF]]></category>

		<guid isPermaLink="false">http://huddledmasses.org/?p=1045</guid>
		<description><![CDATA[Announcing the release of PowerBoots 0.1 This release of PowerBoots is the most exciting release software I&#8217;ve cranked out in awhile. It finally has almost all of the features that I have thought of so far (we&#8217;re still missing proper support for attached properties). You can create pretty much any WPF element, including ones I [...]]]></description>
			<content:encoded><![CDATA[	<h2>Announcing the release of PowerBoots 0.1</h2>

	<p>This release of PowerBoots is the most exciting release software I&#8217;ve cranked out in awhile. It finally has almost all of the features that I have thought of so far (we&#8217;re still missing proper support for attached properties).</p>

	<ul>
		<li>You can create pretty much any <span class="caps">WPF</span> element, including ones I haven&#8217;t thought of adding yet (use Add-BootsFunction to add a new assembly or a single type).</li>
		<li>You can create graphical user interfaces from <a class="zem_slink" href="http://www.microsoft.com/powershell" title="Windows PowerShell" rel="homepage">PowerShell</a> 1.0 all the way to the latest PowerShell 2.0 <span class="caps">CTP</span>.</li>
		<li>You can create your <span class="caps">WPF</span> GUIs <code>-Async</code> <span class="em1">in their own threads</span>, or inline in <a href="http://PoshConsole.CodePlex.com">PoshConsole</a>, or as synchronous dialogs that return values when they close.</li>
		<li>You can capture screenshots of your UIs (eg: <a href="http://huddledmasses.org/powerboots-output-graphs-to-images-from-powershell/">generate .jpg charts from Visifire</a>). You can even do so <strong>without displaying them!</strong></li>
		<li>You can take advantage of <a class="zem_slink" href="http://en.wikipedia.org/wiki/Extensible_Application_Markup_Language" title="Extensible Application Markup Language" rel="wikipedia">XAML</a> Data Templates to generate graphical representations of any objects in the PowerShell pipeline.</li>
	</ul>
	<ul>
		<li>You can add to, or modify your running GUIs from the command line.</li>
	</ul>

	<p>You can read the &#8220;and much much more&#8221; between the lines right?</p>

<object height="280" width="640"> 
<param name="movie" value="http://content.screencast.com/users/Jaykul/folders/Jing/media/5688481d-eb1e-4d47-b91b-31dc9584e465/jingswfplayer.swf" />
<param name="quality" value="high" /> 
<param name="bgcolor" value="#FFFFFF" />
<param name="flashVars" value="thumb=http://content.screencast.com/users/Jaykul/folders/Jing/media/5688481d-eb1e-4d47-b91b-31dc9584e465/FirstFrame.jpg&amp;width=640&amp;height=280&amp;content=http://content.screencast.com/users/Jaykul/folders/Jing/media/5688481d-eb1e-4d47-b91b-31dc9584e465/PowerBootsMonitoring.swf" />
<param name="allowFullScreen" value="true" /> 
<param name="scale" value="showall" />
<param name="allowScriptAccess" value="always" />
<param name="base" value="http://content.screencast.com/users/Jaykul/folders/Jing/media/5688481d-eb1e-4d47-b91b-31dc9584e465/" />  <embed src="http://content.screencast.com/users/Jaykul/folders/Jing/media/5688481d-eb1e-4d47-b91b-31dc9584e465/jingswfplayer.swf" quality="high" bgcolor="#FFFFFF" type="application/x-shockwave-flash" allowscriptaccess="always" flashvars="thumb=http://content.screencast.com/users/Jaykul/folders/Jing/media/5688481d-eb1e-4d47-b91b-31dc9584e465/FirstFrame.jpg&amp;width=640&amp;height=280&amp;content=http://content.screencast.com/users/Jaykul/folders/Jing/media/5688481d-eb1e-4d47-b91b-31dc9584e465/PowerBootsMonitoring.swf" allowfullscreen="true" base="http://content.screencast.com/users/Jaykul/folders/Jing/media/5688481d-eb1e-4d47-b91b-31dc9584e465/" scale="showall" height="280" width="640"></embed>
</object><span id="more-1045"></span>

	<h3>Breaking Changes and New Features</h3>

	<p>The big new thing in this release is that I&#8217;ve added a compiled module (PoshWpf) which contains several cmdlets, and gives us some major new functionality in exchange for a break in the syntax.  The syntax change is pretty simple, really, and the new threading functionality (and PowerShell 1.0 support for the cmdlets) is awesome (if I do say so myself)  <img src='http://joelbennett.net/wordpress/wp-includes/' alt=':)' class='wp-smiley' /> .</p>

	<h4>New-BootsWindow replaces Out-Boots</h4>

	<p>New-BootsWindow is a compiled cmdlet, and in addition to all of the features already present in the now deprecated Out-Boots, it features a few important new features. Incidentally, I&#8217;ve actually left the old Out-Boots function in the code, just in case, but I&#8217;ve renamed it to Out-BootsWindow, and changed the &#8220;Boots&#8221; alias to point at the new New-BootsWindow.</p>

	<h5>ScriptBlock Content</h5>

	<p>The biggest change to your scripts is going to be a change from piping objects into Out-Boots, to creating your objects in a scriptblock parameter to New-BootsWindow. This allows the script to create the UI elements entirely within the new thread.  Since we&#8217;ve switched the &#8220;Boots&#8221; alias to point to New-BootsWindow, anything you used to write like this: <code> ... | Boots</code> you should now be able to write like this: <code>Boots { ... }</code> and get the same result. Additionally, to make the syntax of our little <span class="caps">DSL</span> just a little bit slicker, I now allow you to pass scriptblocks for just about everything (particularly for the main content parameters).  An example that looked like this, before:</p>

	<div class="posh code posh" style="font-family:monospace;"><br />
StackPanel <span style="color: #000066;">-Margin</span> <span style="color: #cc66cc;">10</span> <span style="color: #000066;">-Children</span> $<span style="color: #333;">&#40;</span><br />
&nbsp; &nbsp;TextBlock <span style="color: #009900;">&quot;The Question&quot;</span> <span style="color: #000066;">-FontSize</span> <span style="color: #cc66cc;">42</span> <span style="color: #000066;">-FontWeight</span> Bold <span style="color: #000066;">-Foreground</span> <span style="color: #009900;">&quot;#FF0088&quot;</span><br />
&nbsp; &nbsp;TextBlock <span style="color: #000066;">-FontSize</span> <span style="color: #cc66cc;">24</span> <span style="color: #000066;">-Inlines</span> $<span style="color: #333;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; Hyperlink $<span style="color: #333;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Bold <span style="color: #009900;">&quot;Q. &quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #009900;">&quot;Can PowerBoots do async threads?&quot;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #333;">&#41;</span> <span style="color: #000066;">-NavigateUri</span> <span style="color: #009900;">&quot;_&quot;</span> <span style="color: #000066;">-On_RequestNavigate</span> <span style="color: #333;">&#123;</span> <span style="color: #660033; font-weight: bold;">$global</span>:Answer<span style="color: #333;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #333;">&#93;</span>.<span style="color: #003366;">Visibility</span> <span style="color: #66cc66;">=</span> <span style="color: #009900;">&quot;Visible&quot;</span> <span style="color: #333;">&#125;</span><br />
&nbsp; &nbsp;<span style="color: #333;">&#41;</span><br />
&nbsp; &nbsp;TextBlock <span style="color: #000066;">-FontSize</span> <span style="color: #cc66cc;">16</span> <span style="color: #000066;">-Inlines</span> $<span style="color: #333;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; Span <span style="color: #000066;">-FontSize</span> <span style="color: #cc66cc;">24</span> <span style="color: #000066;">-FontWeight</span> Bold <span style="color: #000066;">-Inlines</span> <span style="color: #009900;">&quot;A. &quot;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #009900;">&quot;Not this way!&quot;</span><br />
&nbsp; &nbsp;<span style="color: #333;">&#41;</span> <span style="color: #000066;">-OV</span> global:Answer <span style="color: #000066;">-Visibility</span> Collapsed<br />
<span style="color: #333;">&#41;</span> <span style="color: #66cc66;">|</span> <span style="color: #0066cc; font-style: italic;">Out-<span style="font-style: normal;">BootsWindow</span></span> </div>

	<p>Can actually end up like this, now (and produce the same output):</p>

	<div class="posh code posh" style="font-family:monospace;"><br />
Boots <span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp;StackPanel <span style="color: #000066;">-Margin</span> <span style="color: #cc66cc;">10</span> <span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; TextBlock <span style="color: #009900;">&quot;The Question&quot;</span> <span style="color: #000066;">-FontSize</span> <span style="color: #cc66cc;">42</span> <span style="color: #000066;">-FontWeight</span> Bold <span style="color: #000066;">-Foreground</span> <span style="color: #009900;">&quot;#FF0088&quot;</span><br />
&nbsp; &nbsp; &nbsp; TextBlock <span style="color: #000066;">-FontSize</span> <span style="color: #cc66cc;">24</span> <span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Hyperlink <span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Bold <span style="color: #009900;">&quot;Q. &quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&quot;Can PowerBoots do async threads?&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #333;">&#125;</span> <span style="color: #000066;">-NavigateUri</span> <span style="color: #009900;">&quot; &quot;</span> <span style="color: #000066;">-On_RequestNavigate</span> <span style="color: #333;">&#123;</span> <span style="color: #660033; font-weight: bold;">$global</span>:Answer<span style="color: #333;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #333;">&#93;</span>.<span style="color: #003366;">Visibility</span> <span style="color: #66cc66;">=</span> <span style="color: #009900;">&quot;Visible&quot;</span> <span style="color: #333;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #333;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; TextBlock <span style="color: #000066;">-FontSize</span> <span style="color: #cc66cc;">16</span> <span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Span <span style="color: #009900;">&quot;A. &quot;</span> <span style="color: #000066;">-FontSize</span> <span style="color: #cc66cc;">24</span> <span style="color: #000066;">-FontWeight</span> Bold <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #009900;">&quot;Oh yes we can!&quot;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #333;">&#125;</span> <span style="color: #000066;">-OV</span> global:Answer <span style="color: #000066;">-Visibility</span> Collapsed<br />
&nbsp; &nbsp;<span style="color: #333;">&#125;</span><br />
<span style="color: #333;">&#125;</span> </div>

	<h5>The Async Parameter</h5>

	<p>If you specify <code>-Async</code>, the new popup window is spawned in a new thread, and all of it&#8217;s events etc. are handled on that separate thread.  This is actually what happens anyway when you run New-BootsWindow from a host that&#8217;s not running in <code>STA</code> mode, but if you don&#8217;t specify -Async, we fake the synchronous result so that you can use <code>Write-Output</code> within a dialog to prompt and get a result &#8220;returned&#8221; from New-BootsWindow. The cool thing about <code>-Async</code> is that not only can you continue using your console, you can run additional windows, and you can even use the new <code>Invoke-BootsWindow</code> cmdlet to run scripts within that window&#8217;s thread so you can change the <span class="caps">GUI</span> content, etc.</p>

	<h5>The Passthru Parameter</h5>

	<p>The <code>-Passthru</code> parameter causes the New-BootsWindow to output the window object that it has created to the pipeline.  It&#8217;s really only useful when you also specify the <code>-Async</code> parameter, since otherwise the window will be closed before you can use it.  Furthermore, because it&#8217;s a UI element, you can&#8217;t really do very much directly on the Window object without the use of our other cmdlets</p>

	<h4>The BootsWindow Collection</h4>

	<p>When you create a New-BootsWindow, the PowerBoots module (or snapin, for v1 users) tracks the window for you, so you can get ahold of it again later to run scripts against it, take screenshots, close it, etc.  To enable this we have three new cmdlets:</p>

	<ul>
		<li><code>Get-BootsWindow</code> returns the windows, and supports filtering by title or index.</li>
		<li><code>Remove-BootsWindow</code> will clear the list of windows that have already been closed, when called without parameters, or will close (and remove) windows that are still running if you pass a specific window, index, or window title.</li>
		<li><code>Invoke-BootsWindow</code> lets you run scriptblocks in a specific window&#8217;s thread</li>
	</ul>
	<ul>
		<li><code>Export-BootsImage</code> lets you take a screen capture of the contents of a window (or of a specific control)</li>
	</ul>

	<h4>Add and Remove Templates</h4>

	<p>There are three new cmdlets for managing <span class="caps">XAML</span> source files.  Add, Remove, and Get BootsTemplate. These allow you to specify additional <span class="caps">XAML</span> files (beyond the default.xaml), and those templates are always automatically loaded into each new window, so you can specify styles, resources, data templates and even new <span class="caps">WPF</span> Templates (I&#8217;ll throw up an example using the ones from <a href="http://WpfThemes.CodePlex.com"><span class="caps">WPF</span> Themes</a> later this weekend).</p>

	<h2>Download and Source now hosted on CodePlex</h2>

	<p>Well, that&#8217;s enough for the highlights for now. I&#8217;ve included the first blush efforts of a ps1xml format and data types files (which get loaded automatically with the module on PowerShell 2, but not v1), and I haven&#8217;t yet written up the help files for the compiled cmdlets.  Look for more help and examples and maybe even some cleaned up sample videos over the weekend. Please file any problems you have as bugs on <a href="http://boots.codeplex.com">Boots.CodePlex.com</a>, where you can find the <a href="http://boots.codeplex.com/Release/ProjectReleases.aspx">latest release</a>.</p>

	<p>I do want to point out that I&#8217;ve left the version number at 0.1 &#8230; I really want to add some explicit support for attached properties, and I&#8217;m sure I&#8217;ve missed a bug or two somewhere along the line  <img src='http://joelbennett.net/wordpress/wp-includes/' alt=';)' class='wp-smiley' />  lets consider this another <strong>solid</strong> beta release.</p>

<div class="zemanta-pixie"><a class="zemanta-pixie-a" href="http://reblog.zemanta.com/zemified/0b00377a-7c0c-4703-abb8-4effc7afedbd/" title="Zemified by Zemanta"><img class="zemanta-pixie-img" src="http://img.zemanta.com/reblog_e.png?x-id=0b00377a-7c0c-4703-abb8-4effc7afedbd" alt="Reblog this post [with Zemanta]" /></a></div>]]></content:encoded>
			<wfw:commentRss>http://joelbennett.net/powerboots-now-multi-threaded/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>PowerBoots &#8211; Output Graphs to Images from PowerShell</title>
		<link>http://joelbennett.net/powerboots-output-graphs-to-images-from-powershell/</link>
		<comments>http://joelbennett.net/powerboots-output-graphs-to-images-from-powershell/#comments</comments>
		<pubDate>Fri, 16 Jan 2009 06:01:08 +0000</pubDate>
		<dc:creator>Joel 'Jaykul' Bennett</dc:creator>
				<category><![CDATA[Huddled]]></category>
		<category><![CDATA[Charting]]></category>
		<category><![CDATA[Charts]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[PowerBoots]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Visifire]]></category>
		<category><![CDATA[WPF]]></category>

		<guid isPermaLink="false">http://huddledmasses.org/?p=1019</guid>
		<description><![CDATA[Once I started playing with the new ability, introduced in PowerBoots 0.0.4 to easily add support for new graphical controls to PowerBoots, I found all sorts of fun widgets out there in open-source land. I&#8217;ll write about a few of them in the future, but for now I&#8217;m just going to stick with Visifire. After [...]]]></description>
			<content:encoded><![CDATA[	<p>Once I started playing with the new ability, introduced in <a href="http://huddledmasses.org/PowerBoots/">PowerBoots</a> 0.0.4 to easily add support for new graphical controls to PowerBoots, I found all sorts of fun widgets out there in open-source land.  I&#8217;ll write about a few of them in the future, but for now I&#8217;m just going to stick with Visifire.  After playing with a few examples, I finally got around to actually trying to create the graphs I needed at work which were the main source of motivation for trying to do Visifire from PowerShell anyway &#8230;</p>

	<p>The problem was, half of the need we have for graphs is to throw them up on a web-server &#8230; so I needed a way to take the <span class="caps">WPF</span> window, and capture the controls and visuals as an image. Basically, render the <span class="caps">WPF</span> control to a bitmap image, instead of to the screen.  To cut a long story short, I figured it out of course &#8212; why else would I be writing this? (<a href="http://huddledmasses.org/PowerBoots/">get it here</a>).</p>

	<h2>Out-BootsImage</h2>

	<p>So the new version of PowerBoots includes the Out-BootsImage function (aliased as BootsImage and &#8220;obi&#8221;), which basically is designed to take the filename of an image, and a boots visual element, and create a screenshot.  It can generate bmp, gif, jpg, png, tiff, and even Microsoft&#8217;s new <a href="http://www.microsoft.com/windows/windowsmedia/wmphoto" title="HD Photo">wdp</a> format, or it can output to clipboard.</p>

	<p><img src="http://huddledmasses.org/images/PowerBoots/VisiFire-BootsImage.jpg" align="right" alt="" width="200" height="150" /></p>

	<p>It&#8217;s late, so I&#8217;m not going to write any more about this &#8230; the bottom line is, if you have been looking for a (free) way to generate graphs and charts to image files in PowerShell, this will work for you: go grab <a href="http://www.visifire.com/">Visifire</a>, check out their <a href="http://www.visifire.com/silverlight_charts_gallery.php">gallery</a> for inspiration, and start churning out graphs! Just for fun, here are the samples from the help documentation (except, this is the actual script I ran, including the upload code) with screen-shots &#8230;  </p>

	<h3>Important note</h3>

	<p>When producing images of Visifire charts using this method, it is absolutely critical that <strong>you must specify <code>-Animation $false</code></strong> because otherwise you will consistenly produce images of empty charts (since by default Visifire animates all of the bars onto the screen right <em>after</em> the <code>SourceInitialized</code> event that I use to capture the image). Oh, and if you need to remove the Visifire.com watermark, there is a <code>-watermark $false</code> parameter on the <code>Chart</code> element, which turns it off.</p>

	<p><img src="http://huddledmasses.org/images/PowerBoots/VisiFire-OutImage.jpg" alt="" width="200" height="150" /></p>

	<div class="posh code posh" style="font-family:monospace;"><br />
<span style="color: #660033; font-weight: bold;">$credential</span> <span style="color: #66cc66;">=</span> <span style="color: #0066cc; font-style: italic;">Get-<span style="font-style: normal;">Credential</span></span><br />
<br />
Chart <span style="color: #000066;">-Width</span> <span style="color: #cc66cc;">200</span> <span style="color: #000066;">-Height</span> <span style="color: #cc66cc;">150</span> <span style="color: #000066;">-Theme</span> Theme3 <span style="color: #000066;">-Watermark</span> <span style="color: #660033; font-weight: bold;">$false</span> <span style="color: #000066;">-Animation</span> <span style="color: #660033; font-weight: bold;">$false</span> <span style="color: #333;">&#40;</span><br />
&nbsp; &nbsp;DataSeries $<span style="color: #333;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; 1..<span style="color: #333;">&#40;</span><span style="color: #0066cc; font-style: italic;">Get-<span style="font-style: normal;">Random</span></span> <span style="color: #000066;">-min</span> <span style="color: #cc66cc;">3</span> <span style="color: #000066;">-max</span> <span style="color: #cc66cc;">6</span><span style="color: #333;">&#41;</span> <span style="color: #66cc66;">|</span> ForEach<span style="color: #66cc66;">-</span>Object &nbsp;<span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;DataPoint <span style="color: #000066;">-YValue</span> <span style="color: #333;">&#40;</span><span style="color: #0066cc; font-style: italic;">Get-<span style="font-style: normal;">Random</span></span> <span style="color: #cc66cc;">100</span><span style="color: #333;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #333;">&#125;</span><br />
&nbsp; &nbsp;<span style="color: #333;">&#41;</span><br />
<span style="color: #333;">&#41;</span> <span style="color: #66cc66;">|</span> <span style="color: #0066cc; font-style: italic;">Out-<span style="font-style: normal;">BootsImage</span></span> VisiFire<span style="color: #66cc66;">-</span>BootsImage.<span style="color: #003366;">jpg</span> <span style="color: #66cc66;">|</span>ForEach<span style="color: #66cc66;">-</span>Object <span style="color: #333;">&#123;</span> <br />
&nbsp; &nbsp;<span style="color: #0066cc; font-style: italic;">Send-<span style="font-style: normal;">FTP</span></span> HuddledMasses.<span style="color: #003366;">org</span> <span style="color: #660033; font-weight: bold;">$credential</span> <span style="color: #000066;">-LocalFile</span> <span style="color: #660033; font-weight: bold;">$_</span> <span style="color: #000066;">-Remotefile</span> <span style="color: #009900;">&quot;$imgPath/$($_.Name)&quot;</span> <br />
&nbsp; &nbsp;<span style="color: #003366; font-weight: bold;"><span style="color: #333;">&#91;</span>Windows.<span style="color: #003366;">Clipboard</span><span style="color: #333;">&#93;</span></span>::<span style="color: #003366;">SetText</span><span style="color: #333;">&#40;</span> <span style="color: #009900;">&quot;!http://huddledmasses.org/images/PowerBoots/$($_.Name)!&quot;</span> <span style="color: #333;">&#41;</span><br />
<span style="color: #333;">&#125;</span><br />
<br />
StackPanel <span style="color: #000066;">-Margin</span> <span style="color: #009900;">&quot;10,5,10,5&quot;</span> $<span style="color: #333;">&#40;</span> <br />
&nbsp; &nbsp;Label <span style="color: #009900;">&quot;Please enter your name:&quot;</span><br />
&nbsp; &nbsp;StackPanel <span style="color: #000066;">-Orientation</span> Horizontal $<span style="color: #333;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; TextBox <span style="color: #000066;">-OutVariable</span> global:textbox <span style="color: #000066;">-Width</span> <span style="color: #cc66cc;">150</span> <span style="color: #000066;">-On_KeyDown</span> <span style="color: #333;">&#123;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #666699; font-weight: bold;">if</span><span style="color: #333;">&#40;</span><span style="color: #660033; font-weight: bold;">$_</span>.<span style="color: #003366;">Key</span> <span style="color: #000066;">-eq</span> <span style="color: #009900;">&quot;Return&quot;</span><span style="color: #333;">&#41;</span> <span style="color: #333;">&#123;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066cc; font-style: italic;">Write-<span style="font-style: normal;">Output</span></span> <span style="color: #660033; font-weight: bold;">$textbox</span><span style="color: #333;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #333;">&#93;</span>.<span style="color: #003366;">Text</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #660033; font-weight: bold;">$BootsWindow</span>.<span style="color: #003366;">Close</span><span style="color: #333;">&#40;</span><span style="color: #333;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #333;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #333;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; Button <span style="color: #009900;">&quot;Ok&quot;</span> <span style="color: #000066;">-Padding</span> <span style="color: #009900;">&quot;5,0,5,0&quot;</span> <span style="color: #000066;">-Margin</span> <span style="color: #009900;">&quot;2,0,0,0&quot;</span> <span style="color: #000066;">-On_Click</span> <span style="color: #333;">&#123;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0066cc; font-style: italic;">Write-<span style="font-style: normal;">Output</span></span> <span style="color: #660033; font-weight: bold;">$textbox</span><span style="color: #333;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #333;">&#93;</span>.<span style="color: #003366;">Text</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #660033; font-weight: bold;">$BootsWindow</span>.<span style="color: #003366;">Close</span><span style="color: #333;">&#40;</span><span style="color: #333;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #333;">&#125;</span><br />
&nbsp; &nbsp;<span style="color: #333;">&#41;</span><br />
<span style="color: #333;">&#41;</span> <span style="color: #66cc66;">|</span> <span style="color: #0066cc; font-style: italic;">Out-<span style="font-style: normal;">BootsImage</span></span> BootsImage<span style="color: #66cc66;">-</span>Screenshot.<span style="color: #003366;">jpg</span> <span style="color: #66cc66;">|</span> ForEach<span style="color: #66cc66;">-</span>Object <span style="color: #333;">&#123;</span> <br />
&nbsp; &nbsp;<span style="color: #0066cc; font-style: italic;">Send-<span style="font-style: normal;">FTP</span></span> HuddledMasses.<span style="color: #003366;">org</span> <span style="color: #660033; font-weight: bold;">$credential</span> <span style="color: #000066;">-LocalFile</span> <span style="color: #660033; font-weight: bold;">$_</span> <span style="color: #000066;">-Remotefile</span> <span style="color: #009900;">&quot;$imgPath/$($_.Name)&quot;</span> <br />
&nbsp; &nbsp;<span style="color: #003366; font-weight: bold;"><span style="color: #333;">&#91;</span>Windows.<span style="color: #003366;">Clipboard</span><span style="color: #333;">&#93;</span></span>::<span style="color: #003366;">SetText</span><span style="color: #333;">&#40;</span> <span style="color: #009900;">&quot;!http://huddledmasses.org/images/PowerBoots/$($_.Name)!&quot;</span> <span style="color: #333;">&#41;</span><br />
<span style="color: #333;">&#125;</span><br />
&nbsp;</div>]]></content:encoded>
			<wfw:commentRss>http://joelbennett.net/powerboots-output-graphs-to-images-from-powershell/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

