摆脱xaml中GridViewColumnHeader末尾的白线
到目前为止,我在 GridViewColumnHeaders 方面遇到了几个问题。最初,我遇到了一个问题,即每个列标题之间都有一小片白色。即使我们将 borderthickness 设置为 0,白线仍然存在。环顾四周后,我发现我必须使用 ControlTemplate 将标题更改为默认具有文本框属性。我使用了这段代码:
<Style x:Key="gridHeaderStyle" TargetType="{x:Type GridViewColumnHeader}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type GridViewColumnHeader}">
<TextBox Text="{TemplateBinding Content}"
FontWeight="Bold"
FontFamily="Arial"
FontSize="11"
Foreground="#00648D"
Padding="5,0,5,0"
BorderBrush="#7EB0CC"
BorderThickness="0,0,2,2"
HorizontalContentAlignment="Center"
VerticalContentAlignment="Center"
IsReadOnly="True"
Background="Transparent"/>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
这有效并删除了标题列之间的白色小条,它还阻止用户移动和调整列的大小,这会弄乱格式,所以这很好。但是,在 gridviewcolumnheader 的最末端仍然有一点白色,如下图所示:
有没有办法删除它?
I've had several problems with the GridViewColumnHeaders so far. Originally I had a issue with there being a tiny sliver of white between each of the column headers. Even if we set the borderthickness to 0, the white lines would still exist. After looking around, I found that I had to use a ControlTemplate to change the header to default to having textbox attributes. I used this code:
<Style x:Key="gridHeaderStyle" TargetType="{x:Type GridViewColumnHeader}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type GridViewColumnHeader}">
<TextBox Text="{TemplateBinding Content}"
FontWeight="Bold"
FontFamily="Arial"
FontSize="11"
Foreground="#00648D"
Padding="5,0,5,0"
BorderBrush="#7EB0CC"
BorderThickness="0,0,2,2"
HorizontalContentAlignment="Center"
VerticalContentAlignment="Center"
IsReadOnly="True"
Background="Transparent"/>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
This worked and removed the little sliver of white between the header columns and it also prevented the user from moving and resizing the column which messed up the formatting so that was good. However there is still a little sliver of white at the very end of the gridviewcolumnheader as shown in the image below:
Is there a way to remove that too?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
该空白是您抓取并调整标题大小的对象。我相信即使您重写标题模板它也存在,因为它是 GridView 模板的一部分,而不是标题列
我不确定是否有办法覆盖这些颜色而不覆盖整个 GridView 模板,但是您可以导航加载视觉树后,从那里手动设置背景颜色。
以下是使用 ListView 的
Loaded
事件和一些 可视化树助手结果
如果您想覆盖 ListView 的 ControlTemplate,可以找到默认的 XAML 这里
That whitespace is the object you grab and resize the Header with. I believe it exists even if you re-write the header template because it is part of the GridView template, not the header column
I'm not sure if there's a way to overwrite those colors without overwriting the entire GridView template, however you can navigate the Visual Tree once it's loaded and manually set the background color from there.
Here's an example using the
Loaded
event of the ListView and some Visual Tree HelpersResult
If you would rather to overwrite the ListView's ControlTemplate, you can find the default XAML here