<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Media And Microcode : WPF</title><link>http://blogs.msdn.com/mediaandmicrocode/archive/tags/WPF/default.aspx</link><description>Tags: WPF</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>Write-Progress &amp;amp; WPK</title><link>http://blogs.msdn.com/mediaandmicrocode/archive/2009/12/28/write-progress-wpk.aspx</link><pubDate>Mon, 28 Dec 2009 21:10:43 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9941716</guid><dc:creator>JamesBrundage</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.msdn.com/mediaandmicrocode/comments/9941716.aspx</comments><wfw:commentRss>http://blogs.msdn.com/mediaandmicrocode/commentrss.aspx?PostID=9941716</wfw:commentRss><description>&lt;p&gt;A nifty trick that you can do in WPK is create a WPF progress bar to show the Write-Progress output from a PowerShell script.&amp;#160; I was reminded that people actually wanted to do this when I ran across a question on StackOverflow, and posted &lt;a href="http://stackoverflow.com/questions/1959129/insert-progressbar-into-statusbar-panel-using-powershell-and-windows-forms/1971546#1971546"&gt;this answer&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;In case you don’t want to follow the link, here’s a quick script to show progress from a background runspace in WPK.&amp;#160; The top half set ups a bunch of data bindings that will bind to whatever DataContext is found, and the second half of the script is a small sample of Write-Progress output.&lt;/p&gt;  &lt;pre class="PowerShellColorizedScript"&gt;&lt;span style="color: #0000ff"&gt;New-Grid&lt;/span&gt; &lt;span style="color: #000080"&gt;-Columns&lt;/span&gt; &lt;span style="color: #800080"&gt;2&lt;/span&gt; &lt;span style="color: #000000"&gt;{&lt;/span&gt;            
    &lt;span style="color: #0000ff"&gt;New-TextBlock&lt;/span&gt; &lt;span style="color: #000080"&gt;-Margin&lt;/span&gt; &lt;span style="color: #800080"&gt;10&lt;/span&gt; &lt;span style="color: #000080"&gt;-TextWrapping&lt;/span&gt; &lt;span style="color: #8a2be2"&gt;Wrap&lt;/span&gt; &lt;span style="color: #000080"&gt;-ZIndex&lt;/span&gt; &lt;span style="color: #800080"&gt;1&lt;/span&gt; &lt;span style="color: #000080"&gt;-HorizontalAlignment&lt;/span&gt; &lt;span style="color: #8a2be2"&gt;Left&lt;/span&gt; &lt;span style="color: #000080"&gt;-FontWeight&lt;/span&gt; &lt;span style="color: #8a2be2"&gt;Bold&lt;/span&gt; &lt;span style="color: #000080"&gt;-FontSize&lt;/span&gt; &lt;span style="color: #800080"&gt;12&lt;/span&gt; &lt;span style="color: #000080"&gt;-DataBinding&lt;/span&gt; &lt;span style="color: #000000"&gt;@{&lt;/span&gt;            
        &lt;span style="color: #8b0000"&gt;&amp;quot;Text&amp;quot;&lt;/span&gt; &lt;span style="color: #a9a9a9"&gt;=&lt;/span&gt; &lt;span style="color: #8b0000"&gt;&amp;quot;LastProgress.Activity&amp;quot;&lt;/span&gt;            
    &lt;span style="color: #000000"&gt;}&lt;/span&gt;            
    &lt;span style="color: #0000ff"&gt;New-TextBlock&lt;/span&gt; &lt;span style="color: #000080"&gt;-Margin&lt;/span&gt; &lt;span style="color: #800080"&gt;10&lt;/span&gt; &lt;span style="color: #000080"&gt;-ZIndex&lt;/span&gt; &lt;span style="color: #800080"&gt;1&lt;/span&gt; &lt;span style="color: #000080"&gt;-TextWrapping&lt;/span&gt; &lt;span style="color: #8a2be2"&gt;Wrap&lt;/span&gt; &lt;span style="color: #000080"&gt;-Column&lt;/span&gt; &lt;span style="color: #800080"&gt;1&lt;/span&gt; &lt;span style="color: #000080"&gt;-VerticalAlignment&lt;/span&gt; &lt;span style="color: #8a2be2"&gt;Bottom&lt;/span&gt; &lt;span style="color: #000080"&gt;-HorizontalAlignment&lt;/span&gt; &lt;span style="color: #8a2be2"&gt;Right&lt;/span&gt; &lt;span style="color: #000080"&gt;-FontStyle&lt;/span&gt; &lt;span style="color: #8a2be2"&gt;Italic&lt;/span&gt; &lt;span style="color: #000080"&gt;-FontSize&lt;/span&gt; &lt;span style="color: #800080"&gt;12&lt;/span&gt; &lt;span style="color: #000080"&gt;-DataBinding&lt;/span&gt; &lt;span style="color: #000000"&gt;@{&lt;/span&gt;            
        &lt;span style="color: #8b0000"&gt;&amp;quot;Text&amp;quot;&lt;/span&gt; &lt;span style="color: #a9a9a9"&gt;=&lt;/span&gt; &lt;span style="color: #8b0000"&gt;&amp;quot;LastProgress.StatusDescription&amp;quot;&lt;/span&gt;            
    &lt;span style="color: #000000"&gt;}&lt;/span&gt;            
    &lt;span style="color: #0000ff"&gt;New-ProgressBar&lt;/span&gt; &lt;span style="color: #000080"&gt;-ColumnSpan&lt;/span&gt; &lt;span style="color: #800080"&gt;2&lt;/span&gt; &lt;span style="color: #000080"&gt;-MinHeight&lt;/span&gt; &lt;span style="color: #800080"&gt;250&lt;/span&gt; &lt;span style="color: #000080"&gt;-Name&lt;/span&gt; &lt;span style="color: #8a2be2"&gt;ProgressPercent&lt;/span&gt; &lt;span style="color: #000080"&gt;-DataBinding&lt;/span&gt; &lt;span style="color: #000000"&gt;@{&lt;/span&gt;            
        &lt;span style="color: #8b0000"&gt;&amp;quot;Value&amp;quot;&lt;/span&gt; &lt;span style="color: #a9a9a9"&gt;=&lt;/span&gt; &lt;span style="color: #8b0000"&gt;&amp;quot;LastProgress.PercentComplete&amp;quot;&lt;/span&gt;            
    &lt;span style="color: #000000"&gt;}&lt;/span&gt;            
