2025-03-01 20:50:12 +01:00
function Initialize-InstallAppArea {
<#
. SYNOPSIS
Creates a [ Windows.Controls.ScrollViewer] containing a [Windows.Controls.ItemsControl ] which is setup to use Virtualization to only load the visible elements for performance reasons .
This is used as the parent object for all category and app entries on the install tab
Used to as part of the Install Tab UI generation
. PARAMETER TargetElement
The element to which the AppArea shoud be added
#>
param ( $TargetElement )
2025-05-12 22:45:57 +02:00
$targetGrid = $sync . Form . FindName ( $TargetElement )
$null = $targetGrid . Children . Clear ( )
# Create the outer Border for the aren where the apps will be placed
$Border = New-Object Windows . Controls . Border
$Border . VerticalAlignment = " Stretch "
$Border . SetResourceReference ( [ Windows.Controls.Control ] :: StyleProperty , " BorderStyle " )
# Add a ScrollViewer, because the ItemsControl does not support scrolling by itself
2025-03-01 20:50:12 +01:00
$scrollViewer = New-Object Windows . Controls . ScrollViewer
$scrollViewer . VerticalScrollBarVisibility = 'Auto'
$scrollViewer . HorizontalAlignment = 'Stretch'
$scrollViewer . VerticalAlignment = 'Stretch'
$scrollViewer . CanContentScroll = $true
2025-05-12 22:45:57 +02:00
## Create the ItemsControl, which will be the parent of all the app entries
2025-03-01 20:50:12 +01:00
$itemsControl = New-Object Windows . Controls . ItemsControl
$itemsControl . HorizontalAlignment = 'Stretch'
$itemsControl . VerticalAlignment = 'Stretch'
2025-05-12 22:45:57 +02:00
# Enable virtualization for the ItemsControl to improve performance (It's hard to test if this is actually working, so if you know what you're doing, please check this)
2025-03-01 20:50:12 +01:00
$itemsPanelTemplate = New-Object Windows . Controls . ItemsPanelTemplate
$factory = New-Object Windows . FrameworkElementFactory ( [ Windows.Controls.VirtualizingStackPanel ] )
$itemsPanelTemplate . VisualTree = $factory
$itemsControl . ItemsPanel = $itemsPanelTemplate
$itemsControl . SetValue ( [ Windows.Controls.VirtualizingStackPanel ] :: IsVirtualizingProperty , $true )
$itemsControl . SetValue ( [ Windows.Controls.VirtualizingStackPanel ] :: VirtualizationModeProperty , [ Windows.Controls.VirtualizationMode ] :: Recycling )
$scrollViewer . Content = $itemsControl
2025-05-12 22:45:57 +02:00
$Border . Child = $scrollViewer
$null = $targetGrid . Children . Add ( $Border )
2025-03-01 20:50:12 +01:00
return $itemsControl
}