ivan rosa
asked on
PowerShell - WPF progress bar, STAthreading...
Hi Folks, I'm integrating WPF in PS. though when I add a Progress Bar so it starts from 1 - 100 while trying to add the value to gradually fill the bar, it actually waits for the operation to conclude then display the 100% ... so it skips the animation.... According to the research I've done this weekend, it's behaviour is normal as this progressbar needs to run Synchronized with the WPF load..., does anybody body have any experience on how to fix the issue, or STAmultithreading...?
I know in WinForms a simple definition of the values and a performstep() would fix it
here's the code I'm working on it. Thanks for looking I know this is a very specific task...so I made as simple as possible. Thanks for looking in advance
I know in WinForms a simple definition of the values and a performstep() would fix it
here's the code I'm working on it. Thanks for looking I know this is a very specific task...so I made as simple as possible. Thanks for looking in advance
[void][System.Reflection.Assembly]::LoadWithPartialName('presentationframework')
[xml]$XAML = @'
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="247.857" Width="700">
<Grid>
<Grid.Background>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="Black" Offset="0"/>
<GradientStop Color="#FF124F2E" Offset="1"/>
</LinearGradientBrush>
</Grid.Background>
<Label Content="This is just a test" HorizontalAlignment="Left" Margin="265,17,0,0" VerticalAlignment="Top" Foreground="#FF72C196" FontFamily="Global User Interface" FontSize="20"/>
<DataGrid x:Name="mainOuput" HorizontalAlignment="Left" Height="106" Margin="24,56,0,0" VerticalAlignment="Top" Width="640"/>
<Button x:Name="btnSubmit" Content="Submit" HorizontalAlignment="Left" Margin="24,175,0,0" VerticalAlignment="Top" Width="75" BorderBrush="#FF7C5B5B" Foreground="#FF615454" Background="#FFAAAE56"/>
<ProgressBar x:Name="progressBar" HorizontalAlignment="Left" Height="10" Margin="464,175,0,0" VerticalAlignment="Top" Width="100"/>
</Grid>
</Window>
'@
$reader=(New-Object System.Xml.XmlNodeReader $xaml)
$XMLForm=[Windows.Markup.XamlReader]::Load($reader)
$mainOuput = $XMLForm.FindName('mainOuput')
$btnSubmit = $XMLForm.FindName('btnSubmit')
$progressBar = $XMLForm.FindName('progressBar')
$btnSubmit.add_click({
for ($i = 0;$i -le 100; $i++){
$progressBar.Value = $i
sleep -Milliseconds 50
}
})
$XMLForm.ShowDialog() | out-null
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thank you so much!