Local function variables not visible in eventlisteners

Feb 27, 2014 at 3:42 PM
Edited Feb 27, 2014 at 3:44 PM
Import-Module ShowUi
function showGui(){
   $z = 1
    StackPanel -ControlName "Prompt"  -Name "prompt" -Orientation Vertical -HorizontalAlignment Left  {
              Button "Create" -IsDefault -Width 100 -Margin "8,8,8,8" -On_Click { 
                  Write-Host ("z=" + $z)
                  Close-Control
        } -On_Loaded{
            $z = 1
        }
    }  -On_Loaded{
            $z = 1
        }-Show
}
showGui
If a function variable is used within a showui element it seems not to be accessible.
As shown i also tried to define it in the on_loaded events of the button and the panel.

Is there a way to use a local variable in show ui elements without having to define it globaly ?