Question
Actualiser GUI XAML dans Powershell
- kevinklein
- Auteur du sujet
- Hors Ligne
- Nouveau membre
Réduire
Plus d'informations
- Messages : 18
- Remerciements reçus 0
il y a 8 ans 7 mois #20629
par kevinklein
Actualiser GUI XAML dans Powershell a été créé par kevinklein
Bonjour l'équipe,
Je souhaite actualiser mon GUI quand j’exécute une barre de progression. Actuellement ma barre se remplit mais après que l'action se soit réalisée et pas pendant.
Je précise que mon GUI est en réalité du code XAML que j'ai intégré dans un script en powershell.
Pourriez vous m'aider svp ? Merci
[code:1][void][Reflection.Assembly]::LoadWithPartialName('PresentationFramework')
[void][Reflection.Assembly]::LoadWithPartialName(\"PresentationCore\"«»)
[void][Reflection.Assembly]::LoadWithPartialName(\"WindowsBase\"«»)
#ERASE ALL THIS AND PUT XAML BELOW between the @\" \"@
$inputXML = @\"
<Window x:Class=\"WpfApplication.MainWindow\"
xmlns=\"schemas.microsoft.com/winfx/2006/xaml/presentation\"
xmlns:«»x=\"schemas.microsoft.com/winfx/2006/xaml\"
Title=\"Interface\" Height=\"350\" Width=\"525\">
<Grid>
<ProgressBar Name=\"progress_bar\" HorizontalAlignment=\"Left\" Height=\"29\" Margin=\"42,79,0,0\" VerticalAlignment=\"Top\" Width=\"403\"/>
<Button Name=\"button_start\" Content=\"Start\" HorizontalAlignment=\"Left\" Height=\"28\" Margin=\"159,155,0,0\" VerticalAlignment=\"Top\" Width=\"88\"/>
</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-Host \"Unable to load Windows.Markup.XamlReader. Double-check syntax and ensure .net is installed.\"}
$xaml.SelectNodes(\"//*[@Name]\"«») | %{Set-Variable -Name \"WPF$($_.Name)\" -Value $Form.FindName($_.Name)}
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}
}
Get-FormVariables
$Global:«»ProgressCurrent = 0
$Global:«»ProgressTotal = 20
$button_start = $Form.FindName(\"button_start\"«»)
Function UpdateProgressBar{
$progress_bar = $Form.FindName(\"progress_bar\"«»)
$Progress = $Global:«»ProgressCurrent /$Global:«»ProgressTotal*100
$progress_bar.Value = $Progress
}
$button_start.Add_Click(
{
Do{
[int]$Global:«»ProgressCurrent = $Global:«»ProgressCurrent +1
UpdateProgressBar
}While($Global:«»ProgressCurrent -lt $Global:«»ProgressTotal)
}
)
$Form.ShowDialog() | out-null[/code:1]
Je souhaite actualiser mon GUI quand j’exécute une barre de progression. Actuellement ma barre se remplit mais après que l'action se soit réalisée et pas pendant.
Je précise que mon GUI est en réalité du code XAML que j'ai intégré dans un script en powershell.
Pourriez vous m'aider svp ? Merci
[code:1][void][Reflection.Assembly]::LoadWithPartialName('PresentationFramework')
[void][Reflection.Assembly]::LoadWithPartialName(\"PresentationCore\"«»)
[void][Reflection.Assembly]::LoadWithPartialName(\"WindowsBase\"«»)
#ERASE ALL THIS AND PUT XAML BELOW between the @\" \"@
$inputXML = @\"
<Window x:Class=\"WpfApplication.MainWindow\"
xmlns=\"schemas.microsoft.com/winfx/2006/xaml/presentation\"
xmlns:«»x=\"schemas.microsoft.com/winfx/2006/xaml\"
Title=\"Interface\" Height=\"350\" Width=\"525\">
<Grid>
<ProgressBar Name=\"progress_bar\" HorizontalAlignment=\"Left\" Height=\"29\" Margin=\"42,79,0,0\" VerticalAlignment=\"Top\" Width=\"403\"/>
<Button Name=\"button_start\" Content=\"Start\" HorizontalAlignment=\"Left\" Height=\"28\" Margin=\"159,155,0,0\" VerticalAlignment=\"Top\" Width=\"88\"/>
</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-Host \"Unable to load Windows.Markup.XamlReader. Double-check syntax and ensure .net is installed.\"}
$xaml.SelectNodes(\"//*[@Name]\"«») | %{Set-Variable -Name \"WPF$($_.Name)\" -Value $Form.FindName($_.Name)}
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}
}
Get-FormVariables
$Global:«»ProgressCurrent = 0
$Global:«»ProgressTotal = 20
$button_start = $Form.FindName(\"button_start\"«»)
Function UpdateProgressBar{
$progress_bar = $Form.FindName(\"progress_bar\"«»)
$Progress = $Global:«»ProgressCurrent /$Global:«»ProgressTotal*100
$progress_bar.Value = $Progress
}
$button_start.Add_Click(
{
Do{
[int]$Global:«»ProgressCurrent = $Global:«»ProgressCurrent +1
UpdateProgressBar
}While($Global:«»ProgressCurrent -lt $Global:«»ProgressTotal)
}
)
$Form.ShowDialog() | out-null[/code:1]
Connexion ou Créer un compte pour participer à la conversation.
- Matthew BETTON
- Hors Ligne
- Membre platinium
Réduire
Plus d'informations
- Messages : 968
- Remerciements reçus 0
il y a 8 ans 7 mois #20630
par Matthew BETTON
Réponse de Matthew BETTON sur le sujet Re:Actualiser GUI XAML dans Powershell
Salut,
Voir ce poste récent
WPF et MultiThread
et notamment la réponse de NicolasB :
NicolasB écrit:
Il me semble que le code qu'il donne en exemple peut t'aider ...
(Voir en bas de page => Re: plantage form - 7/06/15 20:12 )<br><br>Message édité par: Matthew BETTON, à: 13/08/15 08:48
Voir ce poste récent
WPF et MultiThread
et notamment la réponse de NicolasB :
NicolasB écrit:
Tu peux t'aider de ma dernière réponse sur ce poste:
powershell-scripting.com/index.php?optio...gt;<br>Message édité par: NicolasB, à: 2/08/15 22:20
Il me semble que le code qu'il donne en exemple peut t'aider ...
(Voir en bas de page => Re: plantage form - 7/06/15 20:12 )<br><br>Message édité par: Matthew BETTON, à: 13/08/15 08:48
Connexion ou Créer un compte pour participer à la conversation.
Temps de génération de la page : 0.070 secondes
- Vous êtes ici :
- Accueil
- forum
- PowerShell
- Entraide pour les débutants
- Actualiser GUI XAML dans Powershell