【问题标题】:Add row as group header in datagrid在数据网格中添加行作为组标题
【发布时间】:2011-03-25 11:23:59
【问题描述】:

我正在使用 wpf 工具包的数据网格,当属性 IsGroup 设置为 true 时,我想为它的所有列添加一行。我想使用数据触发器而不是 ivalueconverter。我已经用 ivalueconverter 完成了。 还有一件事是我不想使用数据网格的分组功能。只想在特定索引处添加行并将该行作为单列。所以看起来像组名

<my:DataGrid.RowStyle>
                <Style TargetType="{x:Type my:DataGridRow}">
                    <Setter Property="Background" Value="White" />                      
                    <Setter Property="Background" Value="{Binding IsGroup, Converter={StaticResource rowhighlighter}}" />
                    <!--<Style.Triggers>
                        <DataTrigger Binding="{Binding IsGroup,UpdateSourceTrigger=PropertyChanged}" Value="True">
                            <Setter Property="Background" Value="YellowGreen"/>
                        </DataTrigger>
                    </Style.Triggers>-->
                </Style>
            </my:DataGrid.RowStyle>

这种风格的数据触发器在我错的地方不适合我。

【问题讨论】:

    标签: wpf


    【解决方案1】:

    您的问题是您想添加一行作为组标题。但是在您的问题的描述中,您声明您不想使用数据网格的分组功能。你能否详细说明你想要做什么,以及为什么你认为你不应该使用分组功能。 您所说的分组功能是指在某些列上展开折叠行的能力吗? 您可以在数据网格中声明 GroupStyle:

    结合

    <CollectionViewSource.GroupDescriptions>
                        <PropertyGroupDescription PropertyName="Parent"/>
                    </CollectionViewSource.GroupDescriptions>
    

    除了 msdn 提供的关于此主题的内容,例如 introduction WPF
    我发现这个博客有助于了解数据网格: smoura's WPF blog

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-04-14
      • 2021-09-23
      • 2011-04-02
      • 1970-01-01
      • 2016-05-19
      • 1970-01-01
      相关资源
      最近更新 更多