Could someone tell me how I can save all selected items in a xaml listbox in Powershell? I can one selected item, but not all selected items when the listbox selectionmode is set to "extended"?
<ListBox Name="ListBoxRelations" Margin="1,53,0,174" FontSize="11" SelectionMode="Extended" HorizontalAlignment="Left" Width="417"/>
After
$xaml.SelectNodes("//*[@Name]") | %{Set-Variable -Name ($_.Name) -Value $Form.FindName($_.Name)}
$WMFStruct.SelectedHosts = $ListBoxRelations.SelectedItem
The above line only gets the first selected item in the listbox.
You are only getting a single item with the call to $ListBoxRelations.SelectedItem
. You need to get the $ListBoxRelations.SelectedItems
.
Then you can loop over the items.