Files
winutil/functions/public/Invoke-WPFToggleAllCategories.ps1
2026-02-05 15:50:15 -06:00

52 lines
1.9 KiB
PowerShell

function Invoke-WPFToggleAllCategories {
<#
.SYNOPSIS
Expands or collapses all categories in the Install tab
.PARAMETER Action
The action to perform: "Expand" or "Collapse"
.DESCRIPTION
This function iterates through all category containers in the Install tab
and expands or collapses their WrapPanels while updating the toggle button labels
#>
param(
[Parameter(Mandatory=$true)]
[ValidateSet("Expand", "Collapse")]
[string]$Action
)
try {
if ($null -eq $sync.ItemsControl) {
Write-Warning "ItemsControl not initialized"
return
}
$targetVisibility = if ($Action -eq "Expand") { [Windows.Visibility]::Visible } else { [Windows.Visibility]::Collapsed }
$targetPrefix = if ($Action -eq "Expand") { "-" } else { "+" }
$sourcePrefix = if ($Action -eq "Expand") { "+" } else { "-" }
# Iterate through all items in the ItemsControl
$sync.ItemsControl.Items | ForEach-Object {
$categoryContainer = $_
# Check if this is a category container (StackPanel with children)
if ($categoryContainer -is [System.Windows.Controls.StackPanel] -and $categoryContainer.Children.Count -ge 2) {
# Get the WrapPanel (second child)
$wrapPanel = $categoryContainer.Children[1]
$wrapPanel.Visibility = $targetVisibility
# Update the label to show the correct state
$categoryLabel = $categoryContainer.Children[0]
if ($categoryLabel.Content -like "$sourcePrefix*") {
$categoryLabel.Content = $categoryLabel.Content -replace "^$sourcePrefix ", "$targetPrefix "
}
}
}
}
catch {
Write-Error "Error toggling categories: $_"
}
}