Update variable from button click

Apr 16, 2014 at 10:04 PM
Edited Apr 16, 2014 at 10:22 PM
I just started messing around with ShowUI ( which is pretty cool btw ), so sorry if this is a nub question.

How can i update a variable from a button? -On_Click { $KeepLooping= $false } Doesnt seem to work

Below is just a hack i wrote now and is not tested.
$global:KeepLooping = $true
Import-Module ShowUI

while ($true -eq $KeepLooping)
        StackPanel -ControlName 'Exit Loop Test' {
            UniformGrid -Margin 5 -Columns 1 -Rows 2  {
             Label -Name msg1 -Margin 2 "Exit Loop?"

        Grid -Margin 5 -columns 2 {
            Button -Name NoExit -Content "NO " -Margin 2 -column 2  -HorizontalAlignment Left -On_Click { $window.Close()}            
            Button -Name YesExit -Content "YES" -Margin 2 -column 2  -HorizontalAlignment Right -On_Click {$window.Close();$KeepLooping= $false }
        } -show
May 2, 2014 at 11:47 PM
You're updating variables in the scope of the event handler.
You just need to use $global:KeepLooping=$false

Although I have to add: I don't think you really want to create and tear down the UI inside the loop ;)