C# 全局样式-WPF

C# 全局样式-WPF,c#,wpf,mahapps.metro,C#,Wpf,Mahapps.metro,我正在尝试应用样式,但我遇到了一个问题。我有这种全局样式(请注意,我使用的是MahApps)                                                                                                                                                  它所做的是将单元格的内容集中在数据网格中。那很好用。问题是当我想在窗口的.xaml中嵌套另一个样式时 <D

我正在尝试应用样式,但我遇到了一个问题。我有这种全局样式(请注意,我使用的是MahApps)


        
            
                
                    
                        
                    
                
            
        
它所做的是将单元格的内容集中在数据网格中。那很好用。问题是当我想在窗口的.xaml中嵌套另一个样式时

<DataGridTextColumn Header="Date" Binding="{Binding Date, Converter={StaticResource DefaultDateTimeToHyphenStyle}, UpdateSourceTrigger=PropertyChanged}">
    <DataGridTextColumn.CellStyle>
        <Style TargetType="{x:Type DataGridCell}"
               BasedOn="{StaticResource MetroDataGridCell}">
            <Setter Property="Foreground" Value="{Binding Path=., Converter={StaticResource CellForegroundColorDateConverter}}" />
        </Style>
    </DataGridTextColumn.CellStyle>
</DataGridTextColumn>


如果应用该样式,全局样式(在该单元格中)将停止工作。将文本向左对齐。怎么了?谢谢。

据我所知,在WPF中,对于任何特定元素,只能应用一种样式。

发生这种情况是因为您从{StaticResource MetroDataGridCell}继承了您的样式
将其更改为{StaticResource{x:Type DataGridCell}},它应该可以工作。

尝试此BasedOn=“{StaticResource{x:Type DataGridCell}”。由于您是从MetroDataGridCell派生样式的,全局样式将被忽略。@AyyappanSubramanian thx用于回复,但不起作用:(给出全局样式的键,并基于此执行。@AyyappanSubramanian Wait!:)如果它起作用,我正在查看另一个屏幕O.O.非常感谢!
<DataGridTextColumn Header="Date" Binding="{Binding Date, Converter={StaticResource DefaultDateTimeToHyphenStyle}, UpdateSourceTrigger=PropertyChanged}">
    <DataGridTextColumn.CellStyle>
        <Style TargetType="{x:Type DataGridCell}"
               BasedOn="{StaticResource MetroDataGridCell}">
            <Setter Property="Foreground" Value="{Binding Path=., Converter={StaticResource CellForegroundColorDateConverter}}" />
        </Style>
    </DataGridTextColumn.CellStyle>
</DataGridTextColumn>