|
A blank box!? I tested that script on two systems, and on ShowUI 1.3 (and 1.4 which I see now was not properly released, bah James!) just to be sure.
In this script, I want to only create a new FolderBrowserDialog if I haven't already done so (that is, if you click the button twice I want to reuse the dialog from before, instead of creating a new one). So I need to store the dialog in
a variable where I can be sure it will survive when the event handler script exists.
The $this variable is a magic variable in ShowUI's event handlers, it refers to the element that triggered the event (in this case, the button). I know it's always going to be set to the button when this event handler runs.
Every WPF element object has a .Tag property. It's null by default, but you can put anything in it. We use it for the UIValue stuff, as a matter of fact, so you should be careful about where you're setting it (in this case, I set it on a Button,
which doesn't have a value, so I know setting the .Tag isn't going to screw up Get-UIValue later).
So basically:
# If the button's tag property is not set
if(!$this.Tag) {
# Then set the tag to hold our new FolderBrowserDialog
$this.Tag = new-object Windows.Forms.FolderBrowserDialog
}
From then on we just use $this.Tag when we want to use the dialog.
|