我在我的应用程序中使用 MahApps 库,datagrid 单元格的默认样式没有任何边框:
但我希望 DataGrid 看起来像这样:
所以我开始了:
<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
上控件本身会给你内部边界。
请注意,它仍然不会为您提供外部边框,但它比编辑默认模板容易得多。
如果你真的想获得外边框,那么你需要覆盖默认模板。
MahApps 默认的 DataGridCell 模板键是 MetroDataGridCell
, 所以你需要使用 <Style TargetType="{x:Type DataGridCell}" BasedOn="{StaticResource MetroDataGridCell}">
关于c# - MahApps DataGridCell 样式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36487354/