+ Post New Thread
Results 1 to 6 of 6
Scripts Thread, Powershell WPF GUI modification in Coding and Web Development; Hi all I have been playing around with Powershell and the .net framework Windows Presentation Foundation (WPF). Using powershell, i ...
  1. #1

    Join Date
    May 2010
    Location
    England
    Posts
    118
    Thank Post
    21
    Thanked 20 Times in 17 Posts
    Rep Power
    13

    Powershell WPF GUI modification

    Hi all

    I have been playing around with Powershell and the .net framework Windows Presentation Foundation (WPF). Using powershell, i can insert XAML code inside an object and execute this from within Powershell showing a GUI for users to interact with.

    This is all working very well, and im having lost of fun playing with this (as shown by posting from home on a bank holiday monday lol), The only problem im having is when i try and edit the design of the form after the form has been generated.

    I can change basic elements in the form (Height, Width e.c.t) by changing the desired variable and entering a new value, then passing the processing thread to the WPF generated window with a "regenerate" command. However i can not figure out how i can add extra generated content (i.e. extra text box or checkboxes) with this method, as there doesn't seem to be a method to add children / content to the canvas?

    The only way i have found to get around this so far is to have my powershell code include a button on click even that closes the current open form, re-generates the XAML code for the window, and then show the form dialog again. This however only seems to work once, and im not sure how this would effect other options within the program.

    Does anyone have a better method to dynamically add / remove UI elements with this?

    Thanks
    Last edited by koryo; 2nd May 2011 at 10:27 PM.

  2. #2


    Join Date
    Mar 2008
    Location
    Surrey
    Posts
    2,317
    Thank Post
    131
    Thanked 355 Times in 293 Posts
    Blog Entries
    4
    Rep Power
    142
    Can't you use Canvas.Children.Add(whatever_control)?

    Code:
    myCanvas.Children.Add(textBox)
    myCanvas.SetLeft(textBox, xCoord)
    myCanvas.SetTop(textBox, yCoord)
    This is how I'd approach the same thing in C# at least.

  3. #3

    Join Date
    May 2010
    Location
    England
    Posts
    118
    Thank Post
    21
    Thanked 20 Times in 17 Posts
    Rep Power
    13
    Hi jamesb, thanks for your responce.

    In responce to your help, i had a quick look at my form to try this. According to powershell there is no "add" method on the canvas children object. However i gave it a go anyway, and got a responce saying that powershell can not convert a string to the .net object that appears to be required. Looks like more fiddle pokery is required here...

    thanks for the heads up on that hidden little method though.

  4. #4


    Join Date
    Feb 2007
    Location
    51.403651, -0.515458
    Posts
    9,808
    Thank Post
    262
    Thanked 2,969 Times in 2,183 Posts
    Rep Power
    847
    Quote Originally Posted by koryo View Post
    Does anyone have a better method to dynamically add / remove UI elements with this?
    PowerBoots?

  5. #5

    Join Date
    May 2010
    Location
    England
    Posts
    118
    Thank Post
    21
    Thanked 20 Times in 17 Posts
    Rep Power
    13
    Quote Originally Posted by Arthur View Post
    Hi Arthur

    Powerboots does sound very interesting, and somthing i will probably get into very soon. I was trying not to get into too many external modules for the time being as it would be nice to have cross-system code without having to distribute another module along side it.

  6. #6


    Join Date
    Mar 2008
    Location
    Surrey
    Posts
    2,317
    Thank Post
    131
    Thanked 355 Times in 293 Posts
    Blog Entries
    4
    Rep Power
    142
    If it's saying it can't convert, you'll probably need to strongly cast the object you're adding.

    Code:
    [TextBox]$textbox =
    and so forth.



SHARE:
+ Post New Thread

Similar Threads

  1. bash to GUI
    By RabbieBurns in forum *nix
    Replies: 17
    Last Post: 27th May 2010, 11:32 AM
  2. Replies: 2
    Last Post: 24th September 2007, 03:49 PM
  3. Replies: 6
    Last Post: 17th January 2006, 06:13 PM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •