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
2025-06-26 19:11:38 +02:00
Also creates an overlay with a progress bar and text to indicate that an install or uninstall is in progress
2025-03-01 20:50:12 +01:00
. PARAMETER TargetElement
2025-10-14 19:51:53 +02:00
The element to which the AppArea should be added
2025-03-01 20:50:12 +01:00
#>
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 " )
2025-06-26 19:11:38 +02:00
$sync . InstallAppAreaBorder = $Border
2025-05-12 22:45:57 +02:00
# 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-06-26 19:11:38 +02:00
$sync . InstallAppAreaScrollViewer = $scrollViewer
$Border . Child = $scrollViewer
# Initialize the Blur Effect for the ScrollViewer, which will be used to indicate that an install/uninstall is in progress
$blurEffect = New-Object Windows . Media . Effects . BlurEffect
$blurEffect . Radius = 0
$scrollViewer . Effect = $blurEffect
2025-03-01 20:50:12 +01:00
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-06-26 19:11:38 +02:00
$scrollViewer . Content = $itemsControl
2025-03-01 20:50:12 +01:00
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 )
2025-06-26 19:11:38 +02:00
# Add the Border containing the App Area to the target Grid
$targetGrid . Children . Add ( $Border ) | Out-Null
$overlay = New-Object Windows . Controls . Border
$overlay . CornerRadius = New-Object Windows . CornerRadius ( 10 )
$overlay . SetResourceReference ( [ Windows.Controls.Control ] :: BackgroundProperty , " AppInstallOverlayBackgroundColor " )
$overlay . Visibility = [ Windows.Visibility ] :: Collapsed
# Also add the overlay to the target Grid on top of the App Area
$targetGrid . Children . Add ( $overlay ) | Out-Null
$sync . InstallAppAreaOverlay = $overlay
$overlayText = New-Object Windows . Controls . TextBlock
$overlayText . Text = " Installing apps... "
$overlayText . HorizontalAlignment = 'Center'
$overlayText . VerticalAlignment = 'Center'
$overlayText . SetResourceReference ( [ Windows.Controls.TextBlock ] :: ForegroundProperty , " MainForegroundColor " )
$overlayText . Background = " Transparent "
$overlayText . SetResourceReference ( [ Windows.Controls.TextBlock ] :: FontSizeProperty , " HeaderFontSize " )
$overlayText . SetResourceReference ( [ Windows.Controls.TextBlock ] :: FontFamilyProperty , " MainFontFamily " )
$overlayText . SetResourceReference ( [ Windows.Controls.TextBlock ] :: FontWeightProperty , " MainFontWeight " )
$overlayText . SetResourceReference ( [ Windows.Controls.TextBlock ] :: MarginProperty , " MainMargin " )
$sync . InstallAppAreaOverlayText = $overlayText
$progressbar = New-Object Windows . Controls . ProgressBar
$progressbar . Name = " ProgressBar "
$progressbar . Width = 250
$progressbar . Height = 50
$sync . ProgressBar = $progressbar
# Add a TextBlock overlay for the progress bar text
$progressBarTextBlock = New-Object Windows . Controls . TextBlock
$progressBarTextBlock . Name = " progressBarTextBlock "
$progressBarTextBlock . FontWeight = [ Windows.FontWeights ] :: Bold
$progressBarTextBlock . FontSize = 16
$progressBarTextBlock . Width = $progressbar . Width
$progressBarTextBlock . Height = $progressbar . Height
$progressBarTextBlock . SetResourceReference ( [ Windows.Controls.TextBlock ] :: ForegroundProperty , " ProgressBarTextColor " )
$progressBarTextBlock . TextTrimming = " CharacterEllipsis "
$progressBarTextBlock . Background = " Transparent "
$sync . progressBarTextBlock = $progressBarTextBlock
# Create a Grid to overlay the text on the progress bar
$progressGrid = New-Object Windows . Controls . Grid
$progressGrid . Width = $progressbar . Width
$progressGrid . Height = $progressbar . Height
$progressGrid . Margin = " 0,10,0,10 "
$progressGrid . Children . Add ( $progressbar ) | Out-Null
$progressGrid . Children . Add ( $progressBarTextBlock ) | Out-Null
$overlayStackPanel = New-Object Windows . Controls . StackPanel
$overlayStackPanel . Orientation = " Vertical "
$overlayStackPanel . HorizontalAlignment = 'Center'
$overlayStackPanel . VerticalAlignment = 'Center'
$overlayStackPanel . Children . Add ( $overlayText ) | Out-Null
$overlayStackPanel . Children . Add ( $progressGrid ) | Out-Null
$overlay . Child = $overlayStackPanel
2025-03-01 20:50:12 +01:00
return $itemsControl
}