views:

457

answers:

3

We can use [Windows.Markup.XamlReader]::Load to load XAML file in PowerShell, but is there some way to specify some PowerShell script as code behind?

A: 

While I don't know for sure, I would guess not. Given that Visual Studio only exposes C# and VB as languages to use to build WPF applications, that implies that work needs to be done at the tool level in order to add support for WPF to a language. Since a .NET language doesn't get WPF support "for free", it's doubtful that PowerShell has the ability to be the code behind for a WPF UI.

Andy
This is inaccurate. .NET languages largely do get WPF support "for free" (they are almost all able to access the types). Some .NET languages have threading issues that make working with WPF troublesome, and just having access to the .NET types does not guarantee that the types will be useful to people in the language without extra work. In PowerShell's case, you can easily access WPF for free, but you cannot use WPF in a cmdlet-like way without WPK.Hope this helps
Start-Automating
+7  A: 

PowerShell can be used to provide functionality in a WPF application. Check out these great blog posts regarding using PowerShell and WPF...

HuddledMasses.Org - PowerBoots - a WPF GUI Toolkit for PowerShell

PowerBoots - Shoes for PowerShell

PowerBoots - Loading XAML Windows in PowerShell 1.0 or 2.0

Windows PowerShell Team Blog

http://blogs.msdn.com/powershell/archive/2008/05/25/powershell-and-wpf-wtf.aspx

WPF & PowerShell – Part 1 ( Hello World & Welcome to the Week of WPF )

WPF & PowerShell – Part 2 (Exploring WPF (and the rest of .NET) with Scripts)

WPF & PowerShell -- Part 3 (Handling Events)

WPF & PowerShell -- Part 4 (XAML & Show-Control)

WPF & PowerShell - Part 5 ( Using WPF & PowerShell Modules)

WPF & PowerShell - Part 6 (Running Functions in the Background)

WPF & PowerShell - Part 7 (Sharing Hosts)

Steven Murawski
No problem. Joel "Jaykul" Bennet and James Brundage have both done a lot of work with WPF and PowerShell. Great stuff.
Steven Murawski
The next release (you can check it out in source control on codeplex) of PowerBoots includes a .Net4 extension to allow powershell-script embedding in event handlers in xaml
Jaykul
+1  A: 

Now there is also WPK, in the PowerShellPack which makes creating WPF UI in PowerShell extremely straightforward and fun.

Joey