WPF Expander按GroupItem排序

时间:2014-11-26 21:22:14

标签: c# wpf xaml

我有一个带搜索功能的WPF应用程序,数据绑定到数据网格。我按表名对数据进行分组。我怎么能按降序排序扩展器头。如何在最上面显示最大计数组。

XAML代码。

                                                                                     

</DataGrid.Columns>
<DataGrid.GroupStyle>
    <!--Default GroupStyle-->
    <GroupStyle>
        <GroupStyle.Panel>
            <ItemsPanelTemplate>
                <DataGridRowsPresenter/>
            </ItemsPanelTemplate>
        </GroupStyle.Panel>
        <GroupStyle.HeaderTemplate>
            <DataTemplate>
                <StackPanel>
                    <TextBlock Text="{Binding Path=Name}" FontWeight="Bold" Padding="3"/>
                </StackPanel>
            </DataTemplate>
        </GroupStyle.HeaderTemplate>
        <GroupStyle.ContainerStyle>
            <Style TargetType="{x:Type GroupItem}">
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="{x:Type GroupItem}">
                            <Expander x:Name="exp"
                            BorderBrush="#FFA4B97F" 
                            BorderThickness="0,0,0,1" 
                            IsExpanded="{Binding Path=Items[0].IsExpanded}">
                                <Expander.Header>
                                    <DockPanel TextBlock.FontWeight="Bold">
                                        <TextBlock Text="{Binding Name}" Margin="5,0,5,0" Foreground="Blue" />                                          
                                        <TextBlock Text="  (" />
                                        <TextBlock Text="{Binding Path=ItemCount}"/>
                                        <TextBlock Text=" Items )" />                                                  
                                    </DockPanel>
                                </Expander.Header>
                                <ItemsPresenter/>
                            </Expander>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>
        </GroupStyle.ContainerStyle>
    </GroupStyle>
</DataGrid.GroupStyle>

enter image description here

1 个答案:

答案 0 :(得分:0)

在ViewModel中对数据绑定列表进行排序。填充列表后按项目计数。