简体   繁体   中英

How do I remove the borders separating the headers in a Listview in XAML (WPF)?

I am making a ListView which loads users in from an Active Directory. To accomplish the brand/styling of the company I am developing the application for I would like to tweak some of the styling of the ListView element.

I have made it so the border of the headers in the Listview are transparent. In the editor in Visual Studio it looks how I want it to be, but when I look at the headers in the ListView in runtime I still get to see borders separating the headers (See image below). https://i.gyazo.com/99dc8d60d6c5b2e1761456df685d850f.png

I have already tried Googling and I even went to the second page of the Google search result. Can you imagine?

Down here is the style I have used for the headers in my XAML file

<Style x:Key="ListViewHeaderStyle" TargetType="{x:Type GridViewColumnHeader}">
    <Setter Property="Background" Value="Transparent"></Setter>
    <Setter Property="BorderBrush" Value="Transparent"></Setter>
    <Setter Property="IsHitTestVisible" Value="False"></Setter>
</Style>

What I want is to remove those borders separating the headers in my ListView element.

You can override the template of the GridViewColumnHeader

<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>
  <ListView.View>
    <GridView ColumnHeaderContainerStyle="{StaticResource GridHeader}">
  </ListView.View>
</ListView>

Solution taken form here: Remove Separators in ListView Columns - WPF

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM