header1   header
header
header Register : : Login header
header
connector   connector
menuleft menuright
submenu   submenu
left
How do I Combine the 2 WFP Approaches
Last Post 02 Apr 2009 12:41 PM by PowerShell Jedi. 2 Replies.
Printer Friendly
  •  
  •  
  •  
  •  
  •  
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages
PowerShell JediUser is Offline
Basic Member
Basic Member
Posts:410
Avatar

--
02 Apr 2009 02:44 AM
    OK, so I'd Like to use a Runspace for my WPF Like so....

    # ------------------------------------------
    # Create a runspace to run Hello World
    $rs = [RunspaceFactory]::CreateRunspace()
    $rs.ApartmentState, $rs.ThreadOptions = “STA”, “ReuseThread”
    $rs.Open()
    $psCmd = {Add-Type -AssemblyName PresentationCore,PresentationFramework,WindowsBase}.GetPowerShell()
    $psCmd.Runspace = $rs
    $psCmd.Invoke()
    $psCmd.Commands.Clear()
    $psCmd.AddScript({
    $window = New-Object Windows.Window
    $window.Title = “Hello World."
    $window.Content = "PoSH is Cooool!”
    $window.FontSize = '48'
    $window.SizeToContent = “WidthAndHeight”
    $window.add_MouseDoubleClick({$this.Close()})
    $null = $window.ShowDialog()
    }).BeginInvoke()
    # ------------------------------------------

    But I also want write my UI with Proper XAML Like this aproach...

    # ------------------------------------------
    Add-Type -AssemblyName presentationframework
    Add-Type –assemblyName PresentationCore
    Add-Type –assemblyName WindowsBase


    [xml]$xaml = @'
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="This is a test" Height="300" Width="300">






    '@


    $reader=(New-Object Xml.XmlNodeReader $xaml)
    $Form=[Windows.Markup.XamlReader]::Load( $reader )
    $Form.ShowDialog() | out-null
    # ------------------------------------------

    So I guess my Question is how do I combine the 2 approaches. My reason for wanting to use the XAML approach is that's how Visual Studio 2008 Writes it and I feel you have more control over the UI that way.

    As always I'm open to your comments Criticisms, am I taking the correct approach etc..
    PoSH is a Automation Technology surfaced as a scripting language, not a "spice" ;-)
    Marco Shaw (MVP)User is Offline
    Veteran Member
    Veteran Member
    Posts:1647
    Avatar

    --
    02 Apr 2009 11:26 AM
    Are you getting my direct emails to you?

    I think Doug's post here provides the framework for this:
    http://dougfinke.com/blog/index.php...nt-page-1/
    Marco

    *Microsoft MVP - Windows PowerShell
    https://mvp.support.microsoft.com/profile/Marco.Shaw
    *Co-Author - Sams Windows PowerShell Unleashed 2nd Edition
    *Blog - http://marcoshaw.blogspot.com
    PowerShell JediUser is Offline
    Basic Member
    Basic Member
    Posts:410
    Avatar

    --
    02 Apr 2009 12:41 PM
    AHHHH! I figured out my Problems!!!


    XAML is Case Sensitive!!
    Powershell isn't!!

    When working with XAML you have to be aware of cAse!!

    I hate problems like that!!!!!

    PoSH is a Automation Technology surfaced as a scripting language, not a "spice" ;-)
    You are not authorized to post a reply.


    Active Forums 4.3
    right
    footer   footer
    footer Sponsored by Quest Software • SAPIEN Technologies • Compellent • Microsoft Windows Server 2008 R2 footer
    footer   footer