<Page x:Class="Fortune1000.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:Fortune"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:my="using:Fortune1000"
      xmlns:c1Col="using:C1.Xaml"
    xmlns:c1="using:C1.Xaml.FlexGrid"
    mc:Ignorable="d"
    Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
    <Page.Resources>
        <!-- the view model -->
        <my:Model x:Key="myModel" />
        <!-- converters -->
        <my:MarketValueConverter x:Key="_cvtMarketValue" />
        <my:InitialConverter x:Key="_cvtInitial" />

        <!-- brushes -->
        <LinearGradientBrush x:Key="_bkBrush" StartPoint="0 0" EndPoint="0 1">
            <GradientStop Color="#40808080" Offset="0" />
            <GradientStop Color="Black" Offset="1" />
        </LinearGradientBrush>

        <!-- clicking sound -->
        <MediaElement x:Name="_clickSound" Source="Resources/Click5.mp3" Volume="1" AutoPlay="False" />
    </Page.Resources>
    <Grid x:Name="LayoutRoot" Background="Transparent" DataContext="{Binding Companies,Source={StaticResource myModel}}">
        <!-- Pivot Control -->
        <my:CoolPivot Name="_pivot" Title="FORTUNE 1000">
            <!-- Pivot item one: list of items -->
            <PivotItem Header="list">
                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition/>
                        <RowDefinition Height="Auto"/>
                    </Grid.RowDefinitions>

                    <my:ChartingGrid x:Name="_flex"
                                     my:CoolPivot.LocalManipulation="True"
                                     ItemsSource="{Binding}"
                                     FillPositive="Orange"
                                     IsReadOnly="True"
                                     GridLinesVisibility="None"
                                     HeadersVisibility="Column"
                                     SelectionMode="Row"
                                     SelectionBackground="Red"
                                     CursorBackground="Red"
                                     AutoGenerateColumns="False">
                        <my:ChartingGrid.Columns>
                            <c1:Column Binding="{Binding Name}" Width="200" />
                            <c1:Column Binding="{Binding Sales}" />
                            <c1:Column Binding="{Binding Profits}"  />
                            <c1:Column Binding="{Binding Assets}" />
                            <c1:Column Binding="{Binding MarketValue}" Header="Mkt Val" />
                        </my:ChartingGrid.Columns>
                    </my:ChartingGrid>

                    <Border Grid.Row="1" Padding="4 4 0 4">
                        <Border.Resources>
                            <Style TargetType="TextBox">
                                <Setter Property="Foreground" Value="White" />
                                <Setter Property="FontWeight" Value="Bold" />
                            </Style>
                        </Border.Resources>
                        <StackPanel Orientation="Horizontal" >
                            <TextBlock Text="{Binding CurrentItem.Industry}" Style="{ThemeResource BaseTextBlockStyle}"/>
                            <TextBlock Text=" / " Style="{ThemeResource BaseTextBlockStyle}"/>
                            <TextBlock Text="{Binding CurrentItem.Country}" Style="{ThemeResource BaseTextBlockStyle}"/>
                        </StackPanel>
                    </Border>
                </Grid>
            </PivotItem>

            <!-- Pivot item two: item filter -->
            <PivotItem Header="filter" >
                <my:FilterControl CollectionView="{Binding}" ClickSound="{Binding ElementName=_clickSound}">
                    <my:FilterControl.Conditions>
                        <my:FilterCondition PropertyName="Name" Header="Initial" Converter="{StaticResource _cvtInitial}" />
                        <my:FilterCondition PropertyName="Country" />
                        <my:FilterCondition PropertyName="Industry" />
                        <my:FilterCondition PropertyName="MarketValue" Header="Market Value" Converter="{StaticResource _cvtMarketValue}" />
                    </my:FilterControl.Conditions>
                </my:FilterControl>
            </PivotItem>
        </my:CoolPivot>
    </Grid>
</Page>