&lt;span style="color: #000000"&gt;}&lt;/span&gt; &lt;span style="color: #000080"&gt;-DataContext&lt;/span&gt; &lt;span style="color: #000000"&gt;{&lt;/span&gt;            
    &lt;span style="color: #0000ff"&gt;Get-PowerShellDataSource&lt;/span&gt; &lt;span style="color: #000080"&gt;-Script&lt;/span&gt; &lt;span style="color: #000000"&gt;{&lt;/span&gt;             
        &lt;span style="color: #00008b"&gt;foreach&lt;/span&gt; &lt;span style="color: #000000"&gt;(&lt;/span&gt;&lt;span style="color: #ff4500"&gt;$n&lt;/span&gt; &lt;span style="color: #00008b"&gt;in&lt;/span&gt; &lt;span style="color: #800080"&gt;1&lt;/span&gt;&lt;span style="color: #a9a9a9"&gt;..&lt;/span&gt;&lt;span style="color: #800080"&gt;100&lt;/span&gt;&lt;span style="color: #000000"&gt;)&lt;/span&gt; &lt;span style="color: #000000"&gt;{&lt;/span&gt;            
            &lt;span style="color: #0000ff"&gt;Write-Progress&lt;/span&gt; &lt;span style="color: #8b0000"&gt;&amp;quot;MajorProgress&amp;quot;&lt;/span&gt; &lt;span style="color: #8b0000"&gt;&amp;quot;MinorProgress&amp;quot;&lt;/span&gt; &lt;span style="color: #000080"&gt;-PercentComplete&lt;/span&gt; &lt;span style="color: #ff4500"&gt;$n&lt;/span&gt;            
            &lt;span style="color: #0000ff"&gt;Start-Sleep&lt;/span&gt; &lt;span style="color: #000080"&gt;-Milliseconds&lt;/span&gt; &lt;span style="color: #800080"&gt;250&lt;/span&gt;            
        &lt;span style="color: #000000"&gt;}&lt;/span&gt;            
    &lt;span style="color: #000000"&gt;}&lt;/span&gt;            
&lt;span style="color: #000000"&gt;}&lt;/span&gt; &lt;span style="color: #000080"&gt;-AsJob&lt;/span&gt;            &lt;/pre&gt;

