ArcGIS Runtime SDK for .NET Samples

Statistical query group and sort results

Query for statistics on a feature table
Loading

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"
             xmlns:esri="http://schemas.esri.com/arcgis/runtime/2013">
    <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="Auto" />
            <RowDefinition Height="30" />
            <RowDefinition Height="30" />
            <RowDefinition Height="*" />
            <RowDefinition Height="30" />
            <RowDefinition Height="30" />
            <RowDefinition Height="*" />
            <RowDefinition Height="30" />
            <RowDefinition Height="50" />
        </Grid.RowDefinitions>
        <TextBlock Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="6"
                   Text="In the statistics window, add and remove statistics (for example, average number of children under 5 per state) to calculate. Then, select from fields to group by (for example, subregion) and sort by. Tap 'Get statistics' to see the results."
                   Foreground="Red" TextAlignment="Left" TextWrapping="Wrap" Margin="0,5,0,5" />
        <Border Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="5" Grid.RowSpan="4"
                BorderBrush="Black" BorderThickness="2" />
        <TextBlock Grid.Row="1" Grid.Column="1" Grid.ColumnSpan="3"
                   HorizontalAlignment="Center" VerticalAlignment="Center"
                   TextDecorations="Underline"
                   Text="Statistics: US States" />
        <TextBlock Text="Field:"
                   Grid.Row="2" Grid.Column="0"
                   HorizontalAlignment="Right" VerticalAlignment="Center" />
        <ComboBox x:Name="FieldsComboBox"
                  Grid.Row="2" Grid.Column="1"
                  Margin="5,5">
            <ComboBox.ItemTemplate>
                <DataTemplate DataType="{x:Type esri:Field}">
                    <TextBlock Text="{Binding Name}" />
                </DataTemplate>
            </ComboBox.ItemTemplate>
        </ComboBox>
        <TextBlock Grid.Row="2" Grid.Column="2"
                   HorizontalAlignment="Right" VerticalAlignment="Center"
                   Text="Type:" />
        <ComboBox x:Name="StatTypeComboBox"
                  Grid.Row="2" Grid.Column="3"
                  Margin="5,5" />
        <Button x:Name="AddStatisticButton"
                Grid.Row="2" Grid.Column="4"
                Margin="10,5"
                Content="Add"
                Click="AddStatisticClicked" />
        <ListBox x:Name="StatFieldsListBox"
                 Grid.Row="3" Grid.Column="0" Grid.ColumnSpan="5"
                 Margin="25,5"
                 MinHeight="120">
            <ListBox.ItemTemplate>
                <DataTemplate DataType="{x:Type esri:StatisticDefinition}">
                    <TextBlock>
                        <Run Text="{Binding OnFieldName}" />
                        <Run Text=" (" />
                        <Run Text="{Binding StatisticType}" />
                        <Run Text=")" />
                    </TextBlock>
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>
        <Button x:Name="RemoveStatField"
                Grid.Row="4" Grid.Column="3"
                HorizontalAlignment="Stretch" VerticalAlignment="Top"
                Content="Remove statistic"
                Height="20"
                Click="RemoveStatisticClicked" />
        <TextBlock Text="Group Field(s):"
                   Grid.Row="5"
                   HorizontalAlignment="Center" VerticalAlignment="Center"
                   Margin="6,7,33,7" Grid.Column="1" Height="16" Width="76" />
        <ListBox x:Name="GroupFieldsListBox"
                 Grid.Row="6" Grid.Column="0" Grid.ColumnSpan="2"
                 MinWidth="110"
                 HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
                 Margin="25,0,0,0">
            <ListBox.ItemTemplate>
                <DataTemplate DataType="{x:Type esri:Field}">
                    <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="6" 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="5" Grid.Column="3"
                   HorizontalAlignment="Center" VerticalAlignment="Center"
                   Margin="39,7,10,7" Height="16" />
        <ListBox x:Name="OrderByFieldsListBox"
                 Grid.Row="6" Grid.Column="3" Grid.ColumnSpan="2"
                 HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
                 Margin="0,0,25,0">
            <ListBox.ItemTemplate>
                <DataTemplate DataType="{x:Type esri:OrderBy}">
                    <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="7" 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="8" Grid.Column="0" Grid.ColumnSpan="5"
                HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
                Padding="10,0" Margin="25,10"
                Content="Get statistics"
                Click="OnExecuteStatisticsQueryClicked" />
        <TreeView x:Name="ResultsTreeView"
                  Grid.Row="1" Grid.Column="5" Grid.RowSpan="8"
                  Margin="20,0,0,0">
            <TreeView.ItemTemplate>
                <HierarchicalDataTemplate ItemsSource="{Binding}">
                    <TextBlock Text="{Binding Key}" />
                    <HierarchicalDataTemplate.ItemTemplate>
                        <DataTemplate>
                            <ItemsControl ItemsSource="{Binding}">
                                <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>
    </Grid>
</UserControl>


In this topic
  1. Code