Un petit script pour le changement de valeur pour une combobox.
Un peu compliqué a faire pour récupérer la bonne valeur
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
[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="titre" Height="573.975" Width="668.135"> <Grid> <ComboBox Name="Combo1" HorizontalAlignment="Left" VerticalAlignment="Top" Width="453" Margin="40,99,0,0"/> </Grid> </Window> '@ #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. Some possible causes for this problem include: .NET Framework is missing PowerShell must be launched with PowerShell -sta, invalid XAML code was encountered."; exit} #=========================================================================== # Store Form Objects In PowerShell #=========================================================================== $xaml.SelectNodes("//*[@Name]") | %{Set-Variable -Name ($_.Name) -Value $Form.FindName($_.Name)} $Combo1.Items.add("toto") | out-null $Combo1.Items.add("tata") | out-null $Combo1.Items.add("titi") | out-null $Combo1.add_SelectionChanged({ param($sender,$args) write-host $($sender.SelectedValue) }) # Display UI object $Form.ShowDialog() | out-null |
- david on 18 février 2020 à 20 h 17 min
Cet article a été créé par david le 18 février 2020.
Laisser un commentaire