<UserControl x:Class="BTLPartListV"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:EgtBEAMWALL="clr-namespace:EgtBEAMWALL.ViewerOptimizer" 
             xmlns:EgtBEAMWALLCORE="clr-namespace:EgtBEAMWALL.Core;assembly=EgtBEAMWALL.Core">
   <EgtBEAMWALLCORE:EgtDataGrid x:Name="BTLPart_DataGrid"
                                ItemsSource="{Binding Tag.BTLPartVMList,
                                                      RelativeSource={RelativeSource AncestorType={x:Type EgtBEAMWALL:BTLPartListV}}}"
                                CanUserAddRows="False"
                                AutoGenerateColumns="False"
                                CanUserResizeRows="False"
                                SelectionMode="Extended"
                                ScrollViewer.CanContentScroll="True" 
                                ScrollViewer.VerticalScrollBarVisibility="Auto"
                                ScrollViewer.HorizontalScrollBarVisibility="Auto"
                                PreviewMouseDown="DataGrid_PreviewMouseDown"
                                PreviewMouseUp="DataGrid_PreviewMouseUp"
                                PreviewMouseMove="DataGrid_PreviewMouseMove"
                                Margin="0,0,0,5"
                                EgtBEAMWALL:MultiSelectorBehaviours.SynchronizedSelectedItems="{Binding Tag.SelBTLParts,
                                                                                                        RelativeSource={RelativeSource AncestorType={x:Type EgtBEAMWALL:BTLPartListV}}}"
                                BindingColumns="{Binding PartColumns}"
                                IsEnabled="{Binding PartList_IsEnabled}"
                                Style="{StaticResource DataGrid_CustomHighLight}">

      <DataGrid.InputBindings>
         <KeyBinding Key="Delete" Command="{Binding Tag.DeletePart_Command,
                                                    RelativeSource={RelativeSource AncestorType={x:Type EgtBEAMWALL:BTLPartListV}}}" />
      </DataGrid.InputBindings>
      <DataGrid.Resources>
         <!--PDN - Nome-->
         <DataGridTextColumn x:Key="colPDN"
                             Binding="{Binding nPDN}">
            <DataGridTextColumn.Header>
               <TextBlock Text="{Binding Path=DataContext.PDN_Msg,RelativeSource={RelativeSource AncestorType={x:Type EgtBEAMWALL:BTLPartListV}}}"/>
            </DataGridTextColumn.Header>
         </DataGridTextColumn>
         <!--Validità pezzo-->
         <DataGridTemplateColumn x:Key="colCALC" CanUserResize="False"
                                 SortMemberPath="nGlobalState">
            <DataGridTemplateColumn.CellTemplate>
               <DataTemplate>
                  <Grid>
                     <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="Auto"/>
                        <ColumnDefinition Width="25"/>
                        <ColumnDefinition Width="Auto"/>
                     </Grid.ColumnDefinitions>
                     <TextBlock Text="↓"
                                Foreground="Blue"
                                TextAlignment="Center"
                                FontWeight="Bold"
                                FontSize="18"
                                Margin="-1,-6,1,-3"
                                Visibility="{Binding CALC_FALL_Visibility}"/>
                     <Border Grid.Column="1"
                             BorderBrush="{Binding Calc_BorderBrush}"
                             BorderThickness="2"
                             Padding="1">
                        <ItemsControl ItemsSource="{Binding BTLFeatureVMList_View}"
                                      Margin="0"
                                      Padding="0">
                           <ItemsControl.ItemsPanel>
                              <ItemsPanelTemplate>
                                 <UniformGrid Columns="6" Rows="5"
                                              Margin="0"/>
                              </ItemsPanelTemplate>
                           </ItemsControl.ItemsPanel>
                           <ItemsControl.ItemTemplate>
                              <DataTemplate>
                                 <Border Background="{Binding Calc_Background}"/>
                              </DataTemplate>
                           </ItemsControl.ItemTemplate>
                        </ItemsControl>
                     </Border>
                     <Grid Grid.Column="2"
                           HorizontalAlignment="Center">
                        <Grid.ColumnDefinitions>
                           <ColumnDefinition Width="Auto"/>
                        </Grid.ColumnDefinitions>
                        <Grid.RowDefinitions>
                           <RowDefinition Height="1*"/>
                           <RowDefinition Height="Auto"/>
                        </Grid.RowDefinitions>
                        <Ellipse Width="5"
                                 Height="5"
                                 Fill="Red"
                                 Visibility="{Binding CALC_ROT_Visibility}"
                                 HorizontalAlignment="Center"
                                 VerticalAlignment="Top"
                                 Margin="2,1,-2,0"/>
                        <TextBlock Grid.Row="1"
                                   Text="{Binding CALC_ERR_Letter}"
                                   Foreground="{Binding CALC_ERR_Foreground}"
                                   TextAlignment="Center"
                                   FontWeight="Bold"
                                   FontSize="12"
                                   Margin="2,-6,-2,-3"/>
                     </Grid>
                  </Grid>
               </DataTemplate>
            </DataGridTemplateColumn.CellTemplate>
         </DataGridTemplateColumn>
         <!--DO - Abilitazione-->
         <DataGridCheckBoxColumn x:Key="colDO" Binding="{Binding bDO, UpdateSourceTrigger=PropertyChanged}"
                                 MinWidth="28">
            <DataGridCheckBoxColumn.Header>
               <CheckBox IsChecked="{Binding Path=Tag.bDOALL, RelativeSource={RelativeSource AncestorType={x:Type EgtBEAMWALL:BTLPartListV}}}"
                         HorizontalAlignment="Center"/>
            </DataGridCheckBoxColumn.Header>
         </DataGridCheckBoxColumn>
         <!--W - Larghezza-->
         <DataGridTextColumn x:Key="colW" Binding="{Binding sW}" SortMemberPath="dW">
            <DataGridTextColumn.Header>
               <TextBlock Text="{Binding Path=DataContext.W_Msg,RelativeSource={RelativeSource AncestorType={x:Type EgtBEAMWALL:BTLPartListV}}}"/>
            </DataGridTextColumn.Header>
         </DataGridTextColumn>
         <!--H - Altezza-->
         <DataGridTextColumn x:Key="colH" Binding="{Binding sH}" SortMemberPath="dH">
            <DataGridTextColumn.Header>
               <TextBlock Text="{Binding Path=DataContext.H_Msg,RelativeSource={RelativeSource AncestorType={x:Type EgtBEAMWALL:BTLPartListV}}}"/>
            </DataGridTextColumn.Header>
         </DataGridTextColumn>
         <!--L - Lunghezza-->
         <DataGridTextColumn x:Key="colL" Binding="{Binding sL}" SortMemberPath="dL">
            <DataGridTextColumn.Header>
               <TextBlock Text="{Binding Path=DataContext.L_Msg,RelativeSource={RelativeSource AncestorType={x:Type EgtBEAMWALL:BTLPartListV}}}"/>
            </DataGridTextColumn.Header>
         </DataGridTextColumn>
         <!--NAM - Descrizione-->
         <DataGridTextColumn x:Key="colNAM" Binding="{Binding sNAM}">
            <DataGridTextColumn.Header>
               <TextBlock Text="{Binding Path=DataContext.NAM_Msg,RelativeSource={RelativeSource AncestorType={x:Type EgtBEAMWALL:BTLPartListV}}}"/>
            </DataGridTextColumn.Header>
         </DataGridTextColumn>
         <!--MAT - Materiale-->
         <DataGridTextColumn x:Key="colMATERIAL" Binding="{Binding sMATERIAL}">
            <DataGridTextColumn.Header>
               <TextBlock Text="{Binding Path=DataContext.MAT_Msg,RelativeSource={RelativeSource AncestorType={x:Type EgtBEAMWALL:BTLPartListV}}}"/>
            </DataGridTextColumn.Header>
         </DataGridTextColumn>
         <!--CNT - Richiesti da BTL-->
         <DataGridTextColumn x:Key="colCNT" Binding="{Binding sCNT}" SortMemberPath="nCNT">
            <DataGridTextColumn.Header>
               <TextBlock Text="{Binding Path=DataContext.ShortCNT_Msg,RelativeSource={RelativeSource AncestorType={x:Type EgtBEAMWALL:BTLPartListV}}}"
                          ToolTip="{Binding Path=DataContext.CNT_Msg,RelativeSource={RelativeSource AncestorType={x:Type EgtBEAMWALL:BTLPartListV}}}"/>
            </DataGridTextColumn.Header>
         </DataGridTextColumn>
         <!--ADDED - Aggiunti-->
         <DataGridTextColumn x:Key="colADDED" Binding="{Binding sADDED}" SortMemberPath="nADDED">
            <DataGridTextColumn.Header>
               <TextBlock Text="{Binding Path=DataContext.ShortADDED_Msg,RelativeSource={RelativeSource AncestorType={x:Type EgtBEAMWALL:BTLPartListV}}}"
                          ToolTip="{Binding Path=DataContext.ADDED_Msg,RelativeSource={RelativeSource AncestorType={x:Type EgtBEAMWALL:BTLPartListV}}}"/>
            </DataGridTextColumn.Header>
            <DataGridTextColumn.EditingElementStyle>
               <Style TargetType="{x:Type TextBox}">
                  <Setter Property="Foreground" Value="Blue" />
               </Style>
            </DataGridTextColumn.EditingElementStyle>
         </DataGridTextColumn>
         <!--INPROD - IN OTTIMIZZAZIONE-->
         <DataGridTextColumn x:Key="colINPROD" Binding="{Binding nINPROD}">
            <DataGridTextColumn.Header>
               <TextBlock Text="{Binding Path=DataContext.ShortINPROD_Msg,RelativeSource={RelativeSource AncestorType={x:Type EgtBEAMWALL:BTLPartListV}}}"
                          ToolTip="{Binding Path=DataContext.INPROD_Msg,RelativeSource={RelativeSource AncestorType={x:Type EgtBEAMWALL:BTLPartListV}}}"/>
            </DataGridTextColumn.Header>
         </DataGridTextColumn>
         <!--DONE - PRODOTTI-->
         <DataGridTextColumn x:Key="colDONE" Binding="{Binding nDONE}">
            <DataGridTextColumn.Header>
               <TextBlock Text="{Binding Path=DataContext.ShortDONE_Msg,RelativeSource={RelativeSource AncestorType={x:Type EgtBEAMWALL:BTLPartListV}}}"
                          ToolTip="{Binding Path=DataContext.DONE_Msg,RelativeSource={RelativeSource AncestorType={x:Type EgtBEAMWALL:BTLPartListV}}}"/>
            </DataGridTextColumn.Header>
         </DataGridTextColumn>
         <!--TBP - In produzione-->
         <!--<DataGridTextColumn Binding="{Binding nTBP}"
                               IsReadOnly="True">
             <DataGridTextColumn.Header>
                     <TextBlock Text="{Binding Path=DataContext.TBP_Msg,RelativeSource={RelativeSource AncestorType={x:Type EgtBEAMWALL:PartListV}}}"/>
             </DataGridTextColumn.Header>
         </DataGridTextColumn>-->
         <!--DON - Prodotti-->
         <!--<DataGridTextColumn Binding="{Binding nDON}"
                               IsReadOnly="True">
             <DataGridTextColumn.Header>
                     <TextBlock Text="{Binding Path=DataContext.DON_Msg,RelativeSource={RelativeSource AncestorType={x:Type EgtBEAMWALL:PartListV}}}"/>
             </DataGridTextColumn.Header>
         </DataGridTextColumn>-->
         <!--ROT - Ruotare-->
         <!--<DataGridTextColumn Binding="{Binding nROT}"
                               IsReadOnly="True">
             <DataGridTextColumn.Header>
                     <TextBlock Text="{Binding Path=DataContext.ROT_Msg,RelativeSource={RelativeSource AncestorType={x:Type EgtBEAMWALL:PartListV}}}"/>
             </DataGridTextColumn.Header>
         </DataGridTextColumn>-->
         <!--GRP - Gruppo-->
         <DataGridTextColumn x:Key="colGROUP" Binding="{Binding sGROUP}">
            <DataGridTextColumn.Header>
               <TextBlock Text="{Binding Path=DataContext.GRP_Msg,RelativeSource={RelativeSource AncestorType={x:Type EgtBEAMWALL:BTLPartListV}}}"/>
            </DataGridTextColumn.Header>
         </DataGridTextColumn>
         <!--STOREY - Sottogruppo-->
         <DataGridTextColumn x:Key="colSTOREY" Binding="{Binding sSTOREY}">
            <DataGridTextColumn.Header>
               <TextBlock Text="{Binding Path=DataContext.STOREY_Msg,RelativeSource={RelativeSource AncestorType={x:Type EgtBEAMWALL:BTLPartListV}}}"/>
            </DataGridTextColumn.Header>
         </DataGridTextColumn>
         <!--UNT - Unit Time-->
         <!--<DataGridTextColumn Binding="{Binding nUNT}"
                               IsReadOnly="True">
             <DataGridTextColumn.Header>
                     <TextBlock Text="{Binding Path=DataContext.UNT_Msg,RelativeSource={RelativeSource AncestorType={x:Type EgtBEAMWALL:PartListV}}}"/>
             </DataGridTextColumn.Header>
         </DataGridTextColumn>-->
      </DataGrid.Resources>
      <DataGrid.RowStyle>
         <Style TargetType="DataGridRow" BasedOn="{StaticResource RowDataGrid_CustomHighLight}">
            <Setter Property="Background" Value="{Binding Background}"/>
            <Setter Property="Foreground" Value="{Binding Foreground}"/>
            <Setter Property="FontWeight" Value="{Binding FontWeight}"/>
            <!--<Setter Property="IsSelected" Value="{Binding IsSelected, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>-->
            <EventSetter Event="PreviewMouseDown" Handler="PartList_PreviewMouseDown"/>
            <EventSetter Event="PreviewMouseUp" Handler="PartList_PreviewMouseUp"/>
         </Style>
      </DataGrid.RowStyle>

   </EgtBEAMWALLCORE:EgtDataGrid>
</UserControl>
