Animated GIF

Jul 11, 2014 at 11:41 PM
Does anyone know if it is possible to display an animated gif or png file in a new-stackpanel or a new-grid?

I found the new-image commandlet, and I can load the image but it does not animate.

Any help would be appreciated.
Coordinator
Jul 13, 2014 at 6:12 AM
The simplest thing, honestly, is to use the browser control
New-WebBrowser -Source http://stream1.gifsoup.com/view1/1450456/goalie-save-o.gif
E.g.:
stackpanel {
TextBox -Name Source http://stream1.gifsoup.com/view1/1450456/goalie-save-o.gif
button "Load" -On_Click { $Browser.Source = $Source.Text }
webbrowser -Name Browser
} -Width 300 -Height 300 -show
The alternative is to read the frames from the gif and create a frameAnimation yourself (or grab some code from someone who already did that, like https://wpfanimatedgif.codeplex.com/)

See here, in C# for a "simple" example of the code required: http://stackoverflow.com/questions/210922/how-do-i-get-an-animated-gif-to-work-in-wpf
Jul 17, 2014 at 12:33 AM
Hi Jaykul,

Thanks for your response!
I will give it a shot...
Aug 29, 2014 at 10:47 PM
Edited Aug 29, 2014 at 10:48 PM
Jaykul,

The loading a gif in the browser didn't work like i expected. I am trying to popup a window with some sort of an activity indicator while a process is running.
New-ProgressBar seems too tricky to use.

I did manage to take a couple of the RenderTransform examples together, but I can't seem to get the animation to occur within a stackpanel or a uniform grid. The animation always shows up in its own independent window, followed by a new window with the grid.
New-UniformGrid -Width 200 -Height 200 {
new-rectangle -width 10 -height 50 -fill red -show -RenderTransform {
    New-RotateTransform -CenterX 5 -CenterY 100 } -On_Loaded {
    $da = New-DoubleAnimation -From 0 -To 360 -Duration ([Timespan]::FromMilliseconds(350)) -RepeatBehavior Forever;
     start-animation -InputObject $this.RenderTransform -Property Angle -animation $da
     }
     New-Rectangle 'Yellow'
     New-Rectangle 'Green'
     New-Rectangle 'Red'
 } -show
Coordinator
Aug 29, 2014 at 11:39 PM
Edited Aug 29, 2014 at 11:39 PM
I think what you want is: New-ProgressBar -IsIndeterminate
StackPanel -Name Panel -Margin 2 {
   Label "Full Name:"
   # The On_TextChanged thing is just to enable the submit button after the user's typed at least two things with a space...
   TextBox -name "Name" -Height 24 -On_TextChanged { $submit.IsEnabled = $this.Text.split(" ").Length -ge 2 }

   # IsDefault so they can click with ENTER
   # IsEnabled:$false so it starts disabled
   Button "Click Me" -Name submit -IsEnabled:$false -IsDefault -On_Click {
      # You could just use Add-ChildControl, but I want it at the top:
      $This.Parent.Children.Insert(0, (New-ProgressBar -IsIndeterminate -Height 16) )

      # Let's simulate some work by waiting a couple seconds:
      Register-PowerShellCommand -In "0:0:2" -Run -Once {
         # And then stop looking like we're working
         $window.Content.Children.RemoveAt(0)
      }                                                      
   }
} -On_Loaded { $name.Focus() } -Show
Aug 31, 2014 at 2:05 AM
Thanks! That is what I needed -- a progress bar that keeps going until the window is closed:
$MyProcess = start-process notepad.exe -Passthru
new-stackpanel -height 100 -width 100 { 
      new-label "Hello" ; New-ProgressBar -IsIndeterminate -Height 16; 
      new-button "Finish" -Width 100 -VerticalAlignment Bottom -HorizontalAlignment Right -On_Click {
      (get-process -ID $MyProcess.Id).CloseMainWindow();
Get-ParentControl |Set-UIValue -passThru | close-control }} -show