为什么ItemsPresenter重写我的数据表格的前景的风格?
-
24-09-2019 - |
题
我有一个网格式应用程序。键
<Style TargetType="{x:Type DataGrid}">
<Setter Property="Foreground" Value="{StaticResource DataGridItemTextBrush}" />
<Setter Property="VerticalGridLinesBrush" Value="{StaticResource GridBrush}" />
<Setter Property="HorizontalGridLinesBrush" Value="{StaticResource GridBrush}" />
<Setter Property="RowBackground" Value="Transparent" />
<Setter Property="Background" Value="Transparent" />
<Setter Property="HeadersVisibility" Value="Column" />
<Setter Property="AlternatingRowBackground" Value="#77000000" />
</Style>
这个伟大工程,对于我所有的数据表格在我的应用。然而,对于我的一个数据网格,我想我的组排如果具体列共同的价值观。所以我用下面的那特定数据表格:
<DataGrid.GroupStyle>
<GroupStyle>
<GroupStyle.HeaderTemplate>
<DataTemplate>
<StackPanel>
<TextBlock Text="{Binding Path=Name}" Padding="3"/>
</StackPanel>
</DataTemplate>
</GroupStyle.HeaderTemplate>
<GroupStyle.ContainerStyle>
<Style TargetType="{x:Type GroupItem}" >
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type GroupItem}">
<Expander>
<Expander.Resources>
<Style TargetType="{x:Type TextBlock}">
<Setter Property="Foreground" Value="White" />
</Style>
</Expander.Resources>
<Expander.Header>
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding Path=Name, StringFormat=Set: {0}}" Margin="5,0"/>
<TextBlock Text="{Binding Path=ItemCount, StringFormat=(\{0\} Games)}"/>
</StackPanel>
</Expander.Header>
<ItemsPresenter />
</Expander>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</GroupStyle.ContainerStyle>
</GroupStyle>
</DataGrid.GroupStyle>
问题: 现在这个数据表格显示一切正常根据我的网格式,但它显示文本(前)作为黑色的而不是我的风格。
方案: 我可以修复的问题(虽然我不明白这是为什么需要的话)通过修改我的ItemsPresenter到以下:
<ItemsPresenter TextElement.Foreground="{StaticResource DataGridItemTextBrush}"/>
或
<ItemsPresenter TextBlock.Foreground="{StaticResource DataGridItemTextBrush}" />
问题: 任何人都可以解释为什么发生这种情况,并/或提供一个更好的解决方案,这将保证我ItemsPresenter不复盖我的任何数据表格样式?
谢谢你!
解决方案
造型瀑布下,除非儿童选择替代实行风格。的 ItemsPresenter
在你的情况已经默认值;你是不是压倒一切的内你的 DataGrid
风格。无论是创建一个 ItemsPresenter
风格内 App.xaml
来满足你的需要或修改的价值在本地通过明确或隐含的风格,或者选择对于你的提议的解决方案。
还记得你可以使用 BasedOn
财产继承的默认造型;压倒一切只有某些特性。
BasedOn="{StaticResource {x:Type DataGrid}}"
不隶属于 StackOverflow