Partage
  • Partager sur Facebook
  • Partager sur Twitter

ProgressBar Timer en xaml intégré powershell

    16 juin 2021 à 13:48:25

    Bonjour, 

    Je suis débutant et j'ai créé une interface GUI en XAML que j'exécute avec un code powershelll (pour affichage dans une séquence de tache Configuration Manager).

    J'aimerai afficher un timer de 5 minutes qui s'écoule et une fois écoulé, je souhaiterais que la fenetre se ferme automatique tout en envoyant une variable dans ma séquence de tache

    Je souhaiterai également afficher le temps restant en temps réel dans la fenêtre.

    Voici mon code (assez basique pour le moment)

    #Your XAML goes here 
    $inputXML = @"
    <Window x:Name="MainWindow2" x:Class="WpfApp2.MainWindow"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
            xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
            xmlns:local="clr-namespace:WpfApp2"
            mc:Ignorable="d"
            Title="MainWindow" Height="700" Width="800" WindowStyle="None" ResizeMode="NoResize" WindowStartupLocation="CenterScreen">
        <Grid Background="#FFB9AFAF">
          <TextBlock x:Name="timerinfo" TextAlignment="Center" FontFamily="Calibri" FontSize="14" HorizontalAlignment="Center" TextWrapping="Wrap" VerticalAlignment="Top" Height="22" Width="632" Margin="0,598,0,0"><Run Text="Close window in :"/></TextBlock>
            
            <ProgressBar x:Name="timerbar" HorizontalAlignment="Center" Height="14" Margin="0,645,0,0" VerticalAlignment="Top" Width="340"/>
    
    
    
    
        </Grid>
    
    </Window>
    "@ 
     
    $inputXML = $inputXML -replace 'mc:Ignorable="d"','' -replace "x:N",'N' -replace '^<Win.*', '<Window'
    [void][System.Reflection.Assembly]::LoadWithPartialName('presentationframework')
    [xml]$XAML = $inputXML
    #Read XAML
     
    $reader=(New-Object System.Xml.XmlNodeReader $xaml)
    try{
        $Form=[Windows.Markup.XamlReader]::Load( $reader )
    }
    catch{
        Write-Warning "Unable to parse XML, with error: $($Error[0])`n Ensure that there are NO SelectionChanged or TextChanged properties in your textboxes (PowerShell cannot process them)"
        throw
    }
     
    #===========================================================================
    # Load XAML Objects In PowerShell
    #===========================================================================
      
    $xaml.SelectNodes("//*[@Name]") | %{"trying item $($_.Name)";
        try {Set-Variable -Name "WPF$($_.Name)" -Value $Form.FindName($_.Name) -ErrorAction Stop}
        catch{throw}
        }
     
    Function Get-FormVariables{
    if ($global:ReadmeDisplay -ne $true){Write-host "If you need to reference this display again, run Get-FormVariables" -ForegroundColor Yellow;$global:ReadmeDisplay=$true}
    write-host "Found the following interactable elements from our form" -ForegroundColor Cyan
    get-variable WPF*
    }
     
    Get-FormVariables
     
    
    
    #===========================================================================
    # Shows the form
    #===========================================================================
    write-host "To show the form, run the following" -ForegroundColor Cyan
    $Form.ShowDialog() | out-null



    Et sa représentation graphique

    D'avance merci pour vos réponses

    • Partager sur Facebook
    • Partager sur Twitter

    ProgressBar Timer en xaml intégré powershell

    × Après avoir cliqué sur "Répondre" vous serez invité à vous connecter pour que votre message soit publié.
    × Attention, ce sujet est très ancien. Le déterrer n'est pas forcément approprié. Nous te conseillons de créer un nouveau sujet pour poser ta question.
    • Editeur
    • Markdown