Change Control Contents from PowerShell

Jul 19, 2011 at 2:39 PM

Good afternoon,

I am interested to know if it is possible to create a new window using ShowUI and put it in the background using AsJob and then change the content of the controls within that window from the script that generated it.

I have had a look around and cannot work out one way or other.  If someone knows if this is possible or not please could you let me know?

Thanks, Russell

Coordinator
Jul 19, 2011 at 5:20 PM

That's what Update-WPFJob is for :)

Jul 26, 2011 at 6:55 PM

Did you get the Update-WPFJob to work for this?  Incidentally, I needed this functionality, and when I try to use Update-WPFJob, it complains because I am trying to use variables that aren't in scope.

Kyjan

Aug 2, 2011 at 12:41 PM

Hello,

Jaykul, thanks for this, I did not realise there was that function.

Kyjan, I have got somethings working but not 100% the way I want it to.

I would like to have a ShowUI window with various elements on it, e.g text boxes, stack panels etc.  The problem I have with the Update-WPFJob now is that I do not know how to get to the elements that I have described.

So for example if I create a simple label and change the $window.Content that I can change it quite easily, but I do not know how to target individual labels or textboxes for example when I have a Uniform Grid or similar.

How can I accomplish this?  I thought that I would be able to use the following:

$job = New-StackPanel -ControlName 'Get-PersonalInformation' -Columns 1 -Children {            
    New-Label "What is your first name?"            
    New-TextBox -Name Firstname
    New-Label "What is your last name?"            
    New-TextBox -Name Lastname            
    New-Label "When were you born?"            
    Select-Date -Name Birthdate                    
} -asjob  

And then I would be able to update it with something like:

$job | Update-WPFJob { $firstname.Content = "Russell" }

However this does not work and I get an error. I know how I can change the window contents using $window.Content but this does not work.

Any help greatly received.

Thanks in advance,

Russell

Coordinator
Aug 4, 2011 at 5:38 AM
Edited Aug 4, 2011 at 4:11 PM

In ShowUI 1.1, we didn't apply the magic variable-name creation when you called Update-WPFJob ...

I've fixed that in ShowUI 1.2, so your script will run as-is, except that TextBox controls don't have "Content" so you need $firstName.Text = "Russell"

I'll paste the edited version here, just because I keep wanting to copy-paste it:

$job = New-StackPanel -ControlName 'Get-PersonalInformation' -Columns 1 -Children {            
    New-Label "What is your first name?"            
    New-TextBox -Name Firstname
    New-Label "What is your last name?"            
    New-TextBox -Name Lastname            
    New-Label "When were you born?"            
    Select-Date -Name Birthdate                    
} -asjob  

# As of 1.2 you should be able to update it with something like:
$job | Update-WPFJob { $firstname.Text = "Russell" }

Coordinator
Aug 4, 2011 at 6:27 AM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.