Product: PowerShell Universal
Version: 5.5.4
Hello,
I’m having an issue were I can’t seem to access custom classes / types from certain events. One that I’m able to consistantly replace is a simple -OnClick. Below is an example using a static member, but this is an issue with instance members as well.
New-UDGrid -Container -Content {
New-UDButton -id 'btn_TestButton' -Text "$([Example]::staticString)" -OnClick {
Show-UDToast -Message "$([Example]::staticString)"
}
}
class Example{
static [string] $staticString = "I'm a button!"
}
The result is that I see a button with the text “I’m a button!” on the screen, meaning that it can correctly refrence the class, but when it’s clicked I get the following error:
Unable to find type [Example]
However, if I make a function that references the class, it DOES work. This sets the text of the button to “I’m a button!” and displays that same piece of text on the -OnClick event.
New-UDGrid -Container -Content {
New-UDButton -id 'btn_TestButton' -Text "$([Example]::staticString)" -OnClick {
Show-UDToast -Message "$(Get-ExampleStaticString)"
}
}
function Get-ExampleStaticString {
return "$([Example]::staticString)"
}
class Example{
static [string] $staticString = "I'm a button!"
}
Anyone have any thoughts or workarounds besides calling object members from a separate function? This works okay for this example, but with instance members, the object has to be stored in a global variable and it doesn’t really make any sense to have to use a separate function to manipulate the object.