<EgtWPFLib5:EgtCustomWindow x:Class="OnlyProdSetUpWindowV"
                            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"
                            Title="{Binding TitleMsg}"
                            WindowStyle="None" ResizeMode="NoResize" TitleBarHeight="30" IsResizable="False"
                            IsMinimizable="False" WindowStartupLocation="CenterOwner" ShowInTaskbar="False"
                            CloseCommand="{Binding CloseSetUpCommand, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}"
                            Style="{StaticResource OnlyProd_EgtCustomWindow}">

   <EgtWPFLib5:EgtCustomWindow.Resources>
      <Style x:Key="HorizontalScrollViewerItemsControlStyle" TargetType="{x:Type ItemsControl}">
         <Setter Property="ItemsPanel">
            <Setter.Value>
               <ItemsPanelTemplate>
                  <WrapPanel Orientation="Vertical"/>
               </ItemsPanelTemplate>
            </Setter.Value>
         </Setter>
         <Setter Property="Template">
            <Setter.Value>
               <ControlTemplate TargetType="{x:Type ItemsControl}">
                  <ScrollViewer HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Disabled" >
                     <ItemsPresenter/>
                  </ScrollViewer>
               </ControlTemplate>
            </Setter.Value>
         </Setter>
      </Style>
   </EgtWPFLib5:EgtCustomWindow.Resources>

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

      <Grid>
         <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="1*"/>
         </Grid.RowDefinitions>

         <UniformGrid Columns="4">
            <Button Content="{Binding ApplyMsg}" Command="{Binding ApplyCommand}"
                    IsEnabled="{Binding IsEnabledApplyBtn}" Height="30"
                    Style="{StaticResource OnlyRightPanel_HalfRound_Button}"/>
            <Button Content="{Binding ArchiveMsg}" Command="{Binding ArchiveCommand}" Height="30"
                    Style="{StaticResource OnlyRightPanel_HalfRound_Button}"/>
            <Button Content="{Binding RetrievesMsg}" Command="{Binding RetrievesCommand}" Height="30" 
                    CommandParameter="{Binding SelectedItem,ElementName=ToolsTreeView}"
                    Style="{StaticResource OnlyRightPanel_HalfRound_Button}"/>
            <Button Content="{Binding AutomaticMsg}" Command="{Binding AutomaticCommand}" Height="30"
                    CommandParameter="{Binding SelectedItem,ElementName=ToolsTreeView}"
                    Style="{StaticResource OnlyRightPanel_HalfRound_Button}"/>
         </UniformGrid>

         <TreeView Grid.Row="1" Name="ToolsTreeView" ItemsSource="{Binding ToolsList}">
            <TreeView.Style>
               <Style TargetType="{x:Type TreeView}">
                  <Setter Property="Background">
                     <Setter.Value>
                        <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.35,0">
                           <GradientStop Color="{StaticResource BeamWall_Mercury_Color}" Offset="0"/>
                           <GradientStop Color="{StaticResource BeamWall_Concrete_Color}" Offset="0.45"/>
                           <GradientStop Color="{StaticResource BeamWall_White_Color}" Offset="1"/>
                        </LinearGradientBrush>
                     </Setter.Value>
                  </Setter>
               </Style>
            </TreeView.Style>

            <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="Tool_DoubleClick"/>
               </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 Grid.Column="1">
         <Grid.ColumnDefinitions>
            <ColumnDefinition Width="Auto"/>
            <ColumnDefinition Width="1*"/>
         </Grid.ColumnDefinitions>

         <Image Source="{Binding SetUpImage}" MaxWidth="300"/>

         <ItemsControl Grid.Column="1" ItemsSource="{Binding PositionGroupList}"
                       Style="{DynamicResource 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}"/>
                                          <Border x:Name="ToolBorder" Grid.Column="1" BorderBrush="#4D84C4"
                                                  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>

</EgtWPFLib5:EgtCustomWindow>
