我在我的 ListView 上应用了以下样式。但是这种样式导致我的 GridView 隐藏其标题行。如果我从 ListView 中删除此样式。可以看到标题行。我应该如何调整这种样式以显示标题行?
<Style x:Key="listViewStyle" TargetType="{x:Type ListView}">
<Setter Property="Background" Value="Black"/>
<Setter Property="BorderThickness" Value="0"/>
<Setter Property="Foreground" Value="White"/>
<Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Auto"/>
<Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Auto"/>
<Setter Property="ScrollViewer.CanContentScroll" Value="true"/>
<Setter Property="ScrollViewer.PanningMode" Value="Both"/>
<Setter Property="Stylus.IsFlicksEnabled" Value="False"/>
<Setter Property="VerticalContentAlignment" Value="Center"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ListBox}">
<!--<Border x:Name="Bd" BorderBrush="White" Opacity="0.1" BorderThickness="2" Background="{TemplateBinding Background}" Padding="1.5" SnapsToDevicePixels="true">-->
<Grid>
<Border x:Name="Bd" BorderBrush="White" Opacity="0.1" Background="{TemplateBinding Background}" Padding="1.5" SnapsToDevicePixels="true" />
<!--<Border CornerRadius="5" Background="White" Opacity="0.1" />-->
<ScrollViewer Focusable="false" Padding="{TemplateBinding Padding}" Template="{DynamicResource TreeViewScrollViewerControlTemplate}" >
<ItemsPresenter SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
</ScrollViewer>
</Grid>
<!--</Border>-->
<ControlTemplate.Triggers>
<Trigger Property="IsEnabled" Value="false">
<Setter Property="Background" TargetName="Bd" Value="{DynamicResource {x:Static SystemColors.ControlBrushKey}}"/>
</Trigger>
<Trigger Property="IsGrouping" Value="true">
<Setter Property="ScrollViewer.CanContentScroll" Value="false"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
下面是我的 ListView XAML:
<ListView ItemsSource="{Binding PersonList}" Width="750" MaxWidth="750" ScrollViewer.HorizontalScrollBarVisibility="Disabled" VerticalAlignment="Top" Height="200"
HorizontalAlignment="Right" Margin="20" util:GridViewSort.AutoSort="True">
<ListView.Style>
<Style TargetType="{x:Type ListView}" BasedOn="{StaticResource listViewStyle}">
<Style.Triggers>
<DataTrigger Binding="{Binding ElementName=gridViewRB, Path=IsChecked}" Value="true">
<Setter Property="View" Value="{StaticResource ResourceKey=GridView}" />
</DataTrigger>
</Style.Triggers>
</Style>
</ListView.Style>
</ListView>
还有我的 GridView:
<GridView x:Key="GridView">
<GridViewColumn>
<GridViewColumn.HeaderTemplate>
<DataTemplate>
<CheckBox Name="cbSelectAll" Command="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=ListView}, Path=DataContext.SelectAllCommand}" CommandParameter="{Binding RelativeSource={RelativeSource Mode=Self}, Path=IsChecked}" HorizontalAlignment="Center" VerticalAlignment="Center" />
</DataTemplate>
</GridViewColumn.HeaderTemplate>
<GridViewColumn.CellTemplate>
<DataTemplate>
<CheckBox IsChecked="{Binding Path=IsSelected, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Header="FirstName" DisplayMemberBinding="{Binding FirstName}" util:GridViewSort.PropertyName="WeightInGrams" />
<GridViewColumn Header="LastName" DisplayMemberBinding="{Binding LastName}" />
<GridViewColumn Header="Ip Address" DisplayMemberBinding="{Binding Path=IpAddress}" />
</GridView>