当数据由扩展器分组时,数据网格的标题样式未标准化 [英] Header style of data grid is not standardize when the data is group by expander

查看:67
本文介绍了当数据由扩展器分组时,数据网格的标题样式未标准化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个我的数据网格标题的标准样式.

当数据网格中有数据并且我的数据按扩展器分组时,将为扩展器自动生成一个新列,并且新创建的列的样式不遵循我的数据网格样式.意思是第一列标题是灰色的,而其余的 列标题的颜色为蓝色(按照我的风格).

When there is data in the data grid, and my data is group by expander, a new column is auto generated for expander and the style of the newly created column is not following my data grid style. Meaning the first column header is in grey colour, while the rest of the column header is blue in colour (as follow my style).

有人知道为什么扩展器的列不符合我的风格吗?

Anyone has idea why the column of expander does not follow my style?

为了更好地理解图像,请查看以下链接:

For image for better understanding can look at this link:

http://stackoverflow.com/questions/35566674/header-style-of-data-grid-is-not-standardize-when-the-data-is-group-by-expander

http://stackoverflow.com/questions/35566674/header-style-of-data-grid-is-not-standardize-when-the-data-is-group-by-expander

这是我的代码:

DataGrid

<DataGrid ScrollViewer.HorizontalScrollBarVisibility="Auto" Name="dataGridResult"
              Grid.Row="1" RowHeight="20"  
              ItemsSource="{Binding ResultList, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
              BorderBrush="White" 
              IsReadOnly="True" 
              VirtualizingPanel.IsVirtualizingWhenGrouping="True"
              Margin="15"
              Style="{StaticResource DataGridStyle}"
              GridLinesVisibility="None">
        <DataGrid.Columns>
            <DataGridTextColumn Width="180" Header="Column1" Binding="{Binding RunNo}"/>
            <DataGridTextColumn Width="Auto" Header="Column2" Binding="{Binding TestProgramVersion}"/>
            <DataGridTextColumn Width="150" Header="Column3" Binding="{Binding StartTestTime}"/>
            <DataGridTextColumn Width="150" Header="Column4" Binding="{Binding EndTestTime}"/>
        </DataGrid.Columns>
        <DataGrid.GroupStyle>
            <GroupStyle>
                <GroupStyle.ContainerStyle>
                    <Style TargetType="{x:Type GroupItem}">
                        <Setter Property="Template">
                            <Setter.Value>
                                <ControlTemplate>
                                    <Expander x:Name="MyExpander" IsExpanded="True">
                                        <Expander.Header>
                                            <StackPanel Orientation="Horizontal">
                                                <TextBlock x:Name="MyExpanderHeader" Text="{Binding Name}" FontWeight="Bold" VerticalAlignment="Bottom"/>
                                            </StackPanel>
                                        </Expander.Header>
                                        <ItemsPresenter Margin="20,0,0,0"/>
                                    </Expander>
                                </ControlTemplate>
                            </Setter.Value>
                        </Setter>
                    </Style>
                </GroupStyle.ContainerStyle>
            </GroupStyle>
        </DataGrid.GroupStyle>
    </DataGrid>

风格

<Style x:Key="DataGridStyle" TargetType="DataGrid">
     <Setter Property="ColumnHeaderStyle" Value="{StaticResource DataGridColumnHeaderStyle}" />
</Style>

<Style x:Key="DataGridColumnHeaderStyle" TargetType="{x:Type DataGridColumnHeader}"  >
    <Setter Property="Foreground" Value="White" />
    <Setter Property="Background" Value="#FF048EC0"/>
    <Setter Property="Padding" Value="5,0,5,0"/>
    <Setter Property="HorizontalContentAlignment" Value="Left"/>
</Style>



推荐答案

一些能够轻松重现该问题的示例数据会很有帮助.

Some sample data to be able to easily reproduce the issue would have been helpful.

但是您可以尝试将DataGrid的HeadersVisibility列设置为Column以隐藏行选择器,如Stackoverflow上已建议的那样:

But you could try to set the HeadersVisibility column of the DataGrid to Column to hide the row selector as already suggested on Stackoverflow:

<Style x:Key="DataGridStyle" TargetType="DataGrid">
            <Setter Property="ColumnHeaderStyle" Value="{StaticResource DataGridColumnHeaderStyle}" />
            <Setter Property="HeadersVisibility" Value="Column"/>
            <Setter Property="RowHeaderWidth" Value="0"/>
        </Style>

您还可以尝试将RowHeaderWidth属性设置为0,以隐藏行选择器.

You could also try to set the RowHeaderWidth property to 0 to hide the row selector.

希望有帮助.

请记住,通过将有用的帖子标记为答案来关闭话题,然后在遇到新问题时开始新话题.请不要在同一线程中问几个问题.

Please remember to close your threads by marking helpful posts as answer and then start a new thread if you have a new question. Please don't ask several questions in the same thread.


这篇关于当数据由扩展器分组时,数据网格的标题样式未标准化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