Best way to disable a button based on Variable

Jan 4, 2012 at 6:20 PM

In a nutshell I'm tinkering with ShowUI to provide a nicer interface for a backup automation script we use at work. When run on Windows XP only 1 button should be clickable, "Backup". The restore button should be disabled or alternately not visible. When run on Windows 7, the UI should show both a "Backup" and a "Restore" button. I've been trying to use -On_Initialized and $this.IsEnabled but it doesn't appear to be cutting it. A nudge in the right direction would be helpful.

I would expect the code below to show a window with no button in it on Windows 7 (I'm testing on Win7 so my return values are reversed), however when I run the script the button is visible. 

 

function Get-OSVersion
{
    $computer = gwmi -Class Win32_OperatingSystem -Computername "."
    $pieces   = $computer.Version.Split(".")
    
    switch -wildcard ($computer.Version)
    {
        "6*" { return $false; }
        "5*" { return $true; }
    }
}

New-Window {
	StackPanel {
		New-Label "Foo"
		New-Button "Hey" -On_Initialized { $this.IsVisible = $false } -On_Click { Close-Control }
	}
} -Show