<Window x:Class="SurfacePlot3D.MainWindow"
        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"
        mc:Ignorable="d"
        xmlns:Local="clr-namespace:SurfacePlot3D"
        xmlns:Converters="clr-namespace:SurfacePlot3D.Converters"
        xmlns:Behaviors="clr-namespace:SurfacePlot3D.Behaviors"
        xmlns:h="http://helix-toolkit.org/wpf"
        Title="Surface Plot 3D Demo - State Population" 
        Height="1000" Width="1000"               
        WindowStartupLocation="CenterScreen"
        WindowState="Maximized"
        >
    <Grid Background="Black">
        <Grid.Resources>
            <Converters:DivideByNegativeConverter x:Key="DivideByNegativeConverter"/>
            <Converters:DivideByPositiveConverter x:Key="DivideByPositiveConverter"/>
        </Grid.Resources>
        <Grid.RowDefinitions>
            <RowDefinition Height="30"/>
            <RowDefinition Height="30"/>
            <RowDefinition Height="500"/>
            <RowDefinition Height="30"/>
            <RowDefinition/>
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="250"/>
            <ColumnDefinition/>
        </Grid.ColumnDefinitions>
        
        <Button Visibility="Hidden" Background="Black" Foreground="White" Grid.Row="0" Grid.Column="0" HorizontalAlignment="Stretch" Content="Load Csv" Height="30" Command="{Binding Path=ReadCsvCommandIc}"/>
        <TextBlock Grid.Row="0" Grid.Column="1" Foreground="White" VerticalAlignment="Center" HorizontalAlignment="Center" FontWeight="Bold" Text="State Population 1900 - 2019"/>
        <TextBlock Grid.Row="1" Grid.Column="0" Foreground="White" VerticalAlignment="Center" HorizontalAlignment="Center" FontWeight="Bold" Text="States"/>

        <Grid Grid.Row="2" Grid.Column="0" Grid.RowSpan="3" Behaviors:Zoom.EnableMouseWheel="True">
            <ListBox ItemsSource="{Binding Path=Rsd.FilteredStates}" BorderBrush="Transparent" SelectedItem="{Binding Path=SelectedState}" Background="Transparent" Foreground="White">
                <ListBox.ItemContainerStyle>
                    <Style TargetType="ListBoxItem">
                        <Setter Property="Background" Value="Transparent" />
                        <Setter Property="BorderBrush" Value="Transparent" />
                        <Setter Property="BorderThickness" Value="2" />
                        <Style.Triggers>
                            <Trigger Property="IsSelected" Value="True">
                                <Setter Property="Foreground" Value="SeaGreen" />
                            </Trigger>
                            <Trigger Property="IsMouseOver" Value="True">
                                <Setter Property="Foreground" Value="SeaGreen" />
                            </Trigger>
                        </Style.Triggers>
                    </Style>
                </ListBox.ItemContainerStyle>
                <ListBox.ItemTemplate>
                    <DataTemplate>
                        <TextBlock Text="{Binding Path=State}" Background="Transparent"/>
                    </DataTemplate>
                </ListBox.ItemTemplate>
            </ListBox>
        </Grid>

        <Grid Grid.Row="1" Grid.Column="1" Grid.RowSpan="2" Background="Transparent" Behaviors:Zoom.EnableMouseWheel="True">
            <Grid.Resources>
                <Style TargetType="{x:Type TextBox}">
                    <Setter Property="Background" Value="Transparent"/>
                    <Setter Property="BorderThickness" Value="0"/>
                    <Setter Property="BorderBrush" Value="Transparent"/>
                    <Setter Property="VerticalAlignment" Value="Center"/>
                </Style>
                <Style TargetType="{x:Type Border}">
                    <Setter Property="Background" Value="SeaGreen"/>
                    <Setter Property="CornerRadius" Value="7"/>
                    <Setter Property="Margin" Value="1"/>
                </Style>
            </Grid.Resources>
            <Grid.RowDefinitions>
                <RowDefinition Height="30"/>
                <RowDefinition/>
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="50"/>
                <ColumnDefinition Width="105"/>
                <ColumnDefinition Width="50"/>
                <ColumnDefinition Width="100"/>
                <ColumnDefinition Width="50"/>
                <ColumnDefinition Width="50"/>
                <ColumnDefinition/>
            </Grid.ColumnDefinitions>
            <TextBlock FontWeight="Bold" Text="Filter" Foreground="White" HorizontalAlignment="Center" VerticalAlignment="Center"/>
            <Border Grid.Column="1" >
                <TextBox Text="{Binding Path=Rsd.StateFilter,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"/>
            </Border>
            <Border Grid.Column="2" >
                <TextBox Text="{Binding Path=Rsd.YearFilter,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"/>
            </Border>
            <Border Grid.Column="3" >
                <TextBox Text="{Binding Path=Rsd.PopulationFilter,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"/>
            </Border>
            <!--<Slider Grid.Column="4" Margin="25,0,25,0" Grid.ColumnSpan="4" Minimum="100000" Maximum="2000000" Value="{Binding Path=PopulationDivide,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"/>-->


            <!--
            <Border Grid.Column="4" >
                <TextBox Text="{Binding Path=Rsd.RowFilter,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"/>
            </Border>
            <Border Grid.Column="5" >
                <TextBox Text="{Binding Path=Rsd.ColumnFilter,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"/>
            </Border>
            -->

            <ListView Margin="50,1,1,1" Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="7" Background="Transparent" Foreground="White"
                      ItemsSource="{Binding Path=Rsd.FilteredStatePopulationDataItems}"
                      SelectedItem="{Binding Path=SelectedDataItem}"
                      IsSynchronizedWithCurrentItem="True"
                      BorderBrush="Transparent"
                      >
                <ListView.ItemContainerStyle>
                    <Style TargetType="ListViewItem">
                        <Style.Resources>
                            <SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="SeaGreen"/>
                            <SolidColorBrush x:Key="{x:Static SystemColors.ControlBrushKey}" Color="SeaGreen"/>
                        </Style.Resources>
                        <Setter Property="Background" Value="Transparent" />
                        <Setter Property="BorderBrush" Value="Black" />
                        <Setter Property="BorderThickness" Value="2" />
                        <Style.Triggers>
                            <Trigger Property="IsSelected" Value="True">
                                <Setter Property="Foreground" Value="Black" />
                                <Setter Property="Background" Value="SeaGreen" />
                            </Trigger>
                            <Trigger Property="IsMouseOver" Value="True">
                                <Setter Property="Foreground" Value="Black" />
                                <Setter Property="Background" Value="SeaGreen" />
                            </Trigger>
                        </Style.Triggers>
                    </Style>
                </ListView.ItemContainerStyle>
                <ListView.View>
                    <GridView>
                        <GridViewColumn Header="State" DisplayMemberBinding="{Binding Path=State}" Width="100"/>
                        <GridViewColumn Header="Year" DisplayMemberBinding="{Binding Path=Year}" Width="50"/>
                        <GridViewColumn Header="Population" DisplayMemberBinding="{Binding Path=Population}" Width="100" />
                        <!--
                        <GridViewColumn Header="Row" DisplayMemberBinding="{Binding Path=Row}" Width="50"/>
                        <GridViewColumn Header="Col" DisplayMemberBinding="{Binding Path=Column}" Width="50" />

                        <GridViewColumn Header="PosX" DisplayMemberBinding="{Binding Path=PosX}" Width="150" />
                        <GridViewColumn Header="PosY" DisplayMemberBinding="{Binding Path=PosY}" Width="150" />
                        <GridViewColumn Header="PosZ" DisplayMemberBinding="{Binding Path=PosZ}" Width="150" />
                        -->
                    </GridView>
                </ListView.View>
            </ListView>
        </Grid>

        <Border Grid.Row="3" Grid.Column="1" Background="SeaGreen" CornerRadius="7">
            <StackPanel HorizontalAlignment="Center" Orientation="Horizontal">
                <TextBlock FontSize="20" Text="[" FontWeight="Bold" Foreground="Black"/>
                <TextBlock FontSize="20" FontWeight="Bold" VerticalAlignment="Center" Text="{Binding Path=SelectedDataItem.State}" Foreground="Black"/>
                <TextBlock FontSize="20" Margin="5,0,5,0" Text="-" FontWeight="Bold" Foreground="Black"/>
                <TextBlock FontSize="20" FontWeight="Bold" VerticalAlignment="Center" Text="{Binding Path=SelectedDataItem.Year}" Foreground="Black"/>
                <TextBlock FontSize="20" Margin="5,0,5,0" Text="-" FontWeight="Bold" Foreground="Black"/>
                <TextBlock FontSize="20" FontWeight="Bold" VerticalAlignment="Center" Text="{Binding Path=SelectedDataItem.Population}" Foreground="Black"/>
                <TextBlock FontSize="20" Text="]" FontWeight="Bold" Foreground="Black"/>
            </StackPanel>
        </Border>
        
        <h:HelixViewport3D x:Name="HelixTestViewport" Background="Transparent" ShowViewCube="True" Grid.Row="4" Grid.Column="1" Grid.RowSpan="9" Loaded="HelixTestViewport_Loaded">
            <h:HelixViewport3D.Resources>
                <Storyboard x:Key="SpinModelX" >
                    <DoubleAnimation Duration="0:0:30" 
                                     Storyboard.TargetName="MainModelX"
                                     Storyboard.TargetProperty="Angle" From="0" To="360" RepeatBehavior="Forever"/>
                </Storyboard>

                <Storyboard x:Key="SpinModelY" >
                    <DoubleAnimation Duration="0:0:30" 
                                     Storyboard.TargetName="MainModelY"
                                     Storyboard.TargetProperty="Angle" From="0" To="360" RepeatBehavior="Forever"/>
                </Storyboard>

                <Storyboard x:Key="SpinModelZ" >
                    <DoubleAnimation Duration="0:0:30" 
                                     Storyboard.TargetName="MainModelZ"
                                     Storyboard.TargetProperty="Angle" From="0" To="360" RepeatBehavior="Forever"/>
                </Storyboard>


                <Storyboard x:Key="SpinTextX" >
                    <DoubleAnimation Duration="0:0:30" 
                                     Storyboard.TargetName="TextModelX"
                                     Storyboard.TargetProperty="Angle" From="0" To="360" RepeatBehavior="Forever"/>
                </Storyboard>

                <Storyboard x:Key="SpinTextY" >
                    <DoubleAnimation Duration="0:0:30" 
                                     Storyboard.TargetName="TextModelY"
                                     Storyboard.TargetProperty="Angle" From="0" To="360" RepeatBehavior="Forever"/>
                </Storyboard>

                <Storyboard x:Key="SpinTextZ" >
                    <DoubleAnimation Duration="0:0:30" 
                                     Storyboard.TargetName="TextModelZ"
                                     Storyboard.TargetProperty="Angle" From="0" To="360" RepeatBehavior="Forever"/>
                </Storyboard>
            </h:HelixViewport3D.Resources>
            <h:DefaultLights />
            <h:GridLinesVisual3D 
                Visible="{Binding Path=ShowGridX}"
                MajorDistance="{Binding Path=MajorDistanceX}" 
                MinorDistance="{Binding Path=MinorDistanceX}" 
                Width="{Binding Path=MaxY}" Length="{Binding Path=MaxX}">
                <h:GridLinesVisual3D.Transform>
                    <Transform3DGroup>
                        <TranslateTransform3D OffsetX="0" OffsetY="0" OffsetZ="0"/>
                    </Transform3DGroup>
                </h:GridLinesVisual3D.Transform>
            </h:GridLinesVisual3D>
            <h:GridLinesVisual3D 
                Visible="{Binding Path=ShowGridY}" 
                MajorDistance="{Binding Path=MajorDistanceY}" 
                MinorDistance="{Binding Path=MinorDistanceY}" 
                Width="{Binding Path=MaxY}" Length="{Binding Path=GridZHeight}">
                <h:GridLinesVisual3D.Transform>
                    <Transform3DGroup>
                        <RotateTransform3D>
                            <RotateTransform3D.Rotation>
                                <AxisAngleRotation3D Angle="90" Axis="0,1,0"/>
                            </RotateTransform3D.Rotation>
                        </RotateTransform3D>
                        <TranslateTransform3D 
                            OffsetX="{Binding Path=MaxX,Converter={StaticResource DivideByPositiveConverter}}" 
                            OffsetY="0" 
                            OffsetZ="{Binding Path=GridZHeight,Converter={StaticResource DivideByPositiveConverter}}"/>
                    </Transform3DGroup>
                </h:GridLinesVisual3D.Transform>
            </h:GridLinesVisual3D>
            <h:GridLinesVisual3D 
                Visible="{Binding Path=ShowGridZ}" 
                MajorDistance="{Binding Path=MajorDistanceZ}" 
                MinorDistance="{Binding Path=MinorDistanceZ}" 
                Width="{Binding Path=GridZHeight}" Length="{Binding Path=MaxX}">
                <h:GridLinesVisual3D.Transform>
                    <Transform3DGroup>
                        <RotateTransform3D>
                            <RotateTransform3D.Rotation>
                                <AxisAngleRotation3D Angle="90" Axis="1,0,0"/>
                            </RotateTransform3D.Rotation>
                        </RotateTransform3D>
                        <!-- -->
                        <TranslateTransform3D 
                            OffsetX="0" 
                            OffsetY="{Binding Path=MaxY,Converter={StaticResource DivideByNegativeConverter}}"
                            OffsetZ="{Binding Path=GridZHeight,Converter={StaticResource DivideByPositiveConverter}}"/>
                    </Transform3DGroup>
                </h:GridLinesVisual3D.Transform>
            </h:GridLinesVisual3D>
            <Local:SurfacePlotVisual3D 
                Points="{Binding Data}" 
                ColorValues="{Binding ColorValues}"
                SurfaceBrush="{Binding Path=SurfaceBrush}"/>
            <ModelVisual3D Content="{Binding Path=IndicatorModel3DGroup}"/>
            <ModelVisual3D Content="{Binding Path=TextModel3DGroup}">
                <ModelVisual3D.Transform>
                    <Transform3DGroup>
                        <RotateTransform3D>
                            <RotateTransform3D.Rotation>
                                <AxisAngleRotation3D x:Name="TextModelX" Axis="1,0,0" />
                            </RotateTransform3D.Rotation>
                        </RotateTransform3D>

                        <RotateTransform3D>
                            <RotateTransform3D.Rotation>
                                <AxisAngleRotation3D x:Name="TextModelY" Axis="0,1,0" />
                            </RotateTransform3D.Rotation>
                        </RotateTransform3D>

                        <RotateTransform3D>
                            <RotateTransform3D.Rotation>
                                <AxisAngleRotation3D x:Name="TextModelZ" Axis="0,0,1" />
                            </RotateTransform3D.Rotation>
                        </RotateTransform3D>

                    </Transform3DGroup>
                </ModelVisual3D.Transform>
            </ModelVisual3D>
        </h:HelixViewport3D>
    </Grid>
</Window>