gpt4 book ai didi

c# - MahApps DataGridCell 样式

转载 作者:行者123 更新时间:2023-11-30 20:37:00 25 4
gpt4 key购买 nike

我在我的应用程序中使用 MahApps 库,datagrid 单元格的默认样式没有任何边框:

Data Grid Cells without borders

但我希望 DataGrid 看起来像这样:

Data Grid Cells wit borders

所以我开始了:

<Style TargetType="{x:Type DataGridCell}">
<Setter Property="Height"
Value="33" />
<Setter Property="Background"
Value="Transparent" />
<Setter Property="Padding"
Value="5,0" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type DataGridCell}">
<Border x:Name="border"
Background="Transparent"
BorderBrush="Black"
BorderThickness="1"
Padding="0,10,0,10"
SnapsToDevicePixels="True">
<ContentPresenter SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type DataGridCell}">
<Grid Background="{TemplateBinding Background}">
<ContentPresenter VerticalAlignment="Center" />
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>

但没有任何变化,所以我假设我缺少 Based On={} 属性但我不知道,我已经向 MathApps 团队寻求帮助但没有帮助......

最佳答案

设置GridLinesVisibility="All"DataGrid 上控件本身会给你内部边界。

enter image description here

请注意,它仍然不会为您提供外部边框,但它比编辑默认模板容易得多。

如果你真的想获得外边框,那么你需要覆盖默认模板。

MahApps 默认的 DataGridCell 模板键是 MetroDataGridCell , 所以你需要使用 <Style TargetType="{x:Type DataGridCell}" BasedOn="{StaticResource MetroDataGridCell}">

关于c# - MahApps DataGridCell 样式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36487354/

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