@@ -49,7 +49,7 @@ function Show-AnyBox
4949 The resize mode of the window. Note that this parameter also affects whether the minimize and maximize
5050 buttons are present. Due to the design of AnyBox, only horizontal resizing is allowed.
5151 . PARAMETER NoResize
52- A simpler way to prevent window resizing without affecting the appearance of the system buttons .
52+ A simpler way to prevent window resizing.
5353 . PARAMETER MinHeight
5454 The minimum height of the resulting window, in pixels.
5555 . PARAMETER MinWidth
@@ -123,16 +123,16 @@ function Show-AnyBox
123123 [string ]$SelectionMode = ' SingleCell' ,
124124 [switch ]$HideGridSearch
125125 )
126-
127- if ($HideTaskbarIcon -and $ResizeMode -ne ' NoResize' -and @ (' None' , ' ToolWindow' ) -notcontains $WindowStyle ) {
126+
127+ if ($NoResize -or ( $ HideTaskbarIcon -and $ResizeMode -ne ' NoResize' -and @ (' None' , ' ToolWindow' ) -notcontains $WindowStyle ) ) {
128128 # No minimize button
129129 $ResizeMode = ' NoResize'
130130 }
131131
132132 $form = @ {' Result' = @ {}} # [hashtable]::Synchronized(@{ 'Result' = @{})
133133
134134 [string []]$action_btns = @ ()
135-
135+
136136 if ($GridData -and -not $HideGridSearch ) {
137137 $action_btns += @ (' Explore' , ' Save' )
138138 }
@@ -161,9 +161,9 @@ function Show-AnyBox
161161 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
162162 AllowsTransparency="False" WindowStartupLocation="CenterScreen" SizeToContent="WidthAndHeight" ShowActivated="True"
163163 Topmost="$ ( $Topmost -as [bool ]) " ShowInTaskbar="$ ( -not ($HideTaskbarIcon -as [bool ])) " MinWidth="$MinWidth " MinHeight="$MinHeight "
164- WindowStyle="$WindowStyle " WindowState=" $WindowState " ResizeMode="$ResizeMode ">
164+ WindowStyle="$WindowStyle " ResizeMode="$ResizeMode ">
165165 <Border Name="padBorder" Padding="10, 0, 10, 10">
166- <Grid Name="grid" Width="Auto" Height="Auto" Background="LightSteelBlue" ShowGridLines="True ">
166+ <Grid Name="grid" Width="Auto" Height="Auto" ShowGridLines="False ">
167167 <Grid.ColumnDefinitions>
168168 <ColumnDefinition Width="*" />
169169 </Grid.ColumnDefinitions>
@@ -187,9 +187,6 @@ function Show-AnyBox
187187 $xaml.SelectNodes (' //*[@Name]' ).Name | ForEach-Object { $form.Add ($_ , $form.Window.FindName ($_ )) }
188188 $xaml = $null
189189
190- # $form.Window.MaxWidth = [System.Windows.SystemParameters]::WorkArea.Width
191- # $form.Window.MaxHeight = [System.Windows.SystemParameters]::WorkArea.Height
192-
193190 if ($WindowStyle -eq ' None' ) {
194191 $form.Window.BorderBrush = ' Black'
195192 $form.Window.BorderThickness = ' 1'
@@ -288,15 +285,15 @@ function Show-AnyBox
288285
289286 return $null
290287 }
291-
288+
292289 # Add message textblocks.
293290 if (($txtMsg = New-TextBlock - text $ ($Message -join [environment ]::NewLine) - name ' txt_Message' )) {
294- $form.stack .AddChild ($txtMsg )
291+ $form.highStack .AddChild ($txtMsg )
295292 }
296293
297294 if ($GridData -and -not $HideGridSearch ) {
298295 $gridMsg = New-TextBlock - text $ (' {0} Results' -f $GridData.Count ) - name ' txt_Grid'
299- $form.stack .AddChild ($gridMsg )
296+ $form.highStack .AddChild ($gridMsg )
300297 }
301298
302299 # Add prompt-message textblocks and input textboxes.
@@ -306,7 +303,7 @@ function Show-AnyBox
306303
307304 if ($Prompt [$i ].ValidateSet) { # Combo box
308305 if (($inPrmpt = New-TextBlock $Prompt [$i ].Message)){
309- $form.stack .AddChild ($inPrmpt )
306+ $form.highStack .AddChild ($inPrmpt )
310307 }
311308 # Combo box
312309 $inBox = New-Object System.Windows.Controls.ComboBox
@@ -416,7 +413,7 @@ function Show-AnyBox
416413 $inBox.FontSize = $FontSize
417414 $inBox.TextWrapping = ' NoWrap'
418415 $inBox.Background = ' WhiteSmoke'
419-
416+
420417 if ($Prompt [$i ].DefaultValue -ne $null ) {
421418 $inBox.Text = $Prompt [$i ].DefaultValue
422419 }
@@ -434,15 +431,15 @@ function Show-AnyBox
434431 $inBox.MaxHeight = 25 * @ ($Prompt [$i ].DefaultValue -split " `n " ).Count
435432 $inBox.Height = $inBox.MaxHeight
436433 }
437-
434+
438435 $inBox.add_GotFocus ({$_.Source.SelectAll ()})
439436
440437 # #############################################
441438
442439 if ($Prompt [$i ].InputType -eq [AnyBox.InputType ]::FileOpen -or $Prompt [$i ].InputType -eq [AnyBox.InputType ]::FileSave) {
443440 $inPanel = New-Object System.Windows.Controls.DockPanel
444441 $inPanel.LastChildFill = $true
445-
442+
446443 $fileBtn = New-Object System.Windows.Controls.Button
447444 $fileBtn.Name = " btn_Input_$i "
448445 $fileBtn.Height = 25
@@ -451,7 +448,7 @@ function Show-AnyBox
451448
452449 $inBox.Margin = " 0, 5, 0, 0"
453450 $inBox.Padding = " 0, 0, $ ( $fileBtn.Width.ToString ()) , 0"
454-
451+
455452 $fileBtn.ToolTip = ' Browse'
456453 $fileBtn.Content = ' ...'
457454
@@ -521,13 +518,15 @@ function Show-AnyBox
521518 $form.highStack.AddChild ($txtMsg )
522519 }
523520
524- if ($form .ContainsKey ( ' GridData' ) )
521+ if ($GridData )
525522 {
526523 # $dataGrid = New-Object System.Windows.Controls.DataGrid
527524 # $dataGrid.Name = 'data_grid'
528525
529526 $dataGrid = $form [' data_grid' ]
530527
528+ $dataGrid.ItemsSource = $GridData
529+
531530 $dataGrid.Visibility = ' Visible'
532531
533532 if ($SelectionMode -like ' Multi*' ) {
@@ -536,22 +535,21 @@ function Show-AnyBox
536535 else {
537536 $dataGrid.SelectionMode = ' Single'
538537 }
539-
538+
540539 if ($SelectionMode -like ' *Row' ) {
541540 $dataGrid.SelectionUnit = ' FullRow'
542541 }
543542 else {
544543 $dataGrid.SelectionUnit = ' Cell'
545544 }
546-
545+
547546 $dataGrid.ClipboardCopyMode = ' ExcludeHeader'
548547 $dataGrid.Margin = " 0, 10, 0, 0"
549548 $dataGrid.IsReadOnly = $true
550549 $dataGrid.AutoGenerateColumns = $true
551550 $dataGrid.VerticalScrollBarVisibility = ' Auto'
552551 $dataGrid.HorizontalScrollBarVisibility = ' Auto'
553552 $dataGrid.HorizontalAlignment = ' Stretch'
554- # $dataGrid.ColumnWidth = '80'
555553 $dataGrid.HorizontalContentAlignment = ' Stretch'
556554 $dataGrid.VerticalContentAlignment = ' Stretch'
557555 $dataGrid.VerticalAlignment = ' Stretch'
@@ -565,13 +563,12 @@ function Show-AnyBox
565563 $dataGrid.CanUserReorderColumns = $false
566564 $dataGrid.CanUserDeleteRows = $true
567565 $dataGrid.GridLinesVisibility = ' All'
568- $dataGrid.ItemsSource = $GridData # | ConvertTo-DataTable
569566 $dataGrid.FontSize = 12
570567
571568 if (-not $HideGridSearch ) {
572569 [scriptblock ]$filterGrid = {
573570 if (-not $form.filterText.Text ) {
574- $form.data_grid.ItemsSource = $GridData # | ConvertTo-DataTable
571+ $form.data_grid.ItemsSource = $GridData
575572 if ($form.ContainsKey (' txt_Grid' ) -and $form [' txt_Grid' ].Visibility -eq ' Visible' ) {
576573 $form [' txt_Grid' ].Text = ' {0} Results' -f $GridData.Count
577574 }
@@ -629,7 +626,7 @@ function Show-AnyBox
629626 $fltrBy.VerticalAlignment = ' Center'
630627 $fltrBy.VerticalContentAlignment = ' Center'
631628 $fltrBy.add_SelectionChanged ({& $filterGrid })
632-
629+
633630 $fltrMatch = New-Object System.Windows.Controls.ComboBox
634631 $fltrMatch.Name = ' filterMatch'
635632 $fltrMatch.FontSize = $FontSize
@@ -671,25 +668,25 @@ function Show-AnyBox
671668 $form.Add ($fltrBy.Name , $fltrBy )
672669 $form.Add ($fltrMatch.Name , $fltrMatch )
673670 $form.Add ($fltrBox.Name , $fltrBox )
674- $form.stack .AddChild ($fltrPanel )
671+ $form.highStack .AddChild ($fltrPanel )
675672 }
676673
677- $form.stack .AddChild ($dataGrid )
678- $form.Add ($dataGrid.Name , $dataGrid )
674+ # $form.highStack .AddChild($dataGrid)
675+ # $form.Add($dataGrid.Name, $dataGrid)
679676 }
680677
681678 # Add comment textblocks.
682679 if (($txtMsg = New-TextBlock - text $ ($Comment -join [environment ]::NewLine) - name ' txt_Explain' )) {
683680 $txtMsg.FontStyle = ' Italic'
684681 $txtMsg.FontWeight = ' Normal'
685- $form.stack .AddChild ($txtMsg )
682+ $form.highStack .AddChild ($txtMsg )
686683 }
687684
688685 if ($Timeout -and $Timeout -gt 0 -and $Countdown ) {
689686 # Create countdown textblock.
690687 $txtTime = New-TextBlock ' ---'
691688 $txtTime.Name = ' txt_Countdown'
692- $form.stack .AddChild ($txtTime )
689+ $form.highStack .AddChild ($txtTime )
693690 $form.Add ($txtTime.Name , $txtTime )
694691 }
695692
@@ -844,7 +841,7 @@ function Show-AnyBox
844841 $form.Window.Owner.Opacity = 0.4
845842 }
846843
847- if ($form .ContainsKey ( ' data_grid ' ) ) {
844+ if ($GridData ) {
848845 if (-not $HideGridSearch ) {
849846 $form.filterBy.ItemsSource = @ ($form.data_grid.Columns.Header )
850847 $form.filterBy.SelectedIndex = 0
@@ -854,11 +851,7 @@ function Show-AnyBox
854851 $_.CanUserSort = $true
855852 $_.SortMemberPath = $_.Header.ToString ()
856853 $_.SortDirection = " Ascending"
857- $_.Width = $_.ActualWidth # [double]::NaN
858854 }
859-
860- $form.data_grid.Height = $form.data_grid.ActualHeight
861- $form.data_grid.Width = $form.data_grid.ActualWidth
862855 }
863856
864857 if ($Prompt ) {
@@ -882,14 +875,6 @@ function Show-AnyBox
882875 $form.Window.add_ContentRendered ({
883876 $form.Window.SizeToContent = ' Manual'
884877
885- if ($NoResize ) {
886- $form.Window.MinWidth = $form.Window.Width
887- $form.Window.MaxWidth = $form.Window.Width
888- # No vertical resize.
889- $form.Window.MinHeight = $form.Window.Height
890- $form.Window.MaxHeight = $form.Window.Height
891- }
892-
893878 $form.Window.Opacity = 1.0
894879
895880 if ($Timeout -and $Timeout -gt 0 )
@@ -914,7 +899,7 @@ function Show-AnyBox
914899
915900 $timer.Start ()
916901 }
917-
902+
918903 $form.Window.Activate ()
919904 })
920905
@@ -947,7 +932,7 @@ function Show-AnyBox
947932 }
948933 elseif ($_.Name -eq ' data_grid' -and ($form [' data_grid' ].SelectedCells.Count -gt 0 -or $form [' data_grid' ].SelectedItems.Count -gt 0 )) {
949934 $selection = $null
950-
935+
951936 switch ($SelectionMode )
952937 {
953938 ' SingleCell' {
@@ -963,7 +948,7 @@ function Show-AnyBox
963948 [psobject []]$selection = @ ($form [' data_grid' ].SelectedItems)
964949 }
965950 }
966-
951+
967952 $form.Result.Add (' grid_select' , $selection )
968953 }
969954 }
0 commit comments