diff --git a/functions/public/Invoke-WPFUIElements.ps1 b/functions/public/Invoke-WPFUIElements.ps1 index b17623ad..6fcbd19c 100644 --- a/functions/public/Invoke-WPFUIElements.ps1 +++ b/functions/public/Invoke-WPFUIElements.ps1 @@ -36,7 +36,11 @@ function Invoke-WPFUIElements { throw "Failed to retrieve Styles using 'FindResource' from main window element." } - $targetGrid = $window.FindName($targetGridName) + try { + $targetGrid = $window.FindName($targetGridName) + } catch { + throw "Failed to find the target grid '$targetGridName' in the main window." + } # Clear existing ColumnDefinitions and Children $targetGrid.ColumnDefinitions.Clear() | Out-Null