2013-01-15 398 views
1

我創造了未來的ListView刪除分隔符 - WPF

<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

在你可以看到大小列線的圖片, 我怎樣才能刪除它們?

回答

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> 

如果需要,您可以用同樣的方法修改它。

7

剛剛創建自己的風格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