繁体   English   中英

MahApps DataGridCell样式

[英]MahApps DataGridCell style

我在我的应用程序中使用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>

但没有任何变化,因此我假设我缺少基于[=}属性,但是我不知道如何,我已经寻求帮助MathApps团队,但没有帮助...

DataGrid控件本身上设置GridLinesVisibility="All"将为您提供内部边框。

在此处输入图片说明

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

如果您确实想获得外部边界,则需要覆盖默认模板。

MahApps的默认DataGridCell模板密钥是MetroDataGridCell ,因此您需要使用<Style TargetType="{x:Type DataGridCell}" BasedOn="{StaticResource MetroDataGridCell}">

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM