koryo Posted May 2, 2011 Posted May 2, 2011 (edited) 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 Edited May 2, 2011 by koryo
jamesb Posted May 3, 2011 Posted May 3, 2011 Can't you use Canvas.Children.Add(whatever_control)? 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.
koryo Posted May 3, 2011 Author Posted May 3, 2011 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.
Arthur Posted May 3, 2011 Posted May 3, 2011 Does anyone have a better method to dynamically add / remove UI elements with this? PowerBoots?
koryo Posted May 3, 2011 Author Posted May 3, 2011 PowerBoots? 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.
jamesb Posted May 4, 2011 Posted May 4, 2011 If it's saying it can't convert, you'll probably need to strongly cast the object you're adding. [TextBox]$textbox = and so forth.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now