Question ProgressBar avec Timer - Powershell XAML

Plus d'informations
il y a 2 ans 10 mois #30963 par ced24
Bonjour,  Je suis débutant et j'ai créé une interface UI en XAML que j'exécute avec un code powershelll (pour affichage dans une séquence de tache Configuration Manager).J'aimerai afficher une progress bar qui se charge pendant 5 minutes. Une fois écoulé, je souhaiterais que la fenetre se ferme automatique tout en envoyant une variable dans ma séquence de tache (ça c'est ok j'ai la commande)Je souhaiterai également afficher le temps restant en temps réel dans la fenêtre.Voici le modèle épuré de la fenêtre que je souhaiterai.
$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

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

Plus d'informations
il y a 2 ans 10 mois #30964 par Arnaud Petitjean
Bonjour Ced24,

Tout d'abord soit le bienvenu dans le forum ! ;-) 
Pourrais-tu prendre 2 minutes STP pour te présenter dans la rubrique du forum qui va bien ?

Joli petit projet une GUI !
Avant d'entrer davantage dans ton implémentation (car la création de GUI est toujours assez chronophage), as-tu été voir cet article ? : www.systanddeploy.com/2018/12/create-coo...s-or-rings-with.html

 

MVP PowerShell et créateur de ce magnifique forum :-)
Auteur de 6 livres PowerShell aux éditions ENI
Fondateur de la société Start-Scripting
Besoin d'une formation PowerShell ?

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

Plus d'informations
il y a 2 ans 10 mois - il y a 2 ans 10 mois #30966 par ced24
Bonjour,

Oui en effet j'ai bien vu cet article mais je pense que je ne comprends pas tout vu mon faible niveau sur le sujet. Je pense que si je vois mon code incrémenter avec les bonnes lignes je vais dire "ah oui mais bien sûr" mais c'est justement ça qui me manque.

J'ai vu qu'il y a une histoire de fonction timer à intégrer dans mon code mais la question c'est comment incrémenter cette fonction et ses valeurs dans mon code xaml qui est lui même dans un powershell

Du coup, je suis toujours à l'écoute de solution :)
Dernière édition: il y a 2 ans 10 mois par ced24.

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

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