gpt4 book ai didi

wpf - 在 WPF ListView 标题中隐藏列之间的垂直线

转载 作者:行者123 更新时间:2023-12-04 15:15:19 28 4
gpt4 key购买 nike

如何隐藏 WPF ListView 标题中列之间的垂直线?

举例说明:默认情况下,它看起来像顶部的图片;我希望它看起来像底部的图片。


(来源:excastle.com)

最佳答案

不幸的是,没有一个简单的属性可以设置,您必须重新设置 GridViewColumnHeader 的样式。如果您在应用程序或窗口资源中包含以下内容,那么它将完成您想要的 Aero 主题:

<LinearGradientBrush x:Key="GridViewColumnHeaderBorderBackground"
StartPoint="0,0"
EndPoint="0,1">
<LinearGradientBrush.GradientStops>
<GradientStop Color="#FFF2F2F2"
Offset="0" />
<GradientStop Color="#FFD5D5D5"
Offset="1" />
</LinearGradientBrush.GradientStops>
</LinearGradientBrush>

<LinearGradientBrush x:Key="GridViewColumnHeaderBackground"
StartPoint="0,0"
EndPoint="0,1">
<LinearGradientBrush.GradientStops>
<GradientStop Color="#FFFFFFFF"
Offset="0" />
<GradientStop Color="#FFFFFFFF"
Offset="0.4091" />
<GradientStop Color="#FFF7F8F9"
Offset="1" />
</LinearGradientBrush.GradientStops>
</LinearGradientBrush>

<LinearGradientBrush x:Key="GridViewColumnHeaderHoverBackground"
StartPoint="0,0"
EndPoint="0,1">
<LinearGradientBrush.GradientStops>
<GradientStop Color="#FFBDEDFF"
Offset="0" />
<GradientStop Color="#FFB7E7FB"
Offset="1" />
</LinearGradientBrush.GradientStops>
</LinearGradientBrush>

<LinearGradientBrush x:Key="GridViewColumnHeaderPressBackground"
StartPoint="0,0"
EndPoint="0,1">
<LinearGradientBrush.GradientStops>
<GradientStop Color="#FF8DD6F7"
Offset="0" />
<GradientStop Color="#FF8AD1F5"
Offset="1" />
</LinearGradientBrush.GradientStops>
</LinearGradientBrush>

<Style x:Key="GridViewColumnHeaderGripper"
TargetType="{x:Type Thumb}">
<Setter Property="Canvas.Right"
Value="-9" />
<Setter Property="Width"
Value="18" />
<Setter Property="Height"
Value="{Binding Path=ActualHeight,RelativeSource={RelativeSource TemplatedParent}}" />
<Setter Property="Padding"
Value="0" />
<Setter Property="Background"
Value="Transparent" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Thumb}">
<Border Padding="{TemplateBinding Padding}"
Background="Transparent">
<Rectangle HorizontalAlignment="Center"
Width="1"
Fill="{TemplateBinding Background}" />
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>

<Style x:Key="{x:Type GridViewColumnHeader}"
TargetType="{x:Type GridViewColumnHeader}">
<Setter Property="HorizontalContentAlignment"
Value="Center" />
<Setter Property="VerticalContentAlignment"
Value="Center" />
<Setter Property="Background"
Value="{StaticResource GridViewColumnHeaderBackground}" />
<Setter Property="BorderBrush"
Value="{StaticResource GridViewColumnHeaderBorderBackground}" />
<Setter Property="BorderThickness"
Value="0" />
<Setter Property="Padding"
Value="2,0,2,0" />
<Setter Property="Foreground"
Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type GridViewColumnHeader}">
<Grid SnapsToDevicePixels="true">
<Border Name="HeaderBorder"
BorderThickness="0,1,0,1"
BorderBrush="{TemplateBinding BorderBrush}"
Background="{TemplateBinding Background}">
<Grid>
<Grid.RowDefinitions>
<RowDefinition MaxHeight="7" />
<RowDefinition />
</Grid.RowDefinitions>
<Rectangle Name="UpperHighlight"
Visibility="Collapsed"
Fill="#FFE3F7FF" />
<Border Grid.RowSpan="2"
Padding="{TemplateBinding Padding}">
<ContentPresenter Name="HeaderContent"
Margin="0,0,0,1"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
RecognizesAccessKey="True"
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
</Border>
</Grid>
</Border>
<Border Name="HeaderHoverBorder"
BorderThickness="1,0,1,1"
Margin="1,1,0,0" />
<Border Name="HeaderPressBorder"
BorderThickness="1,1,1,0"
Margin="1,0,0,1" />
<Canvas>
<Thumb x:Name="PART_HeaderGripper"
Style="{StaticResource GridViewColumnHeaderGripper}" />
</Canvas>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver"
Value="true">
<Setter TargetName="HeaderBorder"
Property="Background"
Value="{StaticResource GridViewColumnHeaderHoverBackground}" />
<Setter TargetName="HeaderHoverBorder"
Property="BorderBrush"
Value="#FF88CBEB" />
<Setter TargetName="UpperHighlight"
Property="Visibility"
Value="Visible" />
<Setter TargetName="PART_HeaderGripper"
Property="Background"
Value="Transparent" />
</Trigger>
<Trigger Property="IsPressed"
Value="true">
<Setter TargetName="HeaderBorder"
Property="Background"
Value="{StaticResource GridViewColumnHeaderPressBackground}" />
<Setter TargetName="HeaderHoverBorder"
Property="BorderBrush"
Value="#FF95DAF9" />
<Setter TargetName="HeaderPressBorder"
Property="BorderBrush"
Value="#FF7A9EB1" />
<Setter TargetName="UpperHighlight"
Property="Visibility"
Value="Visible" />
<Setter TargetName="UpperHighlight"
Property="Fill"
Value="#FFBCE4F9" />
<Setter TargetName="PART_HeaderGripper"
Property="Visibility"
Value="Hidden" />
<Setter TargetName="HeaderContent"
Property="Margin"
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 Name="PART_FloatingHeaderCanvas">
<Rectangle Opacity="0.4697"
Fill="#FF000000"
Width="{TemplateBinding ActualWidth}"
Height="{TemplateBinding ActualHeight}" />
</Canvas>
</ControlTemplate>
</Setter.Value>
</Setter>
</Trigger>
<Trigger Property="Role"
Value="Padding">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type GridViewColumnHeader}">
<Border Name="HeaderBorder"
BorderThickness="0,1,0,1"
BorderBrush="{TemplateBinding BorderBrush}"
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>

该样式是从 Microsoft 提供的默认系统样式复制而来的,并更改了一行(GridViewColumnHeaderGripper 样式中的 Background 属性设置)。

关于wpf - 在 WPF ListView 标题中隐藏列之间的垂直线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5642550/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com