删除ListView列中的分隔符 - WPF

时间:2013-01-15 08:09:06

标签: wpf listview

我创建了下一个ListView

 <ListView Height="Auto" MaxHeight="300" Margin="5,5,5,0" BorderBrush="Transparent"
                        ItemsSource="{Binding SelectedFolders}" BorderThickness="0" >      
                    <ListView.View>
                             <GridView>
                <GridViewColumn Header="Folder Name" Width="600">
                    <GridViewColumn.CellTemplate>
                        <DataTemplate>
                                 <TextBlock Text="{Binding FolderName}" FontSize="16" Foreground="Black" Margin="2,2" HorizontalAlignment="Left">
                                    <TextBlock.ToolTip>
                                        <TextBlock Text="{Binding FolderFullPath}"/>                        
                                    </TextBlock.ToolTip>                        
                                </TextBlock>                        
                        </DataTemplate>             
                    </GridViewColumn.CellTemplate>
                </GridViewColumn>           

                <GridViewColumn Header="Size" Width="70">
                      <GridViewColumn.CellTemplate>
                        <DataTemplate>
                                 <TextBlock Text="{Binding FolderSize}" FontSize="16" Foreground="Black" Margin="2,2"  HorizontalAlignment="Left">
                                    <TextBlock.ToolTip>
                                        <TextBlock Text="{Binding FolderFullPath}"/>                        
                                    </TextBlock.ToolTip>                        
                                </TextBlock>                        
                        </DataTemplate>             
                    </GridViewColumn.CellTemplate>            
                </GridViewColumn>
            </GridView>                   
            </ListView.View>   
  </ListView>

我正在尝试删除列分隔符但没有成功。 这就是它现在的样子:

ListView

在图片中,您可以看到尺寸列线, 我该如何删除它们?

2 个答案:

答案 0 :(得分:9)

只需创建自己的样式GridViewColumnHeader ...

这是一个简单的示例,除了TextBlock之外没有任何东西(当然,没有垂直线):

<Window.Resources>
    <Style x:Key="GridHeader" TargetType="{x:Type GridViewColumnHeader}">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type GridViewColumnHeader}">
                    <TextBlock Text="{TemplateBinding Content}" Padding="5" Width="{TemplateBinding Width}" TextAlignment="Right" />
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

</Window.Resources>

用法:

<ListView Height="Auto" MaxHeight="300" Margin="5,5,5,0" BorderBrush="Transparent"
          ItemsSource="{Binding ReferenceCollection}" BorderThickness="0">
        <ListView.View>
            <GridView ColumnHeaderContainerStyle="{StaticResource GridHeader}">
               ....

有关详细信息,请参阅GridView Column Header Styles and Templates Overview

答案 1 :(得分:0)

打开表达式混合并编辑GridViewColumnHeader样式。我是为你做的。

