<UserControl x:Class="SetUpV"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:EgtWPFLib5="clr-namespace:EgtWPFLib5;assembly=EgtWPFLib5">

   <Grid>
      <Grid.ColumnDefinitions>
         <ColumnDefinition Width="3*"/>
         <ColumnDefinition Width="1*"/>
      </Grid.ColumnDefinitions>
      
      <TreeView Grid.Column="1" 
                Name="ToolsTreeView" 
                ItemsSource="{Binding ToolsList}"
                Margin="5">
         
         <!--<interactivity:Interaction.Triggers>
            <interactivity:EventTrigger EventName="MouseDoubleClick">
               <interactivity:InvokeCommandAction Command="{Binding ToolDoubleClickCommand}" CommandParameter="{Binding ElementName=ToolsTreeView,Path=SelectedItem}"/>
            </interactivity:EventTrigger>
         </interactivity:Interaction.Triggers>-->

         <TreeView.ItemContainerStyle>
            <Style TargetType="{x:Type TreeViewItem}">
               <Setter Property="IsSelected" Value="{Binding IsSelected, Mode=TwoWay}" />
               <Setter Property="IsExpanded" Value="{Binding IsExpanded, Mode=TwoWay}" />
               <EventSetter Event="MouseDoubleClick" Handler="TreeViewItem_MouseDoubleClick"/>
            </Style>
         </TreeView.ItemContainerStyle>

         <TreeView.Resources>
            <HierarchicalDataTemplate DataType="{x:Type EgtWPFLib5:FamilyToolItem}" ItemsSource="{Binding Items}">

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

                  <Image Grid.Column="0" Source="{Binding PictureString}" Height="20" Width="20" Margin="0,0,5,0" />
                  <TextBlock Grid.Column="1" Text="{Binding Name}" FontSize="15" Margin="0,-2,5,0" VerticalAlignment="Center" />
                  <Ellipse Grid.Column="2" Height="10" Width="10" Fill="{Binding FamilyColor}" />

               </Grid>

            </HierarchicalDataTemplate>

            <DataTemplate DataType="{x:Type EgtWPFLib5:ToolItem}">
               <Grid Height="20" ToolTip="{Binding ToolTipMsg}">
                  <Grid.ColumnDefinitions>
                     <ColumnDefinition Width="Auto"/>
                     <ColumnDefinition Width="1*"/>
                     <ColumnDefinition Width="Auto"/>
                  </Grid.ColumnDefinitions>

                  <!--<Image Grid.Column="0" Source="{Binding PictureString}" Height="32" Margin="0,8,6,4" />-->
                  <TextBlock Grid.Column="1" Text="{Binding Name}" FontSize="15" Margin="0,-2,5,0" VerticalAlignment="Center" />
                  <Ellipse Grid.Column="2" Height="10" Width="10" Fill="{Binding ToolColor}" />

               </Grid>
            </DataTemplate>

         </TreeView.Resources>

      </TreeView>


      <Grid Grid.Column="0" Margin="5,0,0,5">
         <Grid.ColumnDefinitions>
            <ColumnDefinition Width="Auto"/>
            <ColumnDefinition Width="1*"/>
         </Grid.ColumnDefinitions>
      
         <Image Source="{Binding SetUpImage}" MaxWidth="300"/>

         <ItemsControl Grid.Column="1" ItemsSource="{Binding PositionGroupList}"
            Style="{StaticResource HorizontalScrollViewerItemsControlStyle}">
            <ItemsControl.ItemsPanel>
               <ItemsPanelTemplate>
                  <StackPanel Orientation="Horizontal"/>
               </ItemsPanelTemplate>
            </ItemsControl.ItemsPanel>
            <ItemsControl.ItemTemplate>
               <DataTemplate>

                  <ItemsControl Grid.Column="1" ItemsSource="{Binding PositionList}" Margin="0,0,20,0">
                     <ItemsControl.ItemsPanel>
                        <ItemsPanelTemplate>
                           <WrapPanel Orientation="Vertical"/>
                        </ItemsPanelTemplate>
                     </ItemsControl.ItemsPanel>
                     <ItemsControl.ItemTemplate>
                        <DataTemplate>
                           <Grid Margin="5,5,15,5">
                              <Grid.ColumnDefinitions>
                                 <ColumnDefinition Width="30"/>
                                 <ColumnDefinition Width="1*"/>
                              </Grid.ColumnDefinitions>

                              <TextBlock Text="{Binding TcPos}"/>
                              <ItemsControl Grid.Column="1" ItemsSource="{Binding ExitToolAssociationList}"
                                 HorizontalAlignment="Left">
                                 <ItemsControl.ItemsPanel>
                                    <ItemsPanelTemplate>
                                       <!--<WrapPanel Orientation="Horizontal" MaxWidth="200"/>-->
                                       <UniformGrid Columns="1"/>
                                    </ItemsPanelTemplate>
                                 </ItemsControl.ItemsPanel>
                                 <ItemsControl.ItemTemplate>
                                    <DataTemplate>
                                       <Grid Margin="10,0,0,5">
                                          <Grid.ColumnDefinitions>
                                             <ColumnDefinition Width="Auto"/>
                                             <ColumnDefinition Width="1*"/>
                                          </Grid.ColumnDefinitions>

                                          <ToggleButton Content="{Binding ExitPar}" Name="ExitBtn"
                                             CommandParameter="{Binding SelectedItem,ElementName=ToolsTreeView}"
                                             IsChecked="{Binding IsOccupied}" Height="25" Width="25" Margin="0,0,5,0"
                                             Command="{Binding SetUpToolCommand}"
                                             IsEnabled="{Binding IsEnabledPos}"
                                             Background="{Binding ExitBtnBackgroundCol}"
                                             Style="{StaticResource EgtCAM5_SetUpToggleButton}"/>
                                          <Border x:Name="ToolBorder" Grid.Column="1" BorderBrush="{StaticResource EgaltechBlue1}"
                                             BorderThickness="1" ToolTip="{Binding ToolTipMsg}">
                                             <Border.Style>
                                                <Style TargetType="{x:Type Border}">
                                                   <Setter Property="Visibility" Value="Hidden"/>
                                                   <Style.Triggers>
                                                      <DataTrigger Binding="{Binding ElementName=ExitBtn, Path=IsChecked}" Value="True">
                                                         <Setter Property="Visibility" Value="Visible"/>
                                                      </DataTrigger>
                                                   </Style.Triggers>
                                                </Style>
                                             </Border.Style>
                                             <TextBlock  Text="{Binding Tool.Name}" Margin="3"/>
                                          </Border>

                                       </Grid>
                                    </DataTemplate>
                                 </ItemsControl.ItemTemplate>
                              </ItemsControl>

                           </Grid>
                        </DataTemplate>
                     </ItemsControl.ItemTemplate>
                  </ItemsControl>

               </DataTemplate>
            </ItemsControl.ItemTemplate>
         </ItemsControl>

      </Grid>

   </Grid>

</UserControl>
