【问题标题】:Cannot align text content of column to center无法将列的文本内容对齐到中心
【发布时间】:2016-09-06 09:11:23
【问题描述】:

我想将列内的文本居中对齐,为此我创建了一个资源:

<Style x:Key="HeaderStyle" TargetType="GridViewColumnHeader" BasedOn="{StaticResource MetroGridViewColumn}">
        <Setter Property="HorizontalContentAlignment" Value="Center"/>
</Style>

但我明白了

无法解析资源“MetroGridViewColumn”

注意:我需要对齐列内的文本,而不是没有丢失 Mahapp 样式的标题

【问题讨论】:

    标签: wpf xaml mahapps.metro


    【解决方案1】:

    样式的关键是MetroGridViewColumnHeader,可以在Controls.ListView.xaml找到。

    <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Controls.ListView.xaml" />
    

    所以你的自定义样式应该是这样的

    <Style x:Key="HeaderStyle" TargetType="GridViewColumnHeader" BasedOn="{StaticResource MetroGridViewColumnHeader}">
        <Setter Property="HorizontalContentAlignment" Value="Center"/>
    </Style>
    

    【讨论】:

    • @AgainMe 没错,因为它是针对 GridViewColumnHeader 的。如果要更改单元格内容,必须为 GridViewColumn 创建自己的 CellTemplate。
    猜你喜欢
    • 1970-01-01
    • 2018-09-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-03-01
    • 1970-01-01
    相关资源
    最近更新 更多