2017-10-15 12 views
0

私が探している最終的な効果は、「1」行を「消える」ことです:上から2番目の行はText1が行1が存在しなかった場合。Powershell WPF XAML折りたたみRowDefinition高さまたはイベントで0に設定

これは私が達成しようとしているモックアップです。上の2つの行と列はほぼ同じです。

このXAMLをVS2017コミュニティに接続し、行の高さを0に設定すると、これが機能します。数日のグーグル・グーグルでは、私は解決策を考え出していません。

C#はまったく分かりません。

プラットフォーム:Windows 7の //ポッシュV5

すぐのWindows 10 //ポッシュv5の理想的

されるように、私はそれを閉じた状態で起動し、イベントでそれを開きたいと思います。

[void][System.Reflection.Assembly]::LoadWithPartialName('presentationframework') 
[xml]$XAML = @' 
<Window 
     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
     Title="TabularGrid" Height="300" Width="300"> 
    <Grid Name="Grid"> 
       <Grid.ColumnDefinitions> 
         <ColumnDefinition Width="*" /> 
         <ColumnDefinition Width="80" /> 
       </Grid.ColumnDefinitions> 
       <Grid.RowDefinitions> 
         <RowDefinition Height="*" /> 
         <RowDefinition Height="40" /> 
         <RowDefinition Height="30" /> 
         <RowDefinition Height="30" /> 
       </Grid.RowDefinitions> 
       <TextBox Name="Text1" Background="Silver" Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="2" >Text1</TextBox> 
       <TextBox Name="Text2" Grid.Row="1" Grid.Column="0" >Text2</TextBox> 
       <Button Name="Enter" Grid.Row="1" Grid.Column="1" >Enter</Button> 
       <Button Name="Open" Grid.Row="2" Grid.ColumnSpan="2" >Open</Button> 
       <Button Name="Close" Grid.Row="3" Grid.ColumnSpan="2" >Close</Button> 
     </Grid> 
</Window> 
'@ 

$reader=(New-Object System.Xml.XmlNodeReader $xaml) 
$Form=[Windows.Markup.XamlReader]::Load($reader) 
$xaml.SelectNodes("//*[@Name]") | %{Set-Variable -Name "WPF$($_.Name)" -Value $Form.FindName($_.Name)} 

#=========================================================================== 
# Store Form Objects In PowerShell 
#=========================================================================== 

Function Get-FormVariables{ 
if ($global:ReadmeDisplay -ne $true){Write-host "If you need to reference this display again, run Get-FormVariables" -ForegroundColor Yellow;$global:ReadmeDisplay=$true} 
write-host "Found the following interactable elements from our form" -ForegroundColor Cyan 
get-variable WPF* 
} 

Get-FormVariables 


#=========================================================================== 
# Shows the form 
#=========================================================================== 


$WPFOpen.Add_Click({ 
$WPFGrid.RowDefinition[1].Visibility = $true 
# or 
$WPFGrid.RowDefinition[1].Height="40" 
}) 

$WPFClose.Add_Click({ 
$WPFGrid.RowDefinition[1].Visibility = $false 
# or 
$WPFGrid.RowDefinition[1].Height="0" 
}) 
#> 

$Form.ShowDialog() | out-null 

ありがとうございます。

答えて

1

$WPFGrid.RowDefinitionではなく、$WPFGrid.RowDefinitionsの末尾にsがあるからです。

私はそれがRowDefinitionsで実装されていないためだVisibility方法を取り除き、目に見えない行でウィンドウを起動するために<RowDefinition Height="0" /><RowDefinition Height="40" />を変更しました。

このコードは

[void][System.Reflection.Assembly]::LoadWithPartialName('presentationframework') 
[xml]$XAML = @' 
<Window 
     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
     Title="TabularGrid" Height="300" Width="300"> 
    <Grid Name="Grid"> 
       <Grid.ColumnDefinitions> 
         <ColumnDefinition Width="*" /> 
         <ColumnDefinition Width="80" /> 
       </Grid.ColumnDefinitions> 
       <Grid.RowDefinitions> 
         <RowDefinition Height="*" /> 
         <RowDefinition Height="0" /> 
         <RowDefinition Height="30" /> 
         <RowDefinition Height="30" /> 
       </Grid.RowDefinitions> 
       <TextBox Name="Text1" Background="Silver" Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="2" >Text1</TextBox> 
       <TextBox Name="Text2" Grid.Row="1" Grid.Column="0" >Text2</TextBox> 
       <Button Name="Enter" Grid.Row="1" Grid.Column="1" >Enter</Button> 
       <Button Name="Open" Grid.Row="2" Grid.ColumnSpan="2" >Open</Button> 
       <Button Name="Close" Grid.Row="3" Grid.ColumnSpan="2" >Close</Button> 
     </Grid> 
</Window> 
'@ 

$reader=(New-Object System.Xml.XmlNodeReader $xaml) 
$Form=[Windows.Markup.XamlReader]::Load($reader) 
$xaml.SelectNodes("//*[@Name]") | %{Set-Variable -Name "WPF$($_.Name)" -Value $Form.FindName($_.Name)} 

#=========================================================================== 
# Store Form Objects In PowerShell 
#=========================================================================== 

Function Get-FormVariables{ 
if ($global:ReadmeDisplay -ne $true){Write-host "If you need to reference this display again, run Get-FormVariables" -ForegroundColor Yellow;$global:ReadmeDisplay=$true} 
write-host "Found the following interactable elements from our form" -ForegroundColor Cyan 
get-variable WPF* 
} 

Get-FormVariables 


#=========================================================================== 
# Shows the form 
#=========================================================================== 


$WPFOpen.Add_Click({ 
    $WPFGrid.RowDefinitions[1].Height= 40 
}) 

$WPFClose.Add_Click({ 
    $WPFGrid.RowDefinitions[1].Height= 0 
}) 

$Form.ShowDialog() | out-null 
+1

を働いているあなたにマヌーありがとうございました!私はこれを試みました。 (明らかにそうではない)。 – Steve

関連する問題