【问题标题】:Apply Styles to DataGridTextColumn with MahApps Metro使用 MahApps Metro 将样式应用于 DataGridTextColumn
【发布时间】:2016-09-08 06:55:51
【问题描述】:

我刚刚尝试在我的 WPF 应用程序中使用以下 XAML。

<DataGridTextColumn Header="Due" Binding="{Binding QTYDue, Mode=OneWay}">
    <DataGridTextColumn.CellStyle>
        <Style>
            <Setter Property="FrameworkElement.HorizontalAlignment" Value="Center" />
        </Style>
    </DataGridTextColumn.CellStyle>
</DataGridTextColumn>

不幸的是,MahApps Metro 中控件的先前样式已被删除。我如何保持现有的样式,而只是修改它的这一方面。

【问题讨论】:

  • 你试过
  • 是的,但之后我不确定如何让 DataGridTextColumn 中定义的样式匹配。尝试了许多不同的方法来引用 MahApps.Metro.Controls 资源中的样式,但还没有弄清楚。

标签: c# wpf xaml mahapps.metro


【解决方案1】:

试试这个:

风格:

<Style x:Key="DatagridCellStyle1" 
       TargetType="{x:Type DataGridCell}" 
       BasedOn="{StaticResource {x:Type DataGridCell}}">
    <Setter Property="HorizontalAlignment" Value="Center" />
</Style>

XAML:

        <DataGridTextColumn Header="DUE" 
                            Binding="{Binding QTYDue}" 
                            CellStyle="{StaticResource DatagridCellStyle1}" />

或

            <DataGridTemplateColumn Header="DUE">
                <DataGridTemplateColumn.CellTemplate>
                    <DataTemplate>
                        <DataGridCell Style="{StaticResource DatagridCellStyle1}">
                            <TextBlock Text="{Binding QTYDue}"></TextBlock>
                        </DataGridCell>
                    </DataTemplate>
                </DataGridTemplateColumn.CellTemplate>
            </DataGridTemplateColumn>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-02-27
    • 1970-01-01
    相关资源
    最近更新 更多