Question ProgressBar et WFP

Plus d'informations
il y a 3 ans 8 mois #29929 par Mokla
ProgressBar et WFP a été créé par Mokla
Bonjour à tous,
J'essaye de faire une application avec une ProgressBar ou ProgressRing ou quand j'appuie sur un bouton il se passe qq chose et cela m'affiche la ProgressBar ou ProgressRing tant que ce que je dois faire n'est pas fini.

Le problème que j'ai est le suivant :
- Quand je clique sur le bouton il fait ce qu'il doit faire mais n'affiche pas la barre de progression ou la ProgressRing. La ProgressBar s'affiche à la fin et c'est tout.

Je vous joins un petit programme de test mais qui est similaire à mon programme principal que je veux faire :
$ScriptDir = Split-Path $script:MyInvocation.MyCommand.Path
[System.Reflection.Assembly]::LoadWithPartialName('System.Windows.Forms')  				| out-null
[System.Reflection.Assembly]::LoadWithPartialName('presentationframework') 				| out-null
[System.Reflection.Assembly]::LoadFrom("$ScriptDir\assembly\MahApps.Metro.dll") | out-null
[System.Reflection.Assembly]::LoadFrom("$ScriptDir\assembly\MahApps.Metro.IconPacks.dll") | out-null

[xml]$xaml = @"
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"		
xmlns:Controls="clr-namespace:MahApps.Metro.Controls;assembly=MahApps.Metro"
xmlns:iconPacks="http://metro.mahapps.com/winfx/xaml/iconpacks" 
MaxHeight="100" MinHeight="100" Height="167" 
MaxWidth="320" MinWidth="320" Width="320" 
WindowStyle="ToolWindow">
    <Canvas Grid.Row="1" HorizontalAlignment="Left" Width="312" Height="70" VerticalAlignment="Top">
        <TextBlock Name="ProgressText" Canvas.Top="10" Canvas.Left="20">Hello world</TextBlock>
        <ProgressBar Name="Progbar" Canvas.Top="40" Canvas.Left="10" Width="260" Height="20" HorizontalAlignment="Center" Value="20" />
        <Button Content="feu" Name="bouton" Height="25" Canvas.Left="152" Canvas.Top="10" Width="118"/>
        <!-- <Controls:ProgressRing/> -->
        <Controls:ProgressRing Foreground="Red" Name = "Progring" />
    </Canvas>
</Window>
"@

function Affichage
{
PAram ( $ValueAffiche )
        $progBar.Value = $ValueAffiche
        $progBar.ValueChanged
        $progBar.IsEnabledChanged
}

function test
{
Param ( [boolean]$ValueAffich )
        $Progring.IsActive = $ValueAffich
}

$reader = New-Object System.Xml.XmlNodeReader $xaml
$dialog = [Windows.Markup.XamlReader]::Load($reader)
# Les variables d’objets graphiques
$Xaml.SelectNodes("//*[@Name]") | ForEach-Object { Set-Variable -Name "$($_.Name)" -Value $dialog.FindName($_.Name) }
# get an handle for the progress bar
#$progBar = $dialog.FindName("ProgressComplete")
$Progring.IsActive = $false

$bouton.Add_Click(
{
#    $Value = 0;
#    affichage $value
    test $true
    do
    {
        affichage $Value
        if($Value -eq 100)
        {
            #$dialog.close()
            #this.Close();
            $progBar.Name = "fini"
        }
        $Value += 0.25
        Write-Host ("value : $progBar.value")
        Start-Sleep -Seconds 0.2
    }
    While ($Value -ne 100)
test $false
})
$dialog.ShowDialog() | out-null

Merci pour votre aide

Connexion ou Créer un compte pour participer à la conversation.

Temps de génération de la page : 0.062 secondes
Propulsé par Kunena