Statistical query group and sort results

This sample demonstrates how to query a feature table to get statistics for a specified field and to group and sort the results.

Query for statistics on a feature table

Code

<UserControl x:Class="ArcGISRuntime.WPF.Samples.StatsQueryGroupAndSort.StatsQueryGroupAndSort"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <Grid HorizontalAlignment="Center" VerticalAlignment="Center"
          MinWidth="250" MaxWidth="800"
          MinHeight="300" MaxHeight="800">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="50"/>
            <ColumnDefinition Width="*"/>
            <ColumnDefinition Width="40"/>
            <ColumnDefinition Width="*"/>
            <ColumnDefinition Width="50"/>
            <ColumnDefinition Width="300"/>
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="30"/>
            <RowDefinition Height="30"/>
            <RowDefinition Height="*"/>
            <RowDefinition Height="30"/>
            <RowDefinition Height="30"/>
            <RowDefinition Height="*"/>
            <RowDefinition Height="30"/>
            <RowDefinition Height="50"/>
        </Grid.RowDefinitions>
        <Border Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="5" Grid.RowSpan="4"
                BorderBrush="Black" BorderThickness="2"/>
        <TextBlock Grid.Row="0" Grid.Column="1" Grid.ColumnSpan="3"
                   HorizontalAlignment="Center" VerticalAlignment="Center"
                   TextDecorations="Underline"
                   Text="Statistics: US States"/>
        <TextBlock Grid.Row="1" 
                   HorizontalAlignment="Right" VerticalAlignment="Center"
                   Text="Field:"/>
        <ComboBox x:Name="FieldsComboBox" 
                  Grid.Row="1" Grid.Column="1"
                  Margin="5,5">
            <ComboBox.ItemTemplate>
                <DataTemplate>
                    <TextBlock Text="{Binding Name}"/>
                </DataTemplate>
            </ComboBox.ItemTemplate>
        </ComboBox>
        <TextBlock Grid.Row="1" Grid.Column="2"
                   HorizontalAlignment="Right" VerticalAlignment="Center"
                   Text="Type:"/>
        <ComboBox x:Name="StatTypeComboBox" 
                  Grid.Row="1" Grid.Column="3"
                  Margin="5,5"/>
        <Button x:Name="AddStatisticButton"
                Grid.Row="1" Grid.Column="4"
                Margin="10,5"
                Content="Add"
                Click="AddStatisticClicked"/>
        <ListBox x:Name="StatFieldsListBox"
                 Grid.Row="2" Grid.ColumnSpan="5"
                 Margin="25,5"
                 MinHeight="120">
            <ListBox.ItemTemplate>
                <DataTemplate>
                    <TextBlock>
                        <Run Text="{Binding OnFieldName}"/>
                        <Run Text=" ("/>
                        <Run Text="{Binding StatisticType}"/>
                        <Run Text=")"/>
                    </TextBlock>
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>
        <Button x:Name="RemoveStatField"
                Grid.Row="3" Grid.Column="3"
                HorizontalAlignment="Stretch" VerticalAlignment="Top"
                Content="Remove Statistic" 
                Height="20"
                Click="RemoveStatisticClicked"/>
        <TextBlock Text="Group Field(s):"
                   Grid.Row="4"
                   HorizontalAlignment="Center" VerticalAlignment="Center"
                   Margin="6,7,33,7" Grid.Column="1" Height="16" Width="76"/>
        <ListBox x:Name="GroupFieldsListBox"
                 Grid.Row="5" Grid.ColumnSpan="2"
                 MinWidth="110"
                 HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
                 Margin="25,0,0,0">
            <ListBox.ItemTemplate>
                <DataTemplate>
                    <StackPanel Orientation="Horizontal">
                        <CheckBox Tag="{Binding Name}"
                                  Margin="5,0" 
                                  Checked="GroupFieldCheckChanged" Unchecked="GroupFieldCheckChanged"/>
                        <TextBlock Text="{Binding Name}"/>
                    </StackPanel>
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>
        <StackPanel Orientation="Vertical"
                    Grid.Row="5" Grid.Column="2"
                    HorizontalAlignment="Center" VerticalAlignment="Center"
                    Margin="5">
            <Button Content="&gt;&gt;"
                    Margin="0,0,0,5"
                    Click="AddSortFieldClicked"/>
            <Button Content="&lt;&lt;"
                    Click="RemoveSortFieldClicked"/>
        </StackPanel>
        <TextBlock Text="Order by Field(s):"
                   Grid.Row="4" Grid.Column="3"
                   HorizontalAlignment="Center" VerticalAlignment="Center"
                   Margin="39,7,10,7" Height="16" Width="66"/>
        <ListBox x:Name="OrderByFieldsListBox"
                 Grid.Row="5" Grid.Column="3" Grid.ColumnSpan="2"
                 HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
                 MinWidth="300"
                 Margin="0,0,25,0">
            <ListBox.ItemTemplate>
                <DataTemplate>
                    <StackPanel Orientation="Horizontal">
                        <TextBlock>
                            <Run Text="{Binding FieldName}"/>
                            <Run Text=" ("/>
                            <Run Text="{Binding SortOrder}"/>
                            <Run Text=")"/>
                        </TextBlock>
                    </StackPanel>
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>
        <Button x:Name="SortOrderButton"
                Grid.Row="6" Grid.Column="3" Grid.ColumnSpan="2"
                HorizontalAlignment="Center" VerticalAlignment="Top"
                Margin="0,5,25,0"
                Padding="5,0"
                Content="Change sort order"
                Click="ChangeFieldSortOrder"/>
        <Button x:Name="GetStatisticsButton"
                Grid.Row="7" Grid.Column="0" Grid.ColumnSpan="5"
                HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
                Padding="10,0" Margin="25,10"
                Content="Get Statistics"
                Click="OnExecuteStatisticsQueryClicked"/>
        <ScrollViewer Grid.Row="0" Grid.Column="5" Grid.RowSpan="8"
                      Margin="20,0,0,0">
            <TreeView x:Name="ResultsTreeView">
                <TreeView.ItemTemplate>
                    <HierarchicalDataTemplate  ItemsSource="{Binding}">
                        <TextBlock Text="{Binding Key}" />
                        <HierarchicalDataTemplate.ItemTemplate>
                            <DataTemplate>
                                <ItemsControl ItemsSource="{Binding}"
                                                  Grid.Column="1">
                                    <ItemsControl.ItemTemplate>
                                        <DataTemplate>
                                            <Grid>
                                                <Grid.ColumnDefinitions>
                                                    <ColumnDefinition />
                                                    <ColumnDefinition />
                                                </Grid.ColumnDefinitions>
                                                <TextBlock Text="{Binding Key, StringFormat={}{0} :}" />
                                                <TextBlock Text="{Binding Value, StringFormat={} {0}}"
                                                               Grid.Column="1" />
                                            </Grid>
                                        </DataTemplate>
                                    </ItemsControl.ItemTemplate>
                                </ItemsControl>
                            </DataTemplate>
                        </HierarchicalDataTemplate.ItemTemplate>
                    </HierarchicalDataTemplate>
                </TreeView.ItemTemplate>
            </TreeView>
        </ScrollViewer>
    </Grid>
</UserControl>


In this topic
  1. Code