Local function variables not visible in eventlisteners

Feb 27, 2014 at 4:42 PM
Edited Feb 27, 2014 at 4: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)
        } -On_Loaded{
            $z = 1
    }  -On_Loaded{
            $z = 1
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 ?