<Window x:Class="Mercat_1.Window1"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:dotNetKitControls="clr-namespace:DotNetKit.Windows.Controls;assembly=DotNetKit.Wpf.AutoCompleteComboBox"
        xmlns:local="clr-namespace:Mercat_1" WindowStartupLocation="CenterScreen" 
        mc:Ignorable="d"
        Title="Nou Moviment de material" Height="609" Width="621">
    <Window.Resources>
        <ResourceDictionary>
            <!-- This style applies to all auto-complete comboboxes in the window by default. -->
            <Style TargetType="dotNetKitControls:AutoCompleteComboBox">
                <Setter Property="ItemsPanel">
                    <Setter.Value>
                        <ItemsPanelTemplate>
                            <VirtualizingStackPanel />
                        </ItemsPanelTemplate>
                    </Setter.Value>
                </Setter>
            </Style>
            <local:MyDataSource x:Key="Ods"/>
            <Style x:Key="errorToolTip" TargetType="Control">
                <Style.Triggers>
                    <Trigger Property="Validation.HasError" Value="True">
                        <Setter Property="ToolTip" 
                            Value="{
                                Binding RelativeSource={x:Static RelativeSource.Self}, 
                                Path=(Validation.Errors)/ErrorContent}"/>
                    </Trigger>
                </Style.Triggers>
            </Style>
            <Style TargetType="{x:Type TextBox}" BasedOn="{StaticResource errorToolTip}"/>
        </ResourceDictionary>

    </Window.Resources>

    <Grid>

        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="0.3*"/>
            <ColumnDefinition Width="Auto"/>
            <ColumnDefinition Width="1*"/>
            <ColumnDefinition Width="1*"/>
            <ColumnDefinition Width="0.3*"/>
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="1*"/>
            <RowDefinition Height="1*"/>
            <RowDefinition Height="1*"/>
            <RowDefinition Height="1*"/>
            <RowDefinition Height="1*"/>
            <RowDefinition Height="1*"/>
            <RowDefinition Height="1*"/>
            <RowDefinition Height="1*"/>
            <RowDefinition Height="1*"/>
            <RowDefinition Height="4*"/>
            <RowDefinition Height="1*"/>
            <RowDefinition Height="1*"/>
        </Grid.RowDefinitions>

        <TextBlock Grid.Column="2" Grid.Row="0" Margin="5" Text="Empresa:"/>
        <TextBlock Grid.Column="2" Grid.Row="1" Margin="5" Text="Data:"/>

        <!--ItemsSource="{Binding Items}"-->
        <dotNetKitControls:AutoCompleteComboBox
            x:Name="llistaEmpreses"
            Margin="6"
            Width="Auto"
            Height="Auto"
            Grid.Column="3"
            Grid.Row="0"
            SelectedValuePath="numClient"
            TextSearch.TextPath="Name"
            SelectedItem="{Binding SelectedItem}"
            SelectedValue="{Binding SelectedValue}">
           <dotNetKitControls:AutoCompleteComboBox.ItemTemplate>
                <DataTemplate>
                    <StackPanel>
                        <TextBlock Text="{Binding Name}" FontWeight="Bold" />
