<?xml version="1.0" encoding="utf-8"?>
<Application x:Class="InvExplorer.App" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:c1="http://schemas.componentone.com/winfx/2006/xaml" xmlns:local="clr-namespace:InvExplorer">
  <Application.Resources>

    <!-- in C#, this would be written as ViewModel _model = new ViewModel(); -->
    <local:ViewModel x:Key="_model" />

    <!-- convert negative values to red, positive to green -->
    <local:NumberColorConverter x:Key="_cvtNumberColor" />

    <!-- brush for editable grid columns -->
    <SolidColorBrush x:Key="_brEditableColumn" Color="#fffbfbfb" />

    <!-- style for titles -->
    <Style TargetType="TextBlock" x:Key="_stTitle">
      <Setter Property="Foreground" Value="White" />
      <Setter Property="FontSize" Value="20" />
      <Setter Property="FontWeight" Value="Bold" />
      <Setter Property="Opacity" Value=".5" />
      <Setter Property="Margin" Value="4 0" />
      <Setter Property="VerticalAlignment" Value="Center" />
    </Style>

    <!-- style for add boxes -->
    <Style TargetType="TextBox" x:Key="_stAddBox">
      <!--<Setter Property="Background" Value="Black" />
      <Setter Property="Foreground" Value="White" />
      <Setter Property="SelectionBackground" Value="#ff6dbdd1" />
      <Setter Property="SelectionForeground" Value="Black" />-->
      <Setter Property="Width" Value="100" />
      <Setter Property="Margin" Value="4" />
      <Setter Property="VerticalAlignment" Value="Center" />
    </Style>

    <!-- style for hyperlink buttons -->
    <Style TargetType="HyperlinkButton">
      <Setter Property="VerticalAlignment" Value="Center" />
      <Setter Property="Margin" Value="6 0 0 0" />
      <Setter Property="Padding" Value="6 4" />
    </Style>

    <!-- style for grid splitters -->
    <Style TargetType="local:GridSplitter">
      <Setter Property="Background" Value="#ff404040" />
      <Setter Property="MinWidth" Value="8" />
      <Setter Property="MinHeight" Value="8" />
    </Style>

    <!-- style for all grids -->
    <Style TargetType="c1:C1FlexGrid">
      <Setter Property="Margin" Value="6 0" />
      <Setter Property="Background" Value="White" />
      <Setter Property="RowBackground" Value="Transparent" />
      <Setter Property="AlternatingRowBackground" Value="Transparent" />
      <Setter Property="HeadersVisibility" Value="Column" />
      <Setter Property="KeepCurrentVisible" Value="True" />
      <Setter Property="SelectionMode" Value="ListBox" />
      <Setter Property="AutoGenerateColumns" Value="False" />
      <Setter Property="ColumnHeaderBackground" Value="Black" />
      <Setter Property="ColumnHeaderForeground" Value="White" />
      <Setter Property="HeaderGridLinesBrush" Value="Black" />
      <Setter Property="GroupRowBackground" Value="Black" />
      <Setter Property="GroupRowForeground" Value="White" />
      <!--<Setter Property="HeaderFontWeight" Value="Bold" />-->
    </Style>

    <!-- style for TextBlock elements in grid cells -->
    <Style TargetType="TextBlock" x:Key="_tbCell">
      <Setter Property="VerticalAlignment" Value="Center" />
      <Setter Property="HorizontalAlignment" Value="Right" />
      <Setter Property="Padding" Value="3 0" />
    </Style>

    <!--
        
        Simplified ScrollBar template (applies to whole app).
        
        -->
    <Style TargetType="ScrollBar">
      <Setter Property="Template">
        <Setter.Value>
          <ControlTemplate TargetType="ScrollBar">
            <Grid x:Name="Root" Background="{TemplateBinding Background}">
              <Grid.Resources>

                <!-- RepeatButton Templates -->
                <ControlTemplate x:Key="RepeatButtonTemplate" TargetType="RepeatButton">
                  <Grid x:Name="Root" Background="Transparent" />
                </ControlTemplate>

                <!-- Horizontal Inc/Dec/Thumb Templates -->
                <ControlTemplate x:Key="HorizontalIncrementTemplate" TargetType="RepeatButton">
                  <Grid x:Name="Root">
                    <Path Stretch="Uniform" Height="8" Width="4" Data="F1 M 511.047,352.682L 511.047,342.252L 517.145,347.467L 511.047,352.682 Z " Fill="{TemplateBinding Foreground}" />
                    <Rectangle x:Name="DisabledElement" Opacity="0" RadiusX="2" RadiusY="2" Fill="#FFFFFFFF" />
                  </Grid>
                </ControlTemplate>
                <ControlTemplate x:Key="HorizontalDecrementTemplate" TargetType="RepeatButton">
                  <Grid x:Name="Root">
                    <Path Stretch="Uniform" Height="8" Width="4" Data="F1 M 110.692,342.252L 110.692,352.682L 104.594,347.467L 110.692,342.252 Z " Fill="{TemplateBinding Foreground}" />
                    <Rectangle x:Name="DisabledElement" Opacity="0" RadiusX="2" RadiusY="2" Fill="#FFFFFFFF" />
                  </Grid>
                </ControlTemplate>
                <ControlTemplate x:Key="HorizontalThumbTemplate" TargetType="Thumb">
                  <Grid x:Name="ThumbVisual" Margin="0,4,0,4">
                    <Rectangle x:Name="Background" RadiusX="4" RadiusY="4" Fill="{TemplateBinding Foreground}" Opacity=".7" />
                  </Grid>
                </ControlTemplate>

                <!-- Vertical Inc/Dec/Thumb Templates -->
                <ControlTemplate x:Key="VerticalIncrementTemplate" TargetType="RepeatButton">
                  <Grid x:Name="Root">
                    <Path Stretch="Uniform" Height="4" Width="8" Data="F1 M 531.107,321.943L 541.537,321.943L 536.322,328.042L 531.107,321.943 Z " Fill="{TemplateBinding Foreground}" />
                    <Rectangle x:Name="DisabledElement" Opacity="0" RadiusX="2" RadiusY="2" Fill="#FFFFFFFF" />
                  </Grid>
                </ControlTemplate>
                <ControlTemplate x:Key="VerticalDecrementTemplate" TargetType="RepeatButton">
                  <Grid x:Name="Root">
                    <Path Stretch="Uniform" Height="4" Width="8" Data="F1 M 541.537,173.589L 531.107,173.589L 536.322,167.49L 541.537,173.589 Z " Fill="{TemplateBinding Foreground}" />
                    <Rectangle x:Name="DisabledElement" Opacity="0" RadiusX="2" RadiusY="2" Fill="#FFFFFFFF" />
                  </Grid>
                </ControlTemplate>
                <ControlTemplate x:Key="VerticalThumbTemplate" TargetType="Thumb">
                  <Grid x:Name="ThumbVisual" Margin="4,0,4,0">
                    <Rectangle x:Name="Background" RadiusX="4" RadiusY="4" Fill="{TemplateBinding Foreground}" Opacity=".7" />
                  </Grid>
                </ControlTemplate>
              </Grid.Resources>

              <!-- Horizontal Template -->
              <Grid x:Name="HorizontalRoot" Background="#10000000">
                <Grid.ColumnDefinitions>
                  <ColumnDefinition Width="Auto" />
                  <ColumnDefinition Width="Auto" />
                  <ColumnDefinition Width="Auto" />
                  <ColumnDefinition Width="*" />
                  <ColumnDefinition Width="Auto" />
                </Grid.ColumnDefinitions>

                <!-- Repeat Buttons + Thumb -->
                <RepeatButton x:Name="HorizontalSmallDecrease" Foreground="{TemplateBinding Foreground}" Grid.Column="0" Width="16" IsTabStop="False" Interval="50" Template="{StaticResource HorizontalDecrementTemplate}" Margin="1" />
                <RepeatButton x:Name="HorizontalLargeDecrease" Grid.Column="1" Width="0" Template="{StaticResource RepeatButtonTemplate}" Interval="50" IsTabStop="False" />
                <Thumb x:Name="HorizontalThumb" Background="{TemplateBinding Background}" MinWidth="18" Width="18" Grid.Column="2" Template="{StaticResource HorizontalThumbTemplate}" />
                <RepeatButton x:Name="HorizontalLargeIncrease" Grid.Column="3" Template="{StaticResource RepeatButtonTemplate}" Interval="50" IsTabStop="False" />
                <RepeatButton x:Name="HorizontalSmallIncrease" Foreground="{TemplateBinding Foreground}" Grid.Column="4" Width="16" IsTabStop="False" Interval="50" Template="{StaticResource HorizontalIncrementTemplate}" Margin="1" />
              </Grid>

              <!-- Vertical Template -->
              <Grid x:Name="VerticalRoot" Visibility="Collapsed" Background="#10000000">
                <Grid.RowDefinitions>
                  <RowDefinition Height="Auto" />
                  <RowDefinition Height="Auto" />
                  <RowDefinition Height="Auto" />
                  <RowDefinition Height="*" />
                  <RowDefinition Height="Auto" />
                </Grid.RowDefinitions>

                <!-- Repeat Buttons + Thumb -->
                <RepeatButton x:Name="VerticalSmallDecrease" Foreground="{TemplateBinding Foreground}" Grid.Row="0" Height="16" IsTabStop="False" Interval="50" Template="{StaticResource VerticalDecrementTemplate}" Margin="1" />
                <RepeatButton x:Name="VerticalLargeDecrease" Grid.Row="1" Height="0" Template="{StaticResource RepeatButtonTemplate}" Interval="50" IsTabStop="False" />
                <Thumb x:Name="VerticalThumb" Background="{TemplateBinding Background}" MinHeight="18" Height="18" Grid.Row="2" Template="{StaticResource VerticalThumbTemplate}" />
                <RepeatButton x:Name="VerticalLargeIncrease" Grid.Row="3" Template="{StaticResource RepeatButtonTemplate}" Interval="50" IsTabStop="False" />
                <RepeatButton x:Name="VerticalSmallIncrease" Foreground="{TemplateBinding Foreground}" Grid.Row="4" Height="16" IsTabStop="False" Interval="50" Template="{StaticResource VerticalIncrementTemplate}" Margin="1" />
              </Grid>
            </Grid>
          </ControlTemplate>
        </Setter.Value>
      </Setter>
    </Style>

    <!--
        
        Simplified ComboBox template (applies to whole app).
        
        -->
    <Style TargetType="ComboBox">
      <Setter Property="Padding" Value="6,2,25,2" />
      <Setter Property="Background" Value="#FF1F3B53" />
      <Setter Property="HorizontalContentAlignment" Value="Left" />
      <Setter Property="BorderThickness" Value="1" />
      <Setter Property="TabNavigation" Value="Once" />
      <Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Auto" />
      <Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Auto" />
      <Setter Property="BorderBrush" Value="Black" />
      <Setter Property="Template">
        <Setter.Value>
          <ControlTemplate TargetType="ComboBox">
            <Grid>
              <Grid.Resources>
                <Style x:Name="comboToggleStyle" TargetType="ToggleButton">
                  <Setter Property="Foreground" Value="#FF333333" />
                  <Setter Property="Background" Value="#FFFFFFFF" />
                  <Setter Property="BorderBrush" Value="Black" />
                  <Setter Property="BorderThickness" Value="1" />
                  <Setter Property="Padding" Value="3" />
                  <Setter Property="Template">
                    <Setter.Value>
                      <ControlTemplate TargetType="ToggleButton">
                        <Grid>
                          <Rectangle x:Name="Background" Fill="White" StrokeThickness="{TemplateBinding BorderThickness}" Stroke="{TemplateBinding BorderBrush}" />
                          <ContentPresenter x:Name="contentPresenter" Content="{TemplateBinding Content}" ContentTemplate="{TemplateBinding ContentTemplate}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" Margin="{TemplateBinding Padding}" />
                        </Grid>
                      </ControlTemplate>
                    </Setter.Value>
                  </Setter>
                </Style>
              </Grid.Resources>
              <Border x:Name="ContentPresenterBorder">
                <Grid>
                  <ToggleButton x:Name="DropDownToggle" Style="{StaticResource comboToggleStyle}" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="0" HorizontalContentAlignment="Right" Background="{TemplateBinding Background}" BorderThickness="{TemplateBinding BorderThickness}" BorderBrush="{TemplateBinding BorderBrush}">
                    <Path x:Name="BtnArrow" Height="4" Width="8" Stretch="Uniform" Data="F1 M 301.14,-189.041L 311.57,-189.041L 306.355,-182.942L 301.14,-189.041 Z " Margin="0,0,6,0" HorizontalAlignment="Right">
                      <Path.Fill>
                        <SolidColorBrush x:Name="BtnArrowColor" Color="#FF333333" />
                      </Path.Fill>
                    </Path>
                  </ToggleButton>
                  <ContentPresenter x:Name="ContentPresenter" Margin="{TemplateBinding Padding}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}">
                    <TextBlock Text=" " />
                  </ContentPresenter>
                </Grid>
              </Border>
              <Popup x:Name="Popup">
                <Border x:Name="PopupBorder" HorizontalAlignment="Stretch" Height="Auto" BorderThickness="{TemplateBinding BorderThickness}" BorderBrush="{TemplateBinding BorderBrush}" CornerRadius="3">
                  <Border.Background>
                    <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                      <GradientStop Color="#FFFFFFFF" Offset="0" />
                      <GradientStop Color="#FFFEFEFE" Offset="1" />
                    </LinearGradientBrush>
                  </Border.Background>
                  <ScrollViewer x:Name="ScrollViewer" BorderThickness="0" Padding="1">
                    <ItemsPresenter />
                  </ScrollViewer>
                </Border>
              </Popup>
            </Grid>
          </ControlTemplate>
        </Setter.Value>
      </Setter>
    </Style>
  </Application.Resources>
</Application>