• WPF 视图分组排序


    视图分组排序

    效果:

    实现步骤:

    第一步:为分组做一个标题头,就是效果图中的浅蓝色部分:

    <DataGrid.GroupStyle>标签部分:

    <DataGrid x:Name="dgDataPiontInformation" AutoGenerateColumns="False" CanUserAddRows="False" CanUserDeleteRows="False" IsReadOnly="True">
                   <DataGrid.GroupStyle>
                       <GroupStyle>
                           <GroupStyle.HeaderTemplate>
                                <DataTemplate>
                                    <TextBlock Text="{Binding Path=Name}" Foreground="White"
                                               FontWeight="Bold" Background="LightSkyBlue" HorizontalAlignment="Left"
                                               Margin="0,5,0,0" MaxWidth="100" Height="30"/>
                                </DataTemplate>
                           </GroupStyle.HeaderTemplate>
                       </GroupStyle>
                   </DataGrid.GroupStyle>
                    <DataGrid.Columns>
                               。。。。。
                    </DataGrid.Columns>
                </DataGrid>

    特别提醒:

            Text="{Binding Path=Name}" 

    指的是绑定PropertyGroupDescription的Name属性,而不是绑定的数据对象中的属性。

         


    第二步:cs代码:

                    this.dgDataPiontInformation.ItemsSource = getAllDataPointsInfoResponse.DataPointInfoViews;
                   
                    //排序
                    ICollectionView sortView = CollectionViewSource.GetDefaultView(this.dgDataPiontInformation.ItemsSource);
                    sortView.SortDescriptions.Add(
    new SortDescription("Number", ListSortDirection.Descending));

    //分组
                    ICollectionView view = CollectionViewSource.GetDefaultView(this.dgDataPiontInformation.ItemsSource);
                    view.GroupDescriptions.Add(
    new PropertyGroupDescription("Number"));

    【The End】

  • 相关阅读:
    锚点
    autoLayout
    基础动画
    核心动画
    get和post的区别
    block的定义及使用
    传值-自定义构造函数传值
    字符串
    字典与可变字典
    RabbitMQ的可视化界面进行操作
  • 原文地址:https://www.cnblogs.com/easy5weikai/p/3270373.html
Copyright © 2020-2023  润新知