首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >MahApps DataGridCell风格

MahApps DataGridCell风格
EN

Stack Overflow用户
提问于 2016-04-07 21:14:59
回答 1查看 1.3K关注 0票数 3

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

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

所以我开始说:

代码语言:javascript
复制
<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>

但是没有什么变化,所以我假设我丢失了基于On={}属性,但我没有任何线索,我已经请求帮助MathApps团队,但没有帮助.

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-04-07 21:27:05

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

注意,它并没有为您提供外部边框,但它比编辑默认模板容易得多。

如果您确实希望获得外部边框,则需要重写默认模板。

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

票数 5
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/36487354

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档