<UserControl x:Class="CSVPage"
   xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
   xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
   xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
   xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
   xmlns:self="clr-namespace:OmagCUT.TreeViewItem"
   mc:Ignorable="d" 
   d:DesignHeight="853.3" d:DesignWidth="1280">

   <!-- Definizione della SplitPage -->
   <Grid Name="SplitPageGrid" >
      <Grid.ColumnDefinitions>
         <ColumnDefinition Width="3*"/>
         <ColumnDefinition Width="12*"/>
      </Grid.ColumnDefinitions>
      <Grid.RowDefinitions>
         <RowDefinition Height="1*"/>
         <RowDefinition Height="8*"/>
         <RowDefinition Height="1*"/>
      </Grid.RowDefinitions>

      <!--Upper button grid-->
      <Grid Grid.Column="1">
         <Grid.ColumnDefinitions>
            <ColumnDefinition Width="5*"/>
            <ColumnDefinition Width="7*"/>
         </Grid.ColumnDefinitions>

         <!--Griglia per oscurare i bottoni della pagina sottostante-->
            <Grid Background="{DynamicResource OmagCut_Gray}">
            <Grid.ColumnDefinitions>
               <ColumnDefinition Width="1*"/>
               <ColumnDefinition Width="1*"/>
               <ColumnDefinition Width="3*"/>
            </Grid.ColumnDefinitions>

         </Grid>
      </Grid>

      <!--Left Button Grid-->
      <Grid Grid.RowSpan="3">
         <Grid.RowDefinitions>
            <RowDefinition Height="2*"/>
            <RowDefinition Height="0.5*"/>
            <RowDefinition Height="5.5*"/>
            <RowDefinition Height="1*"/>
            <RowDefinition Height="1*"/>
         </Grid.RowDefinitions>

         <Label Name="CsvPathTxBl" Grid.Row="1" Background="White" FontSize="16" VerticalAlignment="Center" Padding="2,5,0,5"/>

            <TreeView Name="PartsTreeView" Grid.Row="2" Background="{DynamicResource OmagCut_TreeViewBackGroundColor}">
            <TreeView.Resources>
               <!--Modifico HierarchicalDataTemplate del CathegoryItem per poter inserire immagine e testo e per -->
               <!--renderlo apribile con un solo click -->
               <HierarchicalDataTemplate DataType="{x:Type self:PartCathegoryItem}" ItemsSource="{Binding Items}">

                  <Grid >
                     <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="Auto"/>
                        <ColumnDefinition Width="1*"/>
                     </Grid.ColumnDefinitions>

                     <Image Grid.Column="0" Source="{Binding PictureString}" Height="32" Width="32" Margin="0,8,6,4" />
                     <TextBlock Grid.Column="1" Text="{Binding Name}" FontSize="15" Margin="10" />

                  </Grid>

                  <!--Assegna ai nodi ToolItem lo Style normale dei TreeViewItem, eliminando l'ombra, data dal -->
                  <!-- multibinding quando sono attivi.-->
                  <HierarchicalDataTemplate.ItemContainerStyle>
                     <Style TargetType="{x:Type TreeViewItem}" >
                        <Setter Property="Foreground" Value="{DynamicResource OmagCut_TreeViewTextColor}" />
                        <Setter Property="IsSelected" Value="{Binding IsSelected}" />
                        <Setter Property="IsExpanded" Value="{Binding IsExpanded}" />
                        <Setter Property="Template">
                           <Setter.Value>
                              <ControlTemplate TargetType="{x:Type TreeViewItem}">
                                 <Grid>
                                    <Grid.ColumnDefinitions>
                                       <ColumnDefinition MinWidth="0" Width="0"/>
                                       <ColumnDefinition Width="Auto"/>
                                       <ColumnDefinition Width="*"/>
                                    </Grid.ColumnDefinitions>
                                    <Grid.RowDefinitions>
                                       <RowDefinition Height="Auto"/>
                                       <RowDefinition/>
                                    </Grid.RowDefinitions>
                                    <ToggleButton x:Name="Expander" ClickMode="Press" IsChecked="{Binding IsExpanded, RelativeSource={RelativeSource TemplatedParent}}" Style="{StaticResource ExpandCollapseToggleStyle}"/>
                                    <Border x:Name="Bd" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" Grid.Column="1" Padding="{TemplateBinding Padding}" SnapsToDevicePixels="true">
                                       <ContentPresenter x:Name="PART_Header" ContentSource="Header" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
                                    </Border>
                                    <ItemsPresenter x:Name="ItemsHost" Grid.ColumnSpan="2" Grid.Column="1" Grid.Row="1"/>
                                    <Rectangle Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="4" HorizontalAlignment="Stretch" VerticalAlignment="Top" Fill="{DynamicResource OmagCut_TreeViewDelimiterColor}" Height="1" />
                                 </Grid>
                                 <ControlTemplate.Triggers>
                                    <Trigger Property="IsExpanded" Value="false">
                                       <Setter Property="Visibility" TargetName="ItemsHost" Value="Collapsed"/>
                                    </Trigger>
                                    <Trigger Property="HasItems" Value="false">
                                       <Setter Property="Visibility" TargetName="Expander" Value="Hidden"/>
                                    </Trigger>
                                    <Trigger Property="IsSelected" Value="true">
                                       <Setter Property="Background" TargetName="Bd" Value="Transparent"/>
                                       <Setter Property="BorderBrush" TargetName="Bd" Value="{DynamicResource {x:Static SystemColors.HighlightBrushKey}}"/>
                                       <Setter Property="BorderThickness" TargetName="Bd" Value="1"/>
                                       <!--<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.HighlightTextBrushKey}}"/>-->
                                    </Trigger>
                                    <!--<MultiTrigger>
                                       <MultiTrigger.Conditions>
                                          <Condition Property="IsSelected" Value="true"/>
                                          <Condition Property="IsSelectionActive" Value="false"/>
                                       </MultiTrigger.Conditions>
                                       <Setter Property="Background" TargetName="Bd" Value="{DynamicResource {x:Static SystemColors.ControlBrushKey}}"/>
                                       <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/>
                                    </MultiTrigger>-->
                                    <Trigger Property="IsEnabled" Value="false">
                                       <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/>
                                    </Trigger>
                                 </ControlTemplate.Triggers>
                              </ControlTemplate>
                           </Setter.Value>
                        </Setter>
                        <Style.Triggers>
                           <DataTrigger Binding="{Binding bIsActive}" Value="False">
                              <Setter Property="Foreground" Value="{StaticResource OmagCut_LightGray}"/>
                           </DataTrigger>
                        </Style.Triggers>
                     </Style>
                  </HierarchicalDataTemplate.ItemContainerStyle>
               </HierarchicalDataTemplate>
               <!--Modifico DataTemplate del ToolItem per poter inserire immagine e testo-->
               <DataTemplate DataType="{x:Type self:PartCustomItem}">
                  <Grid Width="246" Margin="0,5,0,5" HorizontalAlignment="Right">
                     <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="1*"/>
                        <ColumnDefinition Width="60"/>
                        <ColumnDefinition Width="1*"/>
                     </Grid.ColumnDefinitions>

                     <TextBlock Grid.Column="0" Text="{Binding Name}" Height="18" FontSize="14" HorizontalAlignment="Right"/>
                     <TextBlock Grid.Column="1" Text="{Binding sText1}" Height="18" FontSize="14" HorizontalAlignment="Center"/>
                     <TextBlock Grid.Column="2" Text="{Binding sText2}" Height="18" FontSize="14" HorizontalAlignment="Left"/>

                  </Grid>
               </DataTemplate>
            </TreeView.Resources>

            <!--Style dei nodi CathegoryItem che li riquadra di azzurro quando clicckati ed elimina l'ombra grigia -->
            <!--che si presenta quando la categoria rimane vuota (ombra causata dal multibinding). -->
            <TreeView.ItemContainerStyle>
               <Style TargetType="{x:Type TreeViewItem}">
                  <Setter Property="Foreground" Value="{DynamicResource OmagCut_TreeViewTextColor}" />
                  <Setter Property="IsSelected" Value="{Binding IsSelected}" />
                  <Setter Property="IsExpanded" Value="{Binding IsExpanded}" />
                  <Setter Property="Template">
                     <Setter.Value>
                        <ControlTemplate TargetType="{x:Type TreeViewItem}">
                           <Grid>
                              <Grid.ColumnDefinitions>
                                 <ColumnDefinition MinWidth="19" Width="Auto"/>
                                 <ColumnDefinition Width="Auto"/>
                                 <ColumnDefinition Width="*"/>
                              </Grid.ColumnDefinitions>
                              <Grid.RowDefinitions>
                                 <RowDefinition Height="Auto"/>
                                 <RowDefinition/>
                              </Grid.RowDefinitions>
                              <Border x:Name="ExpanderBorder" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" Padding="{TemplateBinding Padding}" SnapsToDevicePixels="true">
                                 <ToggleButton x:Name="Expander" ClickMode="Press" IsChecked="{Binding IsExpanded, RelativeSource={RelativeSource TemplatedParent}}" Style="{StaticResource ExpandCollapseToggleStyle}"/>
                              </Border>
                              <Border x:Name="Bd" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" Grid.Column="1" Padding="{TemplateBinding Padding}" SnapsToDevicePixels="true">
                                 <ContentPresenter x:Name="PART_Header" ContentSource="Header" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
                              </Border>
                              <ItemsPresenter x:Name="ItemsHost" Grid.ColumnSpan="2" Grid.Column="1" Grid.Row="1"/>
                              <Rectangle Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="4" HorizontalAlignment="Stretch" VerticalAlignment="Bottom" Fill="{DynamicResource OmagCut_TreeViewDelimiterColor}" Height="1" />
                           </Grid>
                           <ControlTemplate.Triggers>
                              <Trigger Property="IsExpanded" Value="false">
                                 <Setter Property="Visibility" TargetName="ItemsHost" Value="Collapsed"/>
                              </Trigger>
                              <Trigger Property="HasItems" Value="false">
                                 <Setter Property="Visibility" TargetName="Expander" Value="Hidden"/>
                              </Trigger>
                              <Trigger Property="IsSelected" Value="true">
                                 <Setter Property="Background" TargetName="Bd" Value="Transparent"/>
                                 <Setter Property="BorderBrush" TargetName="Bd" Value="{DynamicResource {x:Static SystemColors.HighlightBrushKey}}"/>
                                 <Setter Property="BorderThickness" TargetName="Bd" Value="0,1,1,1"/>
                                 <Setter Property="Background" TargetName="ExpanderBorder" Value="Transparent"/>
                                 <Setter Property="BorderBrush" TargetName="ExpanderBorder" Value="{DynamicResource {x:Static SystemColors.HighlightBrushKey}}"/>
                                 <Setter Property="BorderThickness" TargetName="ExpanderBorder" Value="1,1,0,1"/>
                                 <!--<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.HighlightTextBrushKey}}"/>-->
                              </Trigger>
                              <!--<MultiTrigger>
                                 <MultiTrigger.Conditions>
                                    <Condition Property="IsSelected" Value="true"/>
                                    <Condition Property="IsSelectionActive" Value="false"/>
                                 </MultiTrigger.Conditions>
                                 <Setter Property="Background" TargetName="Bd" Value="{DynamicResource {x:Static SystemColors.ControlBrushKey}}"/>
                                 <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/>
                              </MultiTrigger>-->
                              <Trigger Property="IsEnabled" Value="false">
                                 <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/>
                              </Trigger>
                           </ControlTemplate.Triggers>
                        </ControlTemplate>
                     </Setter.Value>
                  </Setter>
               </Style>
            </TreeView.ItemContainerStyle>
         </TreeView>

         <Grid Grid.Row="3">
            <Grid.ColumnDefinitions>
               <ColumnDefinition Width="1.*"/>
               <ColumnDefinition Width="1.*"/>
               <ColumnDefinition Width="1.*"/>
            </Grid.ColumnDefinitions>

            <Button Name="NewBtn" Grid.Column="0"
               Style="{DynamicResource OmagCut_YellowIconButton}">
               <Image Source="{DynamicResource CsvNewImg}" Width="65" Height="65" HorizontalAlignment="Center" VerticalAlignment="Center" />
            </Button>
            <Button Name="OpenBtn" Grid.Column="1"
               Style="{DynamicResource OmagCut_YellowIconButton}">
               <Image Source="{DynamicResource CsvOpenImg}" Width="65" Height="65" HorizontalAlignment="Center" VerticalAlignment="Center" />
            </Button>
            <Button Name="RuinedPartsBtn" Grid.Column="2"
               Style="{DynamicResource OmagCut_YellowIconButton}">
               <Image Source="{DynamicResource CsvRuinedPartsImg}" Width="65" Height="65" HorizontalAlignment="Center" VerticalAlignment="Center" />
            </Button>

         </Grid>

      </Grid>

      <!--Lower button grid, sfondo grigio per coprire i bottoni della pagina sottostante-->
      <Grid Grid.Column="1" Grid.Row="2" Background="{DynamicResource OmagCut_Gray}">
         <Grid.ColumnDefinitions>
            <ColumnDefinition Width="1*"/>
            <ColumnDefinition Width="1*"/>
            <ColumnDefinition Width="1*"/>
            <ColumnDefinition Width="1.5*"/>
            <ColumnDefinition Width="1.5*"/>
            <ColumnDefinition Width="5*"/>
            <ColumnDefinition Width="1*"/>
         </Grid.ColumnDefinitions>

         <ToggleButton Name="PlusBtn" Grid.Column="0"
            Style="{DynamicResource OmagCut_YellowIconToggleButton}">
            <Image Source="{DynamicResource CsvPlusImg}" Width="65" Height="65" HorizontalAlignment="Center" VerticalAlignment="Center" />
         </ToggleButton>
         <ToggleButton Name="MinusBtn" Grid.Column="1"
            Style="{DynamicResource OmagCut_YellowIconToggleButton}">
            <Image Source="{DynamicResource CsvMinusImg}" Width="65" Height="65" HorizontalAlignment="Center" VerticalAlignment="Center" />
         </ToggleButton>
         <Button Name="InsertBtn" Grid.Column="3" Style="{DynamicResource OmagCut_YellowTextButton}" />
         <Button Name="RemoveBtn" Grid.Column="4" Style="{DynamicResource OmagCut_YellowTextButton}" />

         <Button Name="OkBtn" Grid.Column="6" Style="{DynamicResource OmagCut_GradientBlueIconButton}">
            <Image Source="{DynamicResource VImg}" Style="{StaticResource OmagCut_ButtonIcon}" />
         </Button>



      </Grid>

   </Grid>
</UserControl>
