使用MahApps Metro将样式应用于DataGridTextColumn

时间:2016-09-07 18:19:51

标签: c# wpf xaml mahapps.metro

我刚尝试在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中控件的先前样式。如何保留现有样式,只需修改它的这一方面。

WPF Behavior

1 个答案:

答案 0 :(得分:2)

试试这个:

<强>样式:

<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}" />

OR

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

enter image description here