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.UWP.Samples.StatsQueryGroupAndSort.StatsQueryGroupAndSort"
    xmlns:local="using:ArcGISRuntime.UWP.Samples.StatsQueryGroupAndSort"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"    
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    
    <UserControl.Resources>
        <CollectionViewSource x:Name="GroupedResultData"
                              Source="{Binding GroupedStatistics}"
                              IsSourceGrouped="True"/>
        <local:StringFormatConverter x:Key="StringFormatter"/>
    </UserControl.Resources>
    
    <Grid HorizontalAlignment="Center" VerticalAlignment="Center"
          MinWidth="300" MaxWidth="800"
          MinHeight="300" MaxHeight="800">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="50"/>
            <ColumnDefinition Width="110"/>
            <ColumnDefinition Width="40"/>
            <ColumnDefinition Width="110"/>
            <ColumnDefinition Width="50"/>
            <ColumnDefinition/>
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="40"/>
            <RowDefinition Height="40"/>
            <RowDefinition MinHeight="50" Height="*"/>
            <RowDefinition Height="40"/>
            <RowDefinition Height="40"/>
            <RowDefinition MinHeight="50" Height="*"/>
            <RowDefinition Height="30"/>
            <RowDefinition MinHeight="50" Height="*"/>
            <RowDefinition Height="30"/>
            <RowDefinition MinHeight="50" Height="50"/>
            <RowDefinition/>
        </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"
                   Text="Statistics: US States"/>
        <TextBlock Grid.Row="1" 
                   HorizontalAlignment="Right" VerticalAlignment="Center"
                   Text="Field:"/>
        <ComboBox x:Name="FieldsComboBox" 
                  Grid.Row="1" Grid.Column="1"
                  HorizontalAlignment="Stretch"
                  Margin="5" VerticalAlignment="Center">
            <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"
                  HorizontalAlignment="Stretch"
                  Margin="5" VerticalAlignment="Center"/>
        <Button x:Name="AddStatisticButton"
                Grid.Row="1" Grid.Column="4"
                Margin="3"
                Content="+"
                Click="AddStatisticClicked"/>
        <ScrollViewer Grid.Row="2" Grid.ColumnSpan="5"
                 Margin="25,5">
            <ListBox x:Name="StatFieldsListBox"                 
                 Height="120">
                <ListBox.ItemTemplate>
                    <DataTemplate>
                        <TextBlock>
                        <Run Text="{Binding OnFieldName}"/>
                        <Run Text=" ("/>
                        <Run Text="{Binding StatisticType}"/>
                        <Run Text=")"/>
                        </TextBlock>
                    </DataTemplate>
                </ListBox.ItemTemplate>
            </ListBox>
        </ScrollViewer>
        <Button x:Name="RemoveStatField"
                Grid.Row="3" Grid.Column="3"
                HorizontalAlignment="Stretch" VerticalAlignment="Top"
                Content="Remove" 
                Height="30"
                Click="RemoveStatisticClicked"/>
        <TextBlock Text="Group by"
                   Grid.Row="4" Grid.ColumnSpan="2"
                   HorizontalAlignment="Left" VerticalAlignment="Bottom"
                   Margin="25,0,0,5"/>
        <ListBox x:Name="GroupFieldsListBox"
                 Grid.Row="5" Grid.ColumnSpan="5"
                 MinHeight="110"
                 HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
                 Margin="25,0">
            <ListBox.ItemTemplate>
                <DataTemplate>
                    <StackPanel Orientation="Horizontal">
                        <CheckBox Content="{Binding Name}"
                                  Checked="GroupFieldCheckChanged" Unchecked="GroupFieldCheckChanged"/>
                    </StackPanel>
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>
        <TextBlock Text="Order by"
                   Grid.Row="6" Grid.ColumnSpan="2"
                   HorizontalAlignment="Left" VerticalAlignment="Bottom"
                   Margin="25,0,0,5"/>
        <ListBox x:Name="OrderByFieldsListBox"
                 Grid.Row="7" Grid.ColumnSpan="5"
                 HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
                 MinHeight="110"
                 Margin="25,0">
            <ListBox.ItemTemplate>
                <DataTemplate>
                    <StackPanel Orientation="Horizontal">
                        <CheckBox IsChecked="{Binding OrderWith}">
                            <CheckBox.Content>
                                <TextBlock>
                                    <Run Text="{Binding OrderInfo.FieldName}"/>
                                    <Run Text=" ("/>
                                    <Run Text="{Binding OrderInfo.SortOrder}"/>
                                    <Run Text=")"/>
                                </TextBlock>
                            </CheckBox.Content>
                        </CheckBox>
                    </StackPanel>
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>
        <Button x:Name="SortOrderButton"
                Grid.Row="8" 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="9" Grid.Column="0" Grid.ColumnSpan="5"
                HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
                Padding="10,0" Margin="25,5,30,5"
                Content="Get Statistics"
                Click="OnExecuteStatisticsQueryClicked" Height="40"/>

        <ScrollViewer x:Name="SmallResultsPanel" Grid.Row="10" Grid.ColumnSpan="5"
                      Margin="25,0">
            <ListView ItemsSource="{Binding Source={StaticResource GroupedResultData}}">
                <ListView.GroupStyle>
                    <GroupStyle>
                        <GroupStyle.HeaderTemplate>
                            <DataTemplate>
                                <TextBlock Text="{Binding Key}"/>
                            </DataTemplate>
                        </GroupStyle.HeaderTemplate>
                    </GroupStyle>
                </ListView.GroupStyle>

                <ListView.ItemTemplate>
                    <DataTemplate>
                        <ItemsControl ItemsSource="{Binding}">
                            <ItemsControl.ItemTemplate>
                                <DataTemplate>
                                    <TextBlock HorizontalAlignment="Left">
                                        <Run FontWeight="Bold" Text="{Binding Key}"/>
                                        <Run Text=" : "/>
                                        <Run Text="{Binding Value, Converter={StaticResource StringFormatter}, ConverterParameter='{}{0:0,0}'}"/>
                                    </TextBlock>
                                </DataTemplate>
                            </ItemsControl.ItemTemplate>
                        </ItemsControl>
                    </DataTemplate>
                </ListView.ItemTemplate>
            </ListView>
        </ScrollViewer>

        <ScrollViewer x:Name="LargeResultsPanel"
                      Grid.Row="0" Grid.Column="5" Grid.RowSpan="10"
                      Margin="15,0">
            <ListView Width="300"
                      ItemsSource="{Binding Source={StaticResource GroupedResultData}}">
                <ListView.GroupStyle>
                    <GroupStyle>
                        <GroupStyle.HeaderTemplate>
                            <DataTemplate>
                                <TextBlock Text="{Binding Key}"/>
                            </DataTemplate>
                        </GroupStyle.HeaderTemplate>
                    </GroupStyle>
                </ListView.GroupStyle>

                <ListView.ItemTemplate>
                    <DataTemplate>
                        <ItemsControl ItemsSource="{Binding}">
                            <ItemsControl.ItemTemplate>
                                <DataTemplate>
                                    <TextBlock HorizontalAlignment="Left">
                                        <Run FontWeight="Bold" Text="{Binding Key}"/>
                                        <Run Text=" : "/>
                                        <Run Text="{Binding Value, Converter={StaticResource StringFormatter}, ConverterParameter='{}{0:0,0}'}"/>
                                    </TextBlock>
                                </DataTemplate>
                            </ItemsControl.ItemTemplate>
                        </ItemsControl>
                    </DataTemplate>
                </ListView.ItemTemplate>
            </ListView>
        </ScrollViewer>
        
        <!--
        ============================
        Adaptive triggers
        ============================
        -->
        <VisualStateManager.VisualStateGroups>
            <VisualStateGroup>
                <!--
                ============================
                Handle screen less than 720 effective pixels
                ============================
                -->
                <VisualState>
                    <VisualState.StateTriggers>
                        <AdaptiveTrigger MinWindowWidth="0" />
                    </VisualState.StateTriggers>
                    <VisualState.Setters>
                        <Setter Target="SmallResultsPanel.Visibility" Value="Visible"/>
                        <Setter Target="LargeResultsPanel.Visibility" Value="Collapsed"/>
                    </VisualState.Setters>
                </VisualState>
                <!--
                ============================
                Handle screen over 720 effective pixels
                ============================
                -->
                <VisualState>
                    <VisualState.StateTriggers>
                        <AdaptiveTrigger MinWindowWidth="720" />
                    </VisualState.StateTriggers>
                    <VisualState.Setters>
                        <Setter Target="SmallResultsPanel.Visibility" Value="Collapsed"/>
                        <Setter Target="LargeResultsPanel.Visibility" Value="Visible"/>
                    </VisualState.Setters>
                </VisualState>
            </VisualStateGroup>
        </VisualStateManager.VisualStateGroups>
    </Grid>
</UserControl>


In this topic
  1. Code