Hi everyone,
I’ve been Googling a lot and ain’t able to make this work.
Essentially, I’m designing a WPF form with a progress bar while I run som lenghty stuff behind.
While this may seem rather easy and basic, I am no coder just a very resourceful guy.
My problem is when I use $window.ShowDialog(), the animation works perfectly but of course doesn’t run anything because it’s a modal form. Of course I went with $window.Show() which does bring up the WPF form and runs my stuff but the progressbar animation ain’t working. I tried with “runspace” and my latest test is with “start-job”.
As you will see, I’m not doing much in my code, it’s a “proof of concept”. I will be adding this to a way bigger PS1 file once it’ll be working.
Thanks for any help you can give me.
Here is my code for the PS1 file.
Add-Type -AssemblyName PresentationFramework
function Load-Xaml {
[xml]$xaml = Get-Content -Path $PSScriptRoot\ProgressBar1.xaml
$manager = New-Object System.Xml.XmlNamespaceManager -ArgumentList $xaml.NameTable
$manager.AddNamespace("x", "http://schemas.microsoft.com/winfx/2006/xaml");
$xamlReader = New-Object System.Xml.XmlNodeReader $xaml
[Windows.Markup.XamlReader]::Load($xamlReader)
}
$ScriptBlock = {
sleep 10
}
$window = Load-Xaml
#$window.Add_Closing( { $_.Cancel = $true; } )
$window.Topmost=$true
$Worker = Start-Job -scriptblock $ScriptBlock
$window.Show()
Do {
#I added these lines to be sure something is actually going on
Write-Host "." -NoNewline
Start-Sleep -Seconds 1
} While ( $Worker.state -notlike "Completed" )
$window.Close()
Here is my XALM code, which again is very basic