Tuesday, May 18, 2010

WPK Snippets

Here is another WPK snippet for you. This one will demonstrate how to use New-Slider and New-Ellipse. Assuming that you the PowerPack Modules installed, you should be able to cut and paste the following:
Import-Module WPK           
New-Window -Name "WPK" -Title "WPK Snippets" -Width 250 -Height 175 -Show {
New-Grid -Rows 28,100 -Columns 200* {
New-TextBox -Name txtSliderValue -Column 0 -Row 1
$fill = [System.Windows.Media.Brushes]::Blue
$stroke = [System.Windows.Media.Brushes]::Black
New-Ellipse -Name oEllipse -Column 0 -Row 2 -Height 100 -Width 100 `
-Fill $fill -Stroke $stroke
New-Slider -Name Slider -Column 0 -Row 0 -Minimum 0 -Maximum 200 `
-IsSnapToTickEnabled -On_ValueChanged {
$txtSliderValue = $window | Get-ChildControl txtSliderValue
$slider = $window | Get-ChildControl Slider
$oEllipse = $window | Get-ChildControl oEllipse
$oEllipse.width = $slider.value
}
}
}
You should see something like the following:


Moving the slider triggers the -On_ValueChanged event.
Moving it around you should see the width of the ellipse change accordingly.


Download the script.

Enjoy!

3 comments:

Unknown said...

Not seen that before Josh. What OS and Framework version are you running?

Unknown said...

Do any of the other Modules exhibit similar behavior?

Anonymous said...

Rip Blu-ray for Mac with Blu-ray Ripper for Mac, snow Leopard included.- Free Download and have a try.
Ultimate Blu-ray video converter is actually an 3-in-one software including Blu-ray Ripper, DVD Ripper and Video Converter.
Blu-ray ripper enables you directly rip and convert your Blu-ray movies and general DVDs, even the protected DVDs and Blu-ray DVDs into other popular audio and video formats.