Update Label Content

Feb 11, 2012 at 3:42 PM

Hi all,

I've not added any sort of GUI to my PowerShell scripts before, so please excuse my lack of knowledge!

I'd like to create a very simple window which shows the value of a variable in large text, and have this window update every fifteen seconds. I can generate the window, I can update the variable, but I can't work out how to update the content of the window.

I found this (http://showui.codeplex.com/workitem/2105) but it doesn't actually present a solution. Can anyone suggest how I can get this working?

Many thanks,

Gavin

Coordinator
Feb 12, 2012 at 9:29 PM
Edited Feb 12, 2012 at 9:29 PM

That work item came from this discussion: http://showui.codeplex.com/discussions/265736 where I explained how to do it and found (and fixed) a bug.  If that's not enough, please feel free to ask more questions :-)

Feb 12, 2012 at 9:34 PM

Thanks for your response. I saw that, but when I tried executing your code (exactly as is), I get an error:

PS C:\Users\Gavin> Import-Module ShowUI
PS C:\Users\Gavin> $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  
>> 
PS C:\Users\Gavin> $job | Update-WPFJob { $firstname.Text = "Russell" }
Exception calling "InvokeScriptInJob" with "3" argument(s): "You cannot call a method on a null-valued expression."
At C:\Users\Gavin\Documents\WindowsPowerShell\Modules\ShowUI\Update-WPFJob.ps1:54 char:43
+                     $job.InvokeScriptInJob <<<< ($realCommand, $null, $Asynchronously)
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : DotNetMethodTargetInvocation
 

Any ideas?

Thanks,

Gavin

Jul 19, 2012 at 2:31 AM

I'm running ShowUI 1.3 and having the same problem as GavMJM.  I copied the example exactly and when run I get the same exception. 

Gavin - did you ever figure out what the problem was?

Jul 19, 2012 at 2:53 AM

I found that this: will work:

$job | Update-WPFJob {  $Window.Content.Children | Where {$_.Name -eq "Firstname"} | % { $_.Text = "Russell" } }

I hope that helps someone and I am still interested in other solutions if they are found.

Dec 23, 2013 at 4:47 AM
matthewwi wrote:
I found that this: will work: $job | Update-WPFJob { $Window.Content.Children | Where {$_.Name -eq "Firstname"} | % { $_.Text = "Russell" } } I hope that helps someone and I am still interested in other solutions if they are found.
And I'm getting following error:
PS C:\Users\farrukh\Documents> $job | Update-WPFJob { $Window.Content.Children | Where {$_.Name -eq "Firstname"} | % { $_.Text = "Russell" } }
InvokeScriptInJob : Cannot find an overload for "InvokeScriptInJob" and the argument count: "3".

At C:\Users\fwaheed\Documents\WindowsPowerShell\Modules\showui\Update-WPFJob.ps1:54 char:43
  • $job.InvokeScriptInJob <<<< ($realCommand, $null, $Asynchronously)
    • CategoryInfo : NotSpecified: (:) [], MethodException
    • FullyQualifiedErrorId : MethodCountCouldNotFindBest
Dec 23, 2013 at 7:23 PM
Which version of .NET, ShowUI, and PowerShell are you using? I just tried this on PowerShell 3.0, running CLR version 4.0.30319.18408, and ShowUI 1.3 without any problems.
Dec 24, 2013 at 3:52 AM
matthewwi wrote:
Which version of .NET, ShowUI, and PowerShell are you using? I just tried this on PowerShell 3.0, running CLR version 4.0.30319.18408, and ShowUI 1.3 without any problems.
Powershell: 3.0
.Net FW: 4.5.

From ShowUI.psd1:
ModuleVersion = '1.4'
Author='Joel Bennett, James Brundage, & Doug Finke'
Copyright='Start-Automating 2011'    
Description='Show-UI is a module to help you write user interfaces to interact with PowerShell'
Guid='ff975fb0-3731-4312-b32d-830fd3185193'
ModuleToProcess='ShowUI.psm1'
FormatsToProcess='ShowUI.Formats.ps1xml'    
ScriptsToProcess='Get-ReferencedCommand.ps1','Get-UiCommand.ps1'


Dec 24, 2013 at 3:54 AM
BTW, I've also installed PowerShellPack.. is there any possibility that it can conflict at any point?
Dec 24, 2013 at 4:16 AM
Edited Dec 24, 2013 at 4:18 AM
Ahhh... Just found the problem... Module WPK, coming with PowerShellPack, also got Update-WPFJob.ps1. So if imported both, this would conflict. i.e:

C:\Users\farrukhw\Documents\WindowsPowerShell\Modules\ShowUI\Update-WPFJob.ps1
and
C:\Users\farrukhw\Documents\WindowsPowerShell\Modules\WPK\Update-WPFJob.ps1

I tested while importing only ShowUI module, while removing WPK and it started working as expected....

Thanks
Coordinator
Dec 27, 2013 at 5:37 AM
Yeah, you'll want to get rid of the WPK module, it's one of the two modules we combined to build ShowUI, so there will be a lot of conflicting commands: You can either take it out of the PowerShell Pack, or you can make sure you explicitly import ShowUI *after* you import PowerShell Pack.