Author Posts

September 6, 2018 at 8:40 pm

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", "");
	$xamlReader = New-Object System.Xml.XmlNodeReader $xaml

$ScriptBlock = {
	sleep 10

$window = Load-Xaml
#$window.Add_Closing( { $_.Cancel = $true; } ) 

$Worker = Start-Job -scriptblock $ScriptBlock

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" )


Here is my XALM code, which again is very basic


September 7, 2018 at 7:03 pm

Your XAML code is not visible, post it via gist and add gist the link to the post.

September 10, 2018 at 3:09 pm

I've removed the leading "< " so I can post this correctly. Please assume those are there.

Title="ProgressBar" Height="100" Width="300" ResizeMode="NoResize" HorizontalAlignment="Center" VerticalAlignment="Center" WindowStartupLocation="CenterScreen" Topmost="True" WindowStyle="ToolWindow" ScrollViewer.VerticalScrollBarVisibility="Disabled" IsHitTestVisible="False">

Grid Margin="20">
ProgressBar Name="pbStatus" IsIndeterminate="True" />