<LinearGradientBrush x:Key="GridViewColumnHeaderBackground" EndPoint="0,1" StartPoint="0,0">
        <GradientStop Color="#FFFFFFFF" Offset="0"/>
        <GradientStop Color="#FFFFFFFF" Offset="0.4091"/>
        <GradientStop Color="#FFF7F8F9" Offset="1"/>
    </LinearGradientBrush>
    <LinearGradientBrush x:Key="GridViewColumnHeaderBorderBackground" EndPoint="0,1" StartPoint="0,0">
        <GradientStop Color="#FFF2F2F2" Offset="0"/>
        <GradientStop Color="#FFD5D5D5" Offset="1"/>
    </LinearGradientBrush>
    <LinearGradientBrush x:Key="GridViewColumnHeaderHoverBackground" EndPoint="0,1" StartPoint="0,0">
        <GradientStop Color="#FFBDEDFF" Offset="0"/>
        <GradientStop Color="#FFB7E7FB" Offset="1"/>
    </LinearGradientBrush>
    <LinearGradientBrush x:Key="GridViewColumnHeaderPressBackground" EndPoint="0,1" StartPoint="0,0">
        <GradientStop Color="#FF8DD6F7" Offset="0"/>
        <GradientStop Color="#FF8AD1F5" Offset="1"/>
    </LinearGradientBrush>

    <Style TargetType="{x:Type GridViewColumnHeader}">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type GridViewColumnHeader}">
                    <Grid SnapsToDevicePixels="true">
                        <VisualStateManager.VisualStateGroups>
                            <VisualStateGroup x:Name="CommonStates"/>
                            <VisualStateGroup x:Name="FocusStates"/>
                            <VisualStateGroup x:Name="ValidationStates"/>
                        </VisualStateManager.VisualStateGroups>
                        <Border x:Name="HeaderBorder" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="0,1,0,1" Background="{TemplateBinding Background}">
                            <Grid>
                                <Grid.RowDefinitions>
                                    <RowDefinition MaxHeight="7"/>
                                    <RowDefinition/>
                                </Grid.RowDefinitions>
                                <Rectangle x:Name="UpperHighlight" Fill="#FFE3F7FF" Visibility="Collapsed"/>
                                <Border Padding="{TemplateBinding Padding}" Grid.RowSpan="2">
                                    <ContentPresenter x:Name="HeaderContent" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="0,0,0,1" RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
                                </Border>
                            </Grid>
                        </Border>
                        <Border x:Name="HeaderHoverBorder" BorderThickness="1,0,1,1" Margin="1,1,0,0"/>
                        <Border x:Name="HeaderPressBorder" BorderThickness="1,1,1,0" Margin="1,0,0,1"/>
                    </Grid>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsMouseOver" Value="true">
                            <Setter Property="Background" TargetName="HeaderBorder" Value="{StaticResource GridViewColumnHeaderHoverBackground}"/>
                            <Setter Property="BorderBrush" TargetName="HeaderHoverBorder" Value="#FF88CBEB"/>
                            <Setter Property="Visibility" TargetName="UpperHighlight" Value="Visible"/>
                        </Trigger>
                        <Trigger Property="IsPressed" Value="true">
                            <Setter Property="Background" TargetName="HeaderBorder" Value="{StaticResource GridViewColumnHeaderPressBackground}"/>
                            <Setter Property="BorderBrush" TargetName="HeaderHoverBorder" Value="#FF95DAF9"/>
                            <Setter Property="BorderBrush" TargetName="HeaderPressBorder" Value="#FF7A9EB1"/>
                            <Setter Property="Visibility" TargetName="UpperHighlight" Value="Visible"/>
                            <Setter Property="Fill" TargetName="UpperHighlight" Value="#FFBCE4F9"/>
                            <Setter Property="Margin" TargetName="HeaderContent" Value="1,1,0,0"/>
                        </Trigger>
                        <Trigger Property="Height" Value="Auto">
                            <Setter Property="MinHeight" Value="20"/>
                        </Trigger>
                        <Trigger Property="IsEnabled" Value="false">
                            <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/>
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
        <Style.Triggers>
            <Trigger Property="Role" Value="Floating">
                <Setter Property="Opacity" Value="0.4082"/>
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="{x:Type GridViewColumnHeader}">
                            <Canvas x:Name="PART_FloatingHeaderCanvas">
                                <Rectangle Fill="#FF000000" Height="{TemplateBinding ActualHeight}" Opacity="0.4697" Width="{TemplateBinding ActualWidth}"/>
                            </Canvas>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Trigger>
            <Trigger Property="Role" Value="Padding">
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="{x:Type GridViewColumnHeader}">
                            <Border x:Name="HeaderBorder" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="0,1,0,1" Background="{TemplateBinding Background}"/>
                            <ControlTemplate.Triggers>
                                <Trigger Property="Height" Value="Auto">
                                    <Setter Property="MinHeight" Value="20"/>
                                </Trigger>
                            </ControlTemplate.Triggers>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Trigger>
        </Style.Triggers>
    </Style>

如果需要,你可以用同样的方式修改它。