我试图让下面的 TextBlocks 折叠起来,但是它不起作用:
<DockPanel Grid.Column="1" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" LastChildFill="False" >
<DockPanel.Resources>
<Style x:Key="ReferenceValues" TargetType="{x:Type TextBlock}">
<Style.Triggers>
<Trigger Property="Text" Value="">
<Setter Property="Visibility" Value="Collapsed" />
</Trigger>
<Trigger Property="Text" Value="{x:Null}">
<Setter Property="Visibility" Value="Collapsed" />
</Trigger>
</Style.Triggers>
</Style>
</DockPanel.Resources>
<TextBlock Style="{StaticResource ReferenceValues}" FontFamily="Segoe UI Light" FontSize="14" DockPanel.Dock="Top" Text="{Binding PropFullName}" Margin="2,2,2,2" Visibility="Visible"/>
<TextBlock Style="{StaticResource ReferenceValues}" FontFamily="Segoe UI Light" FontSize="14" DockPanel.Dock="Top" Text="{Binding PropTitle}" Margin="2,2,2,2" Visibility="Visible"/>
<TextBlock Style="{StaticResource ReferenceValues}" FontFamily="Segoe UI Light" FontSize="14" DockPanel.Dock="Top" Text="{Binding PropUserName}" Margin="2,2,2,2" Visibility="Visible"/>
<TextBlock Style="{StaticResource ReferenceValues}" FontFamily="Segoe UI Light" FontSize="14" DockPanel.Dock="Top" Text="{Binding PropYear}" Margin="2,2,2,2" Visibility="Visible"/>
<TextBlock Style="{StaticResource ReferenceValues}" FontFamily="Segoe UI Light" FontSize="14" DockPanel.Dock="Top" Text="{Binding PropEmailAddress}" Margin="2,2,2,2" Visibility="Visible"/>
<TextBlock Style="{StaticResource ReferenceValues}" FontFamily="Segoe UI Light" FontSize="14" DockPanel.Dock="Top" Text="{Binding PropStartingPage}" Margin="2,2,2,2" Visibility="Visible"/>
<TextBlock Style="{StaticResource ReferenceValues}" FontFamily="Segoe UI Light" FontSize="14" DockPanel.Dock="Top" Text="{Binding PropEndingPage}" Margin="2,2,2,2" Visibility="Visible"/>
<TextBlock Style="{StaticResource ReferenceValues}" FontFamily="Segoe UI Light" FontSize="14" DockPanel.Dock="Top" Text="{Binding PropStartingDate}" Margin="2,2,2,2" Visibility="Visible"/>
<TextBlock Style="{StaticResource ReferenceValues}" FontFamily="Segoe UI Light" FontSize="14" DockPanel.Dock="Top" Text="{Binding PropEndingDate}" Margin="2,2,2,2" Visibility="Visible"/>
<TextBlock Style="{StaticResource ReferenceValues}" FontFamily="Segoe UI Light" FontSize="14" DockPanel.Dock="Top" Text="{Binding PropLastUpdate}" Margin="2,2,2,2" Visibility="Visible"/>
<TextBlock Style="{StaticResource ReferenceValues}" FontFamily="Segoe UI Light" FontSize="14" DockPanel.Dock="Top" Text="{Binding PropFileFormat}" Margin="2,2,2,2" Visibility="Visible"/>
...
</DockPanel>
null
当值为或时,它们仅显示为空白""
。a 是否DockPanel
自动不渲染未显示的控件?(只有 3 个TextBlocks
可以适应 72 像素。)