gpt4 book ai didi

wpf - WPF 的 GridView 有垂直边框吗?

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

有没有办法在 WPF GridView 上设置垂直边框?

以下适用于一些漂亮的水平边框。有没有一种好方法可以向位于此 ListView 内的 GridView 添加垂直边框?

<Style x:Key="ListViewItemBase" TargetType="{x:Type ListViewItem}">
<Setter Property="BorderThickness" Value="1" />
<Setter Property="BorderBrush" Value="#BABABE" />
</Style>

提前致谢

最佳答案

试试这个...来自 http://blogs.microsoft.co.il/blogs/tomershamam/archive/2007/12/16/wpf-listview-vertical-lines-horizontal-as-bonus.aspx

<ScrollContentPresenter x:Name="PART_ScrollContentPresenter"
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
ContentTemplate="{TemplateBinding ContentTemplate}"
KeyboardNavigation.DirectionalNavigation="Local"
CanContentScroll="{TemplateBinding CanContentScroll}">

<ScrollContentPresenter.Content>
<Grid>
<!-- Container of vertical and horizontal lines -->
<ItemsControl Margin="3,0,0,0"
ItemsSource="{Binding Path=TemplatedParent.View.Columns,
RelativeSource={RelativeSource TemplatedParent}}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<Border Width="{Binding Path=ActualWidth}"
BorderThickness="0,0,1,0"
BorderBrush="{DynamicResource verticalLineColor}" />
</DataTemplate>
</ItemsControl.ItemTemplate>
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>

<!-- Fill background with horizontal lines -->
<ItemsControl.Background>
<VisualBrush TileMode="Tile"
Stretch="None"
Viewport="{Binding Source={StaticResource columnHeight},
Converter={StaticResource columnViewportConverter}}"
ViewportUnits="Absolute">
<VisualBrush.Visual>
<StackPanel HorizontalAlignment="Stretch"
VerticalAlignment="Stretch">
<!-- Add Rectangles here for more horizontal lines -->
<Rectangle Height="{DynamicResource columnHeight}"
VerticalAlignment="Stretch"
Fill="{DynamicResource horizontalLineColor1}"
Width="1" />
<Rectangle Height="{DynamicResource columnHeight}"
VerticalAlignment="Stretch"
Fill="{DynamicResource horizontalLineColor2}"
Width="1" />
</StackPanel>
</VisualBrush.Visual>
</VisualBrush>
</ItemsControl.Background>
</ItemsControl>
<ContentControl Content="{TemplateBinding Content}" />
</Grid>
</ScrollContentPresenter.Content>
</ScrollContentPresenter>

关于wpf - WPF 的 GridView 有垂直边框吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1173455/

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