<!--                        <TextBlock>
                            Some descriptions. Id = <Run Text="{Binding Id, Mode=OneTime}" />.
                        </TextBlock> -->
                    </StackPanel>
                </DataTemplate>
            </dotNetKitControls:AutoCompleteComboBox.ItemTemplate>
        </dotNetKitControls:AutoCompleteComboBox>

        <!--
            
            <TextBox x:Name="empresa" Height="Auto" Width="Auto" 
                 Margin="10" Grid.Column="3" Grid.Row="0" >
            <TextBox.Text>
                <Binding Path="Name" Source="{StaticResource Ods}" Mode="TwoWay" UpdateSourceTrigger="PropertyChanged">
                    <Binding.ValidationRules>
                        <local:NameValidationRule/>
                    </Binding.ValidationRules>
                </Binding>
            </TextBox.Text>
        </TextBox>
 -->
        
        <DatePicker x:Name="data" Grid.Column="3" Grid.Row="1" Height="Auto" Width="Auto" Margin="6">
            <DatePicker.SelectedDate>
                <Binding Path="Date" Source="{StaticResource Ods}" Mode="TwoWay" UpdateSourceTrigger="PropertyChanged">
                    <Binding.ValidationRules>
                        <local:DateValidation/>
                    </Binding.ValidationRules>
                </Binding>
            </DatePicker.SelectedDate>
        </DatePicker>


        <TextBlock Grid.Column="2" HorizontalAlignment="Center" Grid.Row="2" Text="ENTRADA" TextWrapping="Wrap" VerticalAlignment="Center" FontWeight="Bold">
            <TextBlock.TextDecorations>
                <TextDecoration/>
            </TextBlock.TextDecorations>
        </TextBlock>
        <TextBlock Grid.Column="3" HorizontalAlignment="Center" Grid.Row="2" Text="SORTIDA" TextWrapping="Wrap" VerticalAlignment="Center" FontWeight="Bold">
            <TextBlock.TextDecorations>
                <TextDecoration/>
            </TextBlock.TextDecorations>
        </TextBlock>

        <TextBlock Grid.Column="1" HorizontalAlignment="Right" Grid.Row="3" Text="Carros DC: " TextWrapping="Wrap" VerticalAlignment="Center"/>
        <TextBox x:Name="entrada_dc" Height="Auto" Width="Auto" 
                 Margin="10" Grid.Column="2" Grid.Row="3" >
            <TextBox.Text>
                <Binding Path="z1" Source="{StaticResource Ods}" Mode="TwoWay" UpdateSourceTrigger="PropertyChanged">
                    <Binding.ValidationRules>
                        <local:NumValidationRule Min="0" Max="9999" />
                    </Binding.ValidationRules>
                </Binding>
            </TextBox.Text>
        </TextBox>
        <TextBox x:Name="sortida_dc" Height="Auto" Width="Auto" 
                 Margin="10" Grid.Column="3" Grid.Row="3" >
            <TextBox.Text>
                <Binding Path="z2" Source="{StaticResource Ods}" Mode="TwoWay" UpdateSourceTrigger="PropertyChanged">
                    <Binding.ValidationRules>
                        <local:NumValidationRule Min="0" Max="9999" />
                    </Binding.ValidationRules>
                </Binding>
            </TextBox.Text>
        </TextBox>

        <TextBlock Grid.Column="1" HorizontalAlignment="Right" Grid.Row="4" Text="Carros CC+: " TextWrapping="Wrap" VerticalAlignment="Center"/>
        <TextBox x:Name="entrada_cc" Height="Auto" Width="Auto" 
                 Margin="10" Grid.Column="2" Grid.Row="4" >
            <TextBox.Text>
                <Binding Path="z3" Source="{StaticResource Ods}" Mode="TwoWay" UpdateSourceTrigger="PropertyChanged">
                    <Binding.ValidationRules>
                        <local:NumValidationRule Min="0" Max="9999" />
                    </Binding.ValidationRules>
                </Binding>
            </TextBox.Text>
        </TextBox>
        <TextBox x:Name="sortida_cc" Height="Auto" Width="Auto" 
                 Margin="10" Grid.Column="3" Grid.Row="4" >
            <TextBox.Text>
                <Binding Path="z4" Source="{StaticResource Ods}" Mode="TwoWay" UpdateSourceTrigger="PropertyChanged">
                    <Binding.ValidationRules>
                        <local:NumValidationRule Min="0" Max="9999" />
                    </Binding.ValidationRules>
                </Binding>
            </TextBox.Text>
        </TextBox>

        <TextBlock Grid.Column="1" HorizontalAlignment="Right" Grid.Row="5" Text="Carros Tag5: " TextWrapping="Wrap" VerticalAlignment="Center"/>
        <TextBox x:Name="entrada_tag5" Height="Auto" Width="Auto" 
                 Margin="10" Grid.Column="2" Grid.Row="5" >
            <TextBox.Text>
                <Binding Path="z5" Source="{StaticResource Ods}" Mode="TwoWay" UpdateSourceTrigger="PropertyChanged">
                    <Binding.ValidationRules>
                        <local:NumValidationRule Min="0" Max="9999" />
                    </Binding.ValidationRules>
                </Binding>
            </TextBox.Text>
        </TextBox>

        <TextBox x:Name="sortida_tag5" Height="Auto" Width="Auto" 
                 Margin="10" Grid.Column="3" Grid.Row="5" >
            <TextBox.Text>
                <Binding Path="z6" Source="{StaticResource Ods}" Mode="TwoWay" UpdateSourceTrigger="PropertyChanged">
                    <Binding.ValidationRules>
                        <local:NumValidationRule Min="0" Max="9999" />
                    </Binding.ValidationRules>
                </Binding>
            </TextBox.Text>
        </TextBox>

        <TextBlock Grid.Column="1" HorizontalAlignment="Right" Grid.Row="6" Text="Safates: " TextWrapping="Wrap" VerticalAlignment="Center" RenderTransformOrigin="0.527,-1.118"/>
        <TextBox x:Name="entrada_safates" Height="Auto" Width="Auto" 
                 Margin="10" Grid.Column="2" Grid.Row="6" >
            <TextBox.Text>
                <Binding Path="z7" Source="{StaticResource Ods}" Mode="TwoWay" UpdateSourceTrigger="PropertyChanged">
                    <Binding.ValidationRules>
                        <local:NumValidationRule Min="0" Max="9999" />
                    </Binding.ValidationRules>
                </Binding>
            </TextBox.Text>
        </TextBox>

        <TextBox x:Name="sortida_safates" Height="Auto" Width="Auto" 
                 Margin="10" Grid.Column="3" Grid.Row="6" >
            <TextBox.Text>
                <Binding Path="z8" Source="{StaticResource Ods}" Mode="TwoWay" UpdateSourceTrigger="PropertyChanged">
                    <Binding.ValidationRules>
                        <local:NumValidationRule Min="0" Max="9999" />
                    </Binding.ValidationRules>
                </Binding>
            </TextBox.Text>
        </TextBox>

        <TextBlock Grid.Column="1" HorizontalAlignment="Right" Grid.Row="7" Text="Alçes Curtes: " TextWrapping="Wrap" VerticalAlignment="Center"/>
        <TextBox x:Name="entrada_alsacurta" Height="Auto" Width="Auto" 
                 Margin="10" Grid.Column="2" Grid.Row="7" >
            <TextBox.Text>
                <Binding Path="z9" Source="{StaticResource Ods}" Mode="TwoWay" UpdateSourceTrigger="PropertyChanged">
                    <Binding.ValidationRules>
                        <local:NumValidationRule Min="0" Max="9999" />
                    </Binding.ValidationRules>
                </Binding>
            </TextBox.Text>
        </TextBox>

        <TextBox x:Name="sortida_alsacurta" Height="Auto" Width="Auto" 
                 Margin="10" Grid.Column="3" Grid.Row="7" >
            <TextBox.Text>
                <Binding Path="z10" Source="{StaticResource Ods}" Mode="TwoWay" UpdateSourceTrigger="PropertyChanged">
                    <Binding.ValidationRules>
                        <local:NumValidationRule Min="0" Max="9999" />
                    </Binding.ValidationRules>
                </Binding>
            </TextBox.Text>
        </TextBox>


        <TextBlock Grid.Column="1" HorizontalAlignment="Right" Grid.Row="8" Text="Alçes Llarges: " TextWrapping="Wrap" VerticalAlignment="Center"/>
        <TextBox x:Name="entrada_alsallarga" Height="Auto" Width="Auto" 
                 Margin="10" Grid.Column="2" Grid.Row="8" >
            <TextBox.Text>
                <Binding Path="z11" Source="{StaticResource Ods}" Mode="TwoWay" UpdateSourceTrigger="PropertyChanged">
                    <Binding.ValidationRules>
                        <local:NumValidationRule Min="0" Max="9999" />
                    </Binding.ValidationRules>
                </Binding>
            </TextBox.Text>
        </TextBox>

        <TextBox x:Name="sortida_alsallarga" Height="Auto" Width="Auto" 
                 Margin="10" Grid.Column="3" Grid.Row="8" >
            <TextBox.Text>
                <Binding Path="z12" Source="{StaticResource Ods}" Mode="TwoWay" UpdateSourceTrigger="PropertyChanged">
                    <Binding.ValidationRules>
                        <local:NumValidationRule Min="0" Max="9999" />
                    </Binding.ValidationRules>
                </Binding>
            </TextBox.Text>
        </TextBox>

        <TextBlock Grid.Column="1" HorizontalAlignment="Right" Grid.Row="9" Text="Observacions: " TextWrapping="Wrap" VerticalAlignment="Top" Margin="0,10,0,0"/>
        <TextBox x:Name="Observacions" Height="120" HorizontalAlignment="Stretch" AcceptsReturn="True" TextWrapping="Wrap" Grid.Column="2" Margin="10" Grid.Row="9" VerticalAlignment="Top" Grid.ColumnSpan="2" />

        <!--        <Button Content="Desar" Grid.Column="2" HorizontalAlignment="Center" Grid.Row="9" VerticalAlignment="Center"
                Width="153" Height="26" Click="okButton_Click"/> -->
        <Button Content="Desar" 
                Grid.Column="2" Grid.Row="10" 
                HorizontalContentAlignment="Center" Width="152" Height="26" 
                VerticalAlignment="Center"
                Click="okButton_Click">
            <Button.Style>
                <Style TargetType="Button">
                    <Setter Property="IsEnabled" Value="False"/>
                    <Style.Triggers>
                        <MultiDataTrigger>
                            <MultiDataTrigger.Conditions>
                                <Condition Binding="{Binding Path=(Validation.HasError), ElementName=data}" Value="False"/>
                                <Condition Binding="{Binding Path=(Validation.HasError), ElementName=entrada_dc}" Value="False"/>
                                <Condition Binding="{Binding Path=(Validation.HasError), ElementName=entrada_cc}" Value="False"/>
                                <Condition Binding="{Binding Path=(Validation.HasError), ElementName=entrada_tag5}" Value="False"/>
                                <Condition Binding="{Binding Path=(Validation.HasError), ElementName=entrada_alsacurta}" Value="False"/>
                                <Condition Binding="{Binding Path=(Validation.HasError), ElementName=entrada_alsallarga}" Value="False"/>
                                <Condition Binding="{Binding Path=(Validation.HasError), ElementName=entrada_safates}" Value="False"/>
                                <Condition Binding="{Binding Path=(Validation.HasError), ElementName=sortida_dc}" Value="False"/>
                                <Condition Binding="{Binding Path=(Validation.HasError), ElementName=sortida_cc}" Value="False"/>
                                <Condition Binding="{Binding Path=(Validation.HasError), ElementName=sortida_tag5}" Value="False"/>
                                <Condition Binding="{Binding Path=(Validation.HasError), ElementName=sortida_safates}" Value="False"/>
                                <Condition Binding="{Binding Path=(Validation.HasError), ElementName=sortida_alsacurta}" Value="False"/>
                                <Condition Binding="{Binding Path=(Validation.HasError), ElementName=sortida_alsallarga}" Value="False"/>
                            </MultiDataTrigger.Conditions>
                            <Setter Property="IsEnabled" Value="True"/>
                        </MultiDataTrigger>
                    </Style.Triggers>
                </Style>
            </Button.Style>
        </Button>


        <Button Content="Torna" Grid.Column="3" HorizontalAlignment="Center" Grid.Row="10" VerticalAlignment="Center" Width="152" Height="26" Click="cancelButton_Click"/>

    </Grid>
</Window>