&lt;p&gt;Hope this Helps&lt;/p&gt;

&lt;p&gt;James Brundage [MSFT]&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9941716" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/mediaandmicrocode/archive/tags/WPF/default.aspx">WPF</category><category domain="http://blogs.msdn.com/mediaandmicrocode/archive/tags/PowerShellPack/default.aspx">PowerShellPack</category><category domain="http://blogs.msdn.com/mediaandmicrocode/archive/tags/WPK/default.aspx">WPK</category><category domain="http://blogs.msdn.com/mediaandmicrocode/archive/tags/DataBinding/default.aspx">DataBinding</category></item><item><title>Microcode: A Quick Trick to turn regular XML into Xaml</title><link>http://blogs.msdn.com/mediaandmicrocode/archive/2009/01/22/microcode-a-quick-trick-to-turn-regular-xml-into-xaml.aspx</link><pubDate>Thu, 22 Jan 2009 13:07:36 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9365908</guid><dc:creator>JamesBrundage</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.msdn.com/mediaandmicrocode/comments/9365908.aspx</comments><wfw:commentRss>http://blogs.msdn.com/mediaandmicrocode/commentrss.aspx?PostID=9365908</wfw:commentRss><description>&lt;p&gt;MSDN has tons of examples about XAML.&amp;nbsp; Nearly everything in WPF has an example in XAML, but not all of these XAML examples actually reference the namespace that is required for this Xaml to be loadable by WPF.&amp;nbsp; It's still valid XML, just not valid XAML.&lt;/p&gt; &lt;p&gt;Here's a quick example of what I mean.&amp;nbsp; I just copied and pasted this chunk from the MSDN topic on &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.media.lineargradientbrush.aspx"&gt;LinearGradientBrush&lt;/a&gt;:&lt;/p&gt; &lt;blockquote&gt; &lt;p&gt;&amp;lt;!-- This rectangle is painted with a diagonal linear gradient. --&amp;gt;&lt;br&gt;&amp;lt;Rectangle Width="200" Height="100"&amp;gt;&lt;br&gt;&amp;nbsp; &amp;lt;Rectangle.Fill&amp;gt;&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;LinearGradientBrush StartPoint="0,0" EndPoint="1,1"&amp;gt;&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;GradientStop Color="Yellow" Offset="0.0" /&amp;gt;&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;GradientStop Color="Red" Offset="0.25" /&amp;gt;&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;GradientStop Color="Blue" Offset="0.75" /&amp;gt;&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;GradientStop Color="LimeGreen" Offset="1.0" /&amp;gt;&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/LinearGradientBrush&amp;gt;&lt;br&gt;&amp;nbsp; &amp;lt;/Rectangle.Fill&amp;gt;&lt;br&gt;&amp;lt;/Rectangle&amp;gt;&lt;/p&gt;&lt;/blockquote&gt; &lt;p&gt;Now if I try to simply load that up as XAML, XamlReader barfs&lt;/p&gt; &lt;blockquote&gt; &lt;p&gt;$x&amp;nbsp; =[xml]'&amp;lt;!-- This rectangle is painted with a diagonal linear gradient. --&amp;gt;&lt;br&gt;&amp;lt;Rectangle Width="200" Height="100"&amp;gt;&lt;br&gt;&amp;nbsp; &amp;lt;Rectangle.Fill&amp;gt;&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;LinearGradientBrush StartPoint="0,0" EndPoint="1,1"&amp;gt;&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;GradientStop Color="Yellow" Offset="0.0" /&amp;gt;&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;GradientStop Color="Red" Offset="0.25" /&amp;gt;&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;GradientStop Color="Blue" Offset="0.75" /&amp;gt;&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;GradientStop Color="LimeGreen" Offset="1.0" /&amp;gt;&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/LinearGradientBrush&amp;gt;&lt;br&gt;&amp;nbsp; &amp;lt;/Rectangle.Fill&amp;gt;&lt;br&gt;&amp;lt;/Rectangle&amp;gt;&lt;br&gt;'  &lt;p&gt;[Windows.Markup.XamlReader]::Parse($x.OuterXml)&lt;/p&gt;&lt;/blockquote&gt; &lt;blockquote&gt; &lt;p style="color: red"&gt;Exception calling "Parse" with "1" argument(s): "'' XML namespace prefix does not map to a namespace URI, so cannot resolve property 'Width'. Line '1' Position '79'."&lt;br&gt;At line:14 char:35&lt;br&gt;+ [Windows.Markup.XamlReader]::Parse &amp;lt;&amp;lt;&amp;lt;&amp;lt; ($x.OuterXml)&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; + CategoryInfo&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : NotSpecified: (:) [], MethodInvocationException&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; + FullyQualifiedErrorId : DotNetMethodException&lt;pre&gt;&lt;/pre&gt;&lt;/blockquote&gt;
&lt;p&gt; Obviously, that's not ideal.&amp;nbsp; Luckily, with CTP3, there's a cmdlet called Select-Xml, which will allow me to query a document with xPath, regardless of namespaces.&lt;/p&gt;
&lt;p&gt;This means that I can check to see if the fist element has a reference to the WPF namespace, and add it if it's not there.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;$t = $x |&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Select-Xml //* | &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Select-Object -First 1 | &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Foreach-Object {&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (-not $_.Node.xmlns) {&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; $_.Node.SetAttribute("xmlns", '&lt;a href="http://schemas.microsoft.com/winfx/2006/xaml/presentation')"&gt;http://schemas.microsoft.com/winfx/2006/xaml/presentation')&lt;/a&gt;&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; $_.Node.OuterXml&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt;I'll stop and explain this pipeline a little.&amp;nbsp; $x is the XML, I pipe it into Select-Xml, with the xPath parameter of //*.&amp;nbsp; //* roughly translates to any node.&amp;nbsp; I pick out the first node (with Select-Object -first 1) and then I check to see if the Node contains an xmlns attribute.&amp;nbsp; If it doesn't, I add it.&amp;nbsp; Either way, I emit the first node's OuterXml, which basically means I emit the entire XML chunk as text.&amp;nbsp; That's what $t is when I am done.
&lt;p&gt;Then I use this chunk to display it:
&lt;blockquote&gt;
&lt;p&gt;$w = New-Object Windows.Window&lt;br&gt;$w.Content = [Windows.Markup.XamlReader]::Parse($t)&lt;br&gt;$w.SizeToContent = "WidthAndHeight"&lt;br&gt;$w.ShowDialog()&lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt;Now I have the MSDN sample working, regardless of if it had an xmlns attribute in the first place.&lt;/p&gt;
&lt;p&gt;Hope this Helps,&lt;/p&gt;
&lt;p&gt;James Brundage [MSFT]&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9365908" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/mediaandmicrocode/archive/tags/Microcode/default.aspx">Microcode</category><category domain="http://blogs.msdn.com/mediaandmicrocode/archive/tags/Select-Object/default.aspx">Select-Object</category><category domain="http://blogs.msdn.com/mediaandmicrocode/archive/tags/WPF/default.aspx">WPF</category><category domain="http://blogs.msdn.com/mediaandmicrocode/archive/tags/Select-Xml/default.aspx">Select-Xml</category></item><item><title>Microcode: Scripting Tricks : Exploring WPF Routed Events with PowerShell</title><link>http://blogs.msdn.com/mediaandmicrocode/archive/2008/10/20/microcode-scripting-tricks-exploring-wpf-routed-events-with-powershell-and-get-member-where-object-and-group-object.aspx</link><pubDate>Mon, 20 Oct 2008 03:12:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9006725</guid><dc:creator>JamesBrundage</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.msdn.com/mediaandmicrocode/comments/9006725.aspx</comments><wfw:commentRss>http://blogs.msdn.com/mediaandmicrocode/commentrss.aspx?PostID=9006725</wfw:commentRss><description>&lt;P&gt;Both WPF and PowerShell are both full of great little touches.&amp;nbsp; One of WPF's nice touches is &lt;A href="http://msdn.microsoft.com/en-us/library/ms742806.aspx" mce_href="http://msdn.microsoft.com/en-us/library/ms742806.aspx"&gt;Routed Events&lt;/A&gt;.&amp;nbsp; Routed Events allow you to capture events raised by child controls or parent controls.&amp;nbsp; This can be incredibly useful, because it allows you write less code (which I believe is generally good) by re-using handlers.&lt;/P&gt;
&lt;P&gt;A good example of why you might want to do this is wanting to have more than one button in a user interface that updates a database.&amp;nbsp; What each button might do may be different, but they all to connect to a database.&amp;nbsp; This means you could write either write three longer (and less portable) methods that connect to the database and perform an operation, or three shorter ( and more portable ) methods that just perform the operation on a database and one operation that connects to the database.&amp;nbsp;&amp;nbsp; By having each of the buttons go through a routed event on a container, you can write one short routing handler that connects to the database, looks at where the message came from, and performs the operation.&lt;/P&gt;
&lt;P&gt;WPF comes with an amazing number of controls, and a pretty nice selection of Routed Events.&amp;nbsp; The WPF team was event nice enough to have a manager for these routed events, which means that we can explore them dynamically using PowerShell.&lt;/P&gt;
&lt;P&gt;The event manager is available in the class &lt;A href="http://msdn.microsoft.com/en-us/library/system.windows.eventmanager(VS.85).aspx" mce_href="http://msdn.microsoft.com/en-us/library/system.windows.eventmanager(VS.85).aspx"&gt;System.Windows.EventManager&lt;/A&gt;.&amp;nbsp; Let's start exploring it with PowerShell.&amp;nbsp; To do this, make sure you've loaded the WPF assembly into PowerShell&amp;nbsp; by using the line [Reflection.Assembly]::LoadWithPartialName("PresentationCore"). We can omit the System namespace when referring to a type in PowerShell, so we can call it [Windows.EventManager] from now on.&amp;nbsp; We can use Get-Member -static to see what this class can do.&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;EM&gt;[Windows.EventManager] | Get-Member -static&lt;/EM&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;It has the following methods:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;Equals (every .NET object has this static member) &lt;/LI&gt;
&lt;LI&gt;GetRoutedEvents()&lt;/LI&gt;
&lt;LI&gt;GetRoutedEventsForOwner(Type ownerType)&lt;/LI&gt;
&lt;LI&gt;ReferenceEquals (every .NET object has this static member)&lt;/LI&gt;
&lt;LI&gt;RegisterClassHandler (Type classType, RoutedEvent routedEvent, Delegate handler)&lt;/LI&gt;
&lt;LI&gt;RegisterClassHandler (Type classType, RoutedEvent routedEvent, Delegate handler, Boolean handledEventsToo)&lt;/LI&gt;
&lt;LI&gt;RegisterRoutedEvent(String name, RoutingStrategy routingStrategy, Type handlerType, Type ownerType)&lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;Since I'm just exploring, GetRoutedEvents() is the method I'm interested in.&lt;/P&gt;
&lt;P&gt;I can see every routed event with the simple PowerShell one-liner:&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;EM&gt;[Windows.EventManager]::GetRoutedEvents()&lt;/EM&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Of course we can pipe that to Get-Member in order to see what we've got for every Routed Event:&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;EM&gt;[Windows.EventManager]::GetRoutedEvents() | Get-Member&lt;/EM&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;It's more interesting to me to figure out what events I can bubble up to the parent controls.&amp;nbsp; Since each &lt;A href="http://msdn.microsoft.com/en-us/library/system.windows.routedevent.aspx" mce_href="http://msdn.microsoft.com/en-us/library/system.windows.routedevent.aspx"&gt;RoutedEvent&lt;/A&gt; has a &lt;A href="http://msdn.microsoft.com/en-us/library/system.windows.routedevent.routingstrategy.aspx" mce_href="http://msdn.microsoft.com/en-us/library/system.windows.routedevent.routingstrategy.aspx"&gt;RoutingStrategy&lt;/A&gt; property, I can write this as a simple filter using Where-Object:&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;EM&gt;[Windows.EventManager]::GetRoutedEvents() | Where-Object { $_.RoutingStrategy -eq "Bubble"&lt;/EM&gt;&lt;EM&gt;} | Sort-Object Name&lt;/EM&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Since each RoutedEvent also has a &lt;A href="http://msdn.microsoft.com/en-us/library/system.windows.routedevent.handlertype.aspx" mce_href="http://msdn.microsoft.com/en-us/library/system.windows.routedevent.handlertype.aspx"&gt;HandlerType&lt;/A&gt; property, I can also see what types of different handlers exist by using&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;EM&gt;[Windows.EventManager]::GetRoutedEvents() | Group-Object HandlerType | Sort-Object Count -descending&lt;/EM&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Finally, I can use the EventManager to help guess about what types of controls could fit the bill for whatever I need to do. The next one liner gives me all of the routed events that work with Drag and Drop&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;EM&gt;[Windows.EventManager]::GetRoutedEvents() | Where-Object {$_.Name -like "*Drag*" -or $_.Name -like "*Drop*" }&lt;/EM&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Associating these events with a class needs to use some tricks of reflection.&amp;nbsp; In the sample below, I'll look for all drag and drop handlers within PresentationBase (where the EventManager and some base components live) and PresentationFramework (where most of the built-in WPF controls reside):&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;EM&gt;$handlers = [Windows.EventManager]::GetRoutedEvents() | &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Where-Object { &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; $_.Name -like "*Drag*" -or $_.Name -like "*Drop*" &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; } &lt;BR&gt;$assemblies = [Windows.EventManager].Assembly, &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; [Windows.Window].Assembly &lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;$assemblies | Foreach-Object { &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; $_.GetTypes() | Where-Object { &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; foreach ($handler in $handlers) { &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if ($_.GetEvent($handler.Name)) { &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return $true &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; } &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; } &lt;BR&gt;}&lt;/EM&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;The script above takes a bit of explaining.&lt;/P&gt;
&lt;P&gt;I store the Drag and Drop handlers into a variable, and store the assemblies I wanted to search in another variable (to search all of my currently loaded types for these handlers, I'd use just assign $assemblies to &lt;EM&gt;[AppDomain]::CurrentDomain.GetAssemblies()&lt;/EM&gt;).&amp;nbsp; Then I go through each assembly, retrieve the types, and pipe them into Where-Object, which will determine if they meet my criteria.&amp;nbsp; I go through each class and each handler that met my criteria, and use the &lt;A href="http://msdn.microsoft.com/en-us/library/system.type.getevent(VS.71).aspx" mce_href="http://msdn.microsoft.com/en-us/library/system.type.getevent(VS.71).aspx"&gt;GetEvent&lt;/A&gt; method (which is defined on any .NET type definition) to determine if the event is present.&amp;nbsp; If the event is present, I return $true, which makes the Where-Object output the type.&amp;nbsp; If the event's not present, then code will go onto the next handler and the next type.&lt;/P&gt;
&lt;P&gt;These are just a few examples of the ways you can use PowerShell to explore WPF routed events.&amp;nbsp; The techniques used in this post can be used on to explore just about any .NET type.&amp;nbsp; Exploring .NET through reflection is a great way to save time looking things up, and the pathway to using existing .NET code to solve a problem rather than reinventing the wheel.&lt;/P&gt;
&lt;P&gt;Hope this helps,&lt;/P&gt;
&lt;P&gt;James Brundage [MSFT]&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9006725" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/mediaandmicrocode/archive/tags/PowerShell/default.aspx">PowerShell</category><category domain="http://blogs.msdn.com/mediaandmicrocode/archive/tags/Sort-Object/default.aspx">Sort-Object</category><category domain="http://blogs.msdn.com/mediaandmicrocode/archive/tags/Group-Object/default.aspx">Group-Object</category><category domain="http://blogs.msdn.com/mediaandmicrocode/archive/tags/Scripting+Tricks/default.aspx">Scripting Tricks</category><category domain="http://blogs.msdn.com/mediaandmicrocode/archive/tags/WPF/default.aspx">WPF</category><category domain="http://blogs.msdn.com/mediaandmicrocode/archive/tags/Where-Object/default.aspx">Where-Object</category><category domain="http://blogs.msdn.com/mediaandmicrocode/archive/tags/Get-Member/default.aspx">Get-Member</category><category domain="http://blogs.msdn.com/mediaandmicrocode/archive/tags/.NET/default.aspx">.NET</category></item></channel></rss>