<Grid x:Class="TopPanelV"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      xmlns:EgtBEAMWALL="clr-namespace:EgtBEAMWALL.ViewerOptimizer"
      MinHeight="50">

   <TabControl SelectedIndex="{Binding SelTab}"
               TabStripPlacement="Right"
               Margin="5">
      <TabControl.ItemContainerStyle>
         <Style TargetType="{x:Type TabItem}">
            <Setter Property="Visibility" Value="Collapsed"/>
         </Style>
      </TabControl.ItemContainerStyle>
      <TabItem Header="OPTIMIZATION">
         <TabItem.Content>
            <Grid>
               <Grid.ColumnDefinitions>
                  <ColumnDefinition Width="{Binding GridDims[0].GridLen, Mode=TwoWay}"/>
                  <ColumnDefinition Width="Auto"/>
                  <ColumnDefinition Width="{Binding GridDims[1].GridLen, Mode=TwoWay}"/>
               </Grid.ColumnDefinitions>
               <Grid>
                  <Grid.ColumnDefinitions>
                     <ColumnDefinition Width="Auto"/>
                     <ColumnDefinition Width="1*"/>
                  </Grid.ColumnDefinitions>
                  <Grid.RowDefinitions>
                     <RowDefinition Height="{Binding GridDims[2].GridLen, Mode=TwoWay}"/>
                     <RowDefinition Height="Auto"/>
                     <RowDefinition Height="{Binding GridDims[3].GridLen, Mode=TwoWay}"/>
                  </Grid.RowDefinitions>
                  <StackPanel Orientation="Vertical"
                  HorizontalAlignment="Right">
                     <Button Command="{Binding ProduceRawPart_Command}"
                             ToolTip="{Binding ProduceRawPart_ToolTip}"
                             IsEnabled="{Binding TopPanel_IsEnabled}"
                             Style="{StaticResource LeftPanel_Button}"
                             Visibility="{Binding ProduceRawPart_Visibility}">
                        <Image Source="/Resources/TopPanel/ProduceRawPart.png" Stretch="Uniform"/>
                     </Button>
                     <Button Command="{Binding ProduceAllRawPart_Command}"
                             ToolTip="{Binding ProduceAllRawPart_ToolTip}"
                             IsEnabled="{Binding TopPanel_IsEnabled}"
                             Style="{StaticResource LeftPanel_Button}"
                             Visibility="{Binding ProduceRawPart_Visibility}">
                        <Image Source="/Resources/TopPanel/ProduceAllRawPart.png" Stretch="Uniform"/>
                     </Button>
                     <Button Command="{Binding CopyRawPart_Command}"
                             ToolTip="{Binding CopyRawPart_ToolTip}"
                             IsEnabled="{Binding TopPanel_IsEnabled}"
                             Style="{StaticResource LeftPanel_Button}">
                        <Image Source="/Resources/TopPanel/CopyRawPart.png" Stretch="Uniform"/>
                     </Button>
                     <Button Command="{Binding RemoveRawPart_Command}"
                             ToolTip="{Binding RemoveRawPart_ToolTip}"
                             IsEnabled="{Binding TopPanel_IsEnabled}"
                             Style="{StaticResource LeftPanel_Button}">
                        <Image Source="/Resources/TopPanel/RemoveRawPart.png" Stretch="Uniform"/>
                     </Button>
                     <Button Command="{Binding RemoveAllRawPart_Command}"
                             ToolTip="{Binding RemoveAllRawPart_ToolTip}"
                             IsEnabled="{Binding TopPanel_IsEnabled}"
                             Style="{StaticResource LeftPanel_Button}">
                        <Image Source="/Resources/TopPanel/RemoveAllRawPart.png" Stretch="Uniform"/>
                     </Button>
                     <Button Command="{Binding MovePartInRawPart_Command}"
                             ToolTip="{Binding MovePartInRawPart_ToolTip}"
                             IsEnabled="{Binding TopPanel_IsEnabled}"
                             Style="{StaticResource LeftPanel_Button}"
                             Visibility="{Binding MovePartInRawPart_Visibility}">
                        <Image Source="/Resources/TopPanel/MovePartInRawPart.png" Stretch="Uniform"/>
                     </Button>
                  </StackPanel>

                  <EgtBEAMWALL:RawPartListV Grid.Column="1"
                                            DataContext="{StaticResource RawPartListVM}"
                                            Tag="{Binding Tag.MachGroupPanelVM, RelativeSource={RelativeSource AncestorType={x:Type EgtBEAMWALL:TopPanelV}}}"/>
                  <GridSplitter Height="3" HorizontalAlignment="Stretch" Grid.Row="1" Grid.ColumnSpan="2"/>
                  <StackPanel Grid.Row="2"
                              Orientation="Vertical"
                              HorizontalAlignment="Right">
                     <Button Command="{Binding ReOrderPart_Command}"
                             Visibility="{Binding MovePart_Visibility}"
                             ToolTip="{Binding ReOrderPart_ToolTip}"
                             IsEnabled="{Binding TopPanel_IsEnabled}"
                             Style="{StaticResource LeftPanel_Button}">
                        <Image Source="/Resources/TopPanel/ReOrderPart.png" Stretch="Uniform"/>
                     </Button>
                     <Button Command="{Binding MoveUpPart_Command}"
                             Visibility="{Binding MovePart_Visibility}"
                             ToolTip="{Binding MoveUpPart_ToolTip}"
                             IsEnabled="{Binding TopPanel_IsEnabled}"
                             Style="{StaticResource LeftPanel_Button}">
                        <Image Source="/Resources/TopPanel/MoveUpPart.png" Stretch="Uniform"/>
                     </Button>
                     <Button Command="{Binding MoveDownPart_Command}"
                             Visibility="{Binding MovePart_Visibility}"
                             ToolTip="{Binding MoveDownPart_ToolTip}"
                             IsEnabled="{Binding TopPanel_IsEnabled}"
                             Style="{StaticResource LeftPanel_Button}">
                        <Image Source="/Resources/TopPanel/MoveDownPart.png" Stretch="Uniform"/>
                     </Button>
                     <Button Command="{Binding RemovePart_Command}"
                             ToolTip="{Binding RemovePart_ToolTip}"
                             IsEnabled="{Binding TopPanel_IsEnabled}"
                             Style="{StaticResource LeftPanel_Button}">
                        <Image Source="/Resources/TopPanel/RemovePart.png" Stretch="Uniform"/>
                     </Button>
                  </StackPanel>
                  <EgtBEAMWALL:PartInRawPartListV Grid.Column="1" Grid.Row="2"
                                                  DataContext="{StaticResource PartInRawPartListVM}"
                                                  Tag="{Binding Tag.MachGroupPanelVM.SelectedMachGroup, RelativeSource={RelativeSource AncestorType={x:Type EgtBEAMWALL:TopPanelV}}}"
                                                  Margin="0,0,5,0"/>
               </Grid>
               <GridSplitter Width="3" HorizontalAlignment="Center" VerticalAlignment="Stretch" Grid.Column="1"/>
               <Grid Grid.Column="2">
                  <Grid.RowDefinitions>
                     <RowDefinition Height="{Binding GridDims[4].GridLen, Mode=TwoWay}"/>
                     <RowDefinition Height="Auto"/>
                     <RowDefinition Height="{Binding GridDims[5].GridLen, Mode=TwoWay}"/>
                     <RowDefinition Height="Auto"/>
                     <RowDefinition Height="Auto"/>
                     <RowDefinition Height="Auto"/>
                  </Grid.RowDefinitions>
                  <Grid.Resources>
                     <Style TargetType="TextBlock">
                        <Style.Triggers>
                           <Trigger Property="Text" Value="">
                              <Setter Property="Visibility" Value="Collapsed"/>
                           </Trigger>
                        </Style.Triggers>
                     </Style>
                  </Grid.Resources>
                  <EgtBEAMWALL:FeatureInPartInRawPartListV Grid.Row="0"
                                                           DataContext="{StaticResource FeatureInPartInRawPartListVM}"
                                                           Tag="{Binding Tag.MachGroupPanelVM.SelectedMachGroup.SelPart, RelativeSource={RelativeSource AncestorType={x:Type EgtBEAMWALL:TopPanelV}}}"/>
                  <GridSplitter Height="3"
                                HorizontalAlignment="Stretch"
                                Grid.Row="1"
                                Visibility="{Binding QParSplitter_Visibility}"/>
                  <EgtBEAMWALL:QParameterListV Grid.Row="2"
                                               DataContext="{StaticResource DuploQParameterListVM}"
                                               Tag="{Binding Tag.MachGroupPanelVM.SelectedMachGroup.SelPart.SelFeatureVM, RelativeSource={RelativeSource AncestorType={x:Type EgtBEAMWALL:TopPanelV}}}"
                                               Visibility="{Binding DataContext.QParameter_Visibility, RelativeSource={RelativeSource AncestorType={x:Type EgtBEAMWALL:TopPanelV}}}"/>
                  <TextBlock Grid.Row="3"
                             Text="{Binding Tag.MachGroupPanelVM.SelectedMachGroup.sCALC_MSG, RelativeSource={RelativeSource AncestorType={x:Type EgtBEAMWALL:TopPanelV}}}"
                             Margin="5,0,5,0"
                             Foreground="{Binding Tag.MachGroupPanelVM.SelectedMachGroup.Calc_Background, RelativeSource={RelativeSource AncestorType={x:Type EgtBEAMWALL:TopPanelV}}}"/>
                  <TextBlock Grid.Row="4"
                             Text="{Binding Tag.MachGroupPanelVM.SelectedMachGroup.SelPart.sCALC_MSG, RelativeSource={RelativeSource AncestorType={x:Type EgtBEAMWALL:TopPanelV}}}"
                             Margin="5,0,5,0"
                             Foreground="{Binding Tag.MachGroupPanelVM.SelectedMachGroup.SelPart.Calc_Background, RelativeSource={RelativeSource AncestorType={x:Type EgtBEAMWALL:TopPanelV}}}"/>
                  <TextBlock Grid.Row="5"
                             Text="{Binding Tag.MachGroupPanelVM.SelectedMachGroup.SelPart.SelFeatureVM.sCALC_MSG, RelativeSource={RelativeSource AncestorType={x:Type EgtBEAMWALL:TopPanelV}}}"
                             Margin="5,0,5,0"
                             Foreground="{Binding Tag.MachGroupPanelVM.SelectedMachGroup.SelPart.SelFeatureVM.Calc_Background, RelativeSource={RelativeSource AncestorType={x:Type EgtBEAMWALL:TopPanelV}}}"/>
               </Grid>
            </Grid>
         </TabItem.Content>
      </TabItem>
      <TabItem Header="STATISTICS">
         <TabItem.Content>
            <EgtBEAMWALL:OptimizerStatisticsV DataContext="{StaticResource StatisticsVM}"
                                              Tag="{Binding Tag, RelativeSource={RelativeSource AncestorType={x:Type EgtBEAMWALL:TopPanelV}}}"
                                              Margin="5"/>
         </TabItem.Content>
      </TabItem>

   </TabControl>

</Grid>
