<Page
    x:Class="FlexGrid101.CollectionView"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:flexGrid="using:C1.Xaml.FlexGrid"
    xmlns:c1="using:C1.Xaml"
    xmlns:local="using:FlexGrid101"
    mc:Ignorable="d"
    Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">

    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition />
        </Grid.RowDefinitions>
        <Grid.Resources>
            <Style TargetType="TextBlock">
                <Setter Property="FontSize" Value="14"/>
                <Setter Property="Margin" Value="10,0,6,0"/>
                <Setter Property="VerticalAlignment" Value="Center"/>
            </Style>
            <local:C1CollectionViewConverter x:Name="converter" >
                <local:C1CollectionViewConverter.GroupDescriptions>
                    <c1:PropertyGroupDescription PropertyName="Color" />
                    <c1:PropertyGroupDescription PropertyName="Line" />
                </local:C1CollectionViewConverter.GroupDescriptions>
                <local:C1CollectionViewConverter.SortDescriptions>
                    <c1:SortDescription PropertyName="Color" Direction="Descending"/>
                </local:C1CollectionViewConverter.SortDescriptions>
            </local:C1CollectionViewConverter>
        </Grid.Resources>
        <StackPanel Orientation="Horizontal" Margin="-4,0,0,0">
            <TextBlock x:Name="_txtGroupOn" Text="{Binding GroupOn_Text, Source={StaticResource FlexGridSamplesLocalization}}" HorizontalAlignment="Right"/>
            <CheckBox x:Name="_cbColor" Content="{Binding Color_Content, Source={StaticResource FlexGridSamplesLocalization}}" VerticalContentAlignment="Center" IsChecked="True" Checked="groupCheckbox_Checked" Unchecked="groupCheckbox_Unchecked"/>
            <CheckBox x:Name="_cbLine" Content="{Binding Line_Content, Source={StaticResource FlexGridSamplesLocalization}}" VerticalContentAlignment="Center" IsChecked="True" Checked="groupCheckbox_Checked" Unchecked="groupCheckbox_Unchecked"/>
            <CheckBox x:Name="_cbRating" Content="{Binding Rating_Content, Source={StaticResource FlexGridSamplesLocalization}}" VerticalContentAlignment="Center" IsChecked="False" Checked="groupCheckbox_Checked" Unchecked="groupCheckbox_Unchecked"/>

        </StackPanel>
        <StackPanel Orientation="Horizontal" Margin="-4,0,0,0" Grid.Row="1">
            <TextBlock x:Name="_txtFilterOn" Text="{Binding FilterOn_Text, Source={StaticResource FlexGridSamplesLocalization}}"  VerticalAlignment="Center"/>
            <ComboBox 
                        Name="filterComboBox"   SelectionChanged="filterComboBox_SelectionChanged"
                        Height="30" Width="150" Margin="5" VerticalAlignment="Center"/>
            <TextBox 
                        Name="filterTextBox"  HorizontalAlignment="Center" VerticalAlignment="Center" TextChanged="filterTextBox_TextChanged" PlaceholderText="{Binding FilterBox_Placeholder, Source={StaticResource FlexGridSamplesLocalization}}" Height="25" 
                        Width="150" Margin="5"/>
        </StackPanel>

        <!-- FlexGrid -->
        <flexGrid:C1FlexGrid x:Name="c1FlexGrid1" AutoGenerateColumns="false" IsReadOnly="True" ItemsSource="{Binding Path=Products,Converter={StaticResource ResourceKey=converter}}" ShowOutlineBar="True" Grid.Row="2" BorderThickness="1">
            <flexGrid:C1FlexGrid.Columns>
                <flexGrid:Column  Width="200">
                    <flexGrid:Column.CellTemplate>
                        <DataTemplate>
                            <TextBlock Text="{Binding Name}"/>
                        </DataTemplate>
                    </flexGrid:Column.CellTemplate>
                </flexGrid:Column>
                <flexGrid:Column x:Uid="/FlexGridSamplesLib/Resources/CVLine" Header="Line" Binding="{Binding Line}" Width="auto"/>
                <flexGrid:Column x:Uid="/FlexGridSamplesLib/Resources/CVColor" Header="Color" Binding="{Binding Color}" Width="auto" />
                <flexGrid:Column x:Uid="/FlexGridSamplesLib/Resources/CVPrice" Header="Price" Binding="{Binding Price}" Format="c2" GroupAggregate="Sum" Width="auto"/>
                <flexGrid:Column x:Uid="/FlexGridSamplesLib/Resources/CVWeight" Header="Weight" Binding="{Binding Weight}" Format="n2" GroupAggregate="Sum" Width="auto" />
                <flexGrid:Column x:Uid="/FlexGridSamplesLib/Resources/CVCost" Header="Cost" Binding="{Binding Cost}" Format="c2" GroupAggregate="Sum" Width="auto"/>
                <flexGrid:Column x:Uid="/FlexGridSamplesLib/Resources/CVVolume" Header="Volume" Binding="{Binding Volume}" GroupAggregate="Sum" Width="auto"/>
                <flexGrid:Column x:Uid="/FlexGridSamplesLib/Resources/CVRating" Header="Rating" Binding="{Binding Rating}" Format="n2" GroupAggregate="Average" Width="auto" />
                <flexGrid:Column x:Uid="/FlexGridSamplesLib/Resources/CVDiscontinued" Header="Discontinued" Binding="{Binding Discontinued}" Width="120"/>
            </flexGrid:C1FlexGrid.Columns>
        </flexGrid:C1FlexGrid>
        <VisualStateManager.VisualStateGroups>

            <!-- Visual states reflect the application's window size -->
            <VisualStateGroup>
                <VisualState x:Name="WideLayout">
                    <VisualState.StateTriggers>
                        <AdaptiveTrigger MinWindowWidth="540" />
                    </VisualState.StateTriggers>
                    <VisualState.Setters>
                    </VisualState.Setters>
                </VisualState>

                <VisualState x:Name="NarrowLayout">
                    <VisualState.StateTriggers>
                        <AdaptiveTrigger MinWindowWidth="0" />
                    </VisualState.StateTriggers>
                    <VisualState.Setters>
                        <Setter Target="_txtGroupOn.FontSize" Value="10" />
                        <Setter Target="_cbColor.FontSize" Value="10" />
                        <Setter Target="_cbColor.MinWidth" Value="60" />
                        <Setter Target="_cbColor.Margin" Value="0" />
                        <Setter Target="_cbLine.FontSize" Value="10" />
                        <Setter Target="_cbLine.MinWidth" Value="60" />
                        <Setter Target="_cbLine.Margin" Value="0" />
                        <Setter Target="_cbRating.FontSize" Value="10" />
                        <Setter Target="_cbRating.MinWidth" Value="60" />
                        <Setter Target="_cbRating.Margin" Value="0" />
                        <Setter Target="_txtFilterOn.FontSize" Value="10" />
                        <Setter Target="filterComboBox.FontSize" Value="10" />
                        <Setter Target="filterComboBox.Margin" Value="0" />
                        <Setter Target="filterTextBox.FontSize" Value="10" />
                        <Setter Target="filterTextBox.Width" Value="100" />
                        <Setter Target="filterTextBox.MinWidth" Value="0" />
                        <Setter Target="filterTextBox.Margin" Value="3,0,0,3" />
                        <Setter Target="c1FlexGrid1.FontSize" Value="10" />
                    </VisualState.Setters>
                </VisualState>
            </VisualStateGroup>
        </VisualStateManager.VisualStateGroups>
    </Grid>
</Page>
