<UserControl x:Class="FormDesigner.ListBoxPropertiesForm"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:FormDesigner">

    <UserControl.Resources>
        <local:PDFDeviceColorToSolidColorBrushConverter x:Key="pdfDeviceColorToSolidColorBrushConverter"/>
        <local:BoolToVisibilityConverter x:Key="boolToVisibilityConverter"/>
        <local:ReverseBoolToVisibilityConverter x:Key="reverseBoolToVisibilityConverter"/>
    </UserControl.Resources>

    <Grid>
        <Grid Background="DarkGray" Opacity="0.4"/>

        <Grid Height="470" Width="500" HorizontalAlignment="Center" VerticalAlignment="Center">
            <Border Background="#FAFAFA" BorderBrush="Black" BorderThickness="2">
                <Border.Effect>
                    <DropShadowEffect Color="Black" Opacity="0.6" Direction="315" ShadowDepth="5"/>
                </Border.Effect>
            </Border>

            <Grid Background="#FAFAFA" Margin="7">
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="*"/>
                    <RowDefinition Height="Auto"/>
                </Grid.RowDefinitions>

                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition/>
                        <RowDefinition/>
                    </Grid.RowDefinitions>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="Auto"/>
                        <ColumnDefinition Width="*"/>
                    </Grid.ColumnDefinitions>

                    <TextBlock Text="Field name:" VerticalAlignment="Center"/>
                    <TextBox Grid.Column="1" Margin="2" Text="{Binding Path=ListBoxField.Name, Mode=TwoWay}"/>

                    <TextBlock Grid.Row="1" Text="Tooltip:" VerticalAlignment="Center"/>
                    <TextBox Grid.Row="1" Grid.Column="1" Margin="2" Text="{Binding Path=ListBoxField.Tooltip, Mode=TwoWay}"/>
                </Grid>

                <Grid Grid.Row="1" Margin="2">
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto"/>
                        <RowDefinition Height="Auto"/>
                        <RowDefinition Height="Auto"/>
                    </Grid.RowDefinitions>

                    <Grid Margin="6">
                        <Grid.RowDefinitions>
                            <RowDefinition Height="30"/>
                        </Grid.RowDefinitions>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="110"/>
                            <ColumnDefinition Width="*"/>
                            <ColumnDefinition Width="110"/>
                            <ColumnDefinition Width="*"/>
                        </Grid.ColumnDefinitions>

                        <TextBlock Text="Visibility:" VerticalAlignment="Center"/>
                        <ComboBox Grid.Column="1" Margin="2" ItemsSource="{Binding PDFFieldWidgetVisibilityStatuses}" SelectedItem="{Binding Path=ListBoxWidget.VisibilityStatus, Mode=TwoWay}"/>

                        <TextBlock Grid.Column="2" Text="Orientation:" VerticalAlignment="Center"/>
                        <ComboBox Grid.Column="3" Margin="2" ItemsSource="{Binding PDFRotationModes}" SelectedItem="{Binding Path=ListBoxWidget.Rotation, Mode=TwoWay}"/>
                    </Grid>

                    <Grid Grid.Row="1">
                        <Grid.RowDefinitions>
                            <RowDefinition Height="30"/>
                            <RowDefinition Height="30"/>
                        </Grid.RowDefinitions>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="110"/>
                            <ColumnDefinition Width="*"/>
                            <ColumnDefinition Width="110"/>
                            <ColumnDefinition Width="*"/>
                        </Grid.ColumnDefinitions>

                        <TextBlock Text="Border width:" VerticalAlignment="Center"/>
                        <ComboBox Grid.Column="1" Margin="2" ItemsSource="{Binding BorderWidths}" SelectedIndex="{Binding Path=ListBoxWidget.BorderWidth, Mode=TwoWay}"/>

                        <TextBlock Grid.Row="1" Text="Border style:" VerticalAlignment="Center"/>
                        <ComboBox Grid.Row="1" Grid.Column="1" Margin="2" ItemsSource="{Binding PDFBorderStyles}" SelectedItem="{Binding Path=ListBoxWidget.BorderStyle, Mode=TwoWay}"/>

                        <TextBlock Grid.Column="2" Text="Border color:" VerticalAlignment="Center"/>
                        <local:ColorUserControl Grid.Column="3" Margin="2" SelectedColor="{Binding Path=ListBoxWidget.BorderColor, Mode=TwoWay, Converter={StaticResource pdfDeviceColorToSolidColorBrushConverter}}"/>

                        <TextBlock Grid.Row="1" Grid.Column="2" Text="Fill color:" VerticalAlignment="Center"/>
                        <local:ColorUserControl Grid.Row="1" Grid.Column="3" Margin="2" SelectedColor="{Binding Path=ListBoxWidget.BackColor, Mode=TwoWay, Converter={StaticResource pdfDeviceColorToSolidColorBrushConverter}}"/>
                    </Grid>

                    <Grid Grid.Row="2">
                        <Grid.RowDefinitions>
                            <RowDefinition Height="30"/>
                            <RowDefinition Height="30"/>
                        </Grid.RowDefinitions>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="110"/>
                            <ColumnDefinition Width="*"/>
                            <ColumnDefinition Width="110"/>
                            <ColumnDefinition Width="*"/>
                        </Grid.ColumnDefinitions>

                        <TextBlock Text="Font:" VerticalAlignment="Center"/>
                        <ComboBox Grid.Column="1" Grid.ColumnSpan="3" Margin="2" ItemsSource="{Binding Fonts}" SelectedIndex="{Binding SelectedFontIndex, Mode=TwoWay}"/>

                        <TextBlock Grid.Row="1" Text="Size:" VerticalAlignment="Center"/>
                        <ComboBox Grid.Row="1" Grid.Column="1" Margin="2" ItemsSource="{Binding FontSizes}" SelectedValue="{Binding SelectedFontSize, Mode=TwoWay}"/>

                        <TextBlock Grid.Row="1" Grid.Column="2" Text="Color:" VerticalAlignment="Center"/>
                        <local:ColorUserControl Grid.Row="1" Grid.Column="3" Margin="2" SelectedColor="{Binding Path=ListBoxWidget.TextColor, Mode=TwoWay, Converter={StaticResource pdfDeviceColorToSolidColorBrushConverter}}"/>
                    </Grid>
                </Grid>

                <Grid Grid.Row="2">
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto"/>
                        <RowDefinition Height="Auto"/>
                    </Grid.RowDefinitions>

                    <!--Up part of the window: name, value, listbox and buttons-->
                    <Grid>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="*"/>
                            <ColumnDefinition Width="80"/>
                        </Grid.ColumnDefinitions>

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

                            <!--Name and value-->
                            <Grid>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition/>
                                    <ColumnDefinition/>
                                    <ColumnDefinition/>
                                    <ColumnDefinition/>
                                </Grid.ColumnDefinitions>

                                <TextBlock Grid.Column="0" Text="Name:" VerticalAlignment="Center"/>
                                <TextBox Grid.Column="1" Margin="2" Name="NameTextBox"/>

                                <TextBlock Grid.Column="2" Text="Value:" VerticalAlignment="Center"/>
                                <TextBox Grid.Column="3" Margin="2" Name="ValueTextBox"/>
                            </Grid>

                            <ListBox Grid.Row="1" Name="ListBoxUi" BorderThickness="1" BorderBrush="Black" Margin="2" ItemsSource="{Binding ListBoxItems}" DisplayMemberPath="Name" SelectionChanged="ListBoxUi_SelectionChanged"/>
                        </Grid>

                        <!--Buttons-->
                        <Grid Grid.Column="1">
                            <Grid.RowDefinitions>
                                <RowDefinition/>
                                <RowDefinition/>
                                <RowDefinition/>
                                <RowDefinition/>
                            </Grid.RowDefinitions>
                            <Button Grid.Row="0" Margin="4" Height="24" Content="Add" Click="AddItem_Click"/>
                            <Button Grid.Row="1" Margin="4" Height="24" Content="Delete" Click="DeleteItem_Click" IsEnabled="{Binding IsDeleteEnabled}"/>
                            <Button Grid.Row="2" Margin="4" Height="24" Content="Up" Click="Up_Click" IsEnabled="{Binding IsUpEnabled}"/>
                            <Button Grid.Row="3" Margin="4" Height="24" Content="Down" Click="Down_Click" IsEnabled="{Binding IsDownEnabled}"/>
                        </Grid>
                    </Grid>

                    <!--Down part with checkboxes-->
                    <Grid Grid.Row="1">
                        <Grid.RowDefinitions>
                            <RowDefinition/>
                            <RowDefinition/>
                            <RowDefinition/>
                        </Grid.RowDefinitions>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition/>
                            <ColumnDefinition/>
                        </Grid.ColumnDefinitions>

                        <CheckBox Grid.Row="0" Grid.Column="0" Margin="2" Content="Sort items" IsChecked="{Binding Path=ListBoxField.Sort, Mode=TwoWay}"/>
                        <CheckBox Grid.Row="1" Grid.Column="0" Margin="2" Content="Multiple selection" IsChecked="{Binding Path=ListBoxField.MultipleSelection, Mode=TwoWay}"/>
                        <CheckBox Grid.Row="2" Grid.Column="0" Margin="2" Content="Commit selected value immediately" IsChecked="{Binding Path=ListBoxField.CommitOnSelChange, Mode=TwoWay}"/>

                        <CheckBox Grid.Row="0" Grid.Column="1" Margin="2" Content="Read only" IsChecked="{Binding Path=ListBoxField.ReadOnly, Mode=TwoWay}"/>
                        <CheckBox Grid.Row="1" Grid.Column="1" Margin="2" Content="No export" IsChecked="{Binding Path=ListBoxField.NoExport, Mode=TwoWay}"/>
                        <CheckBox Grid.Row="2" Grid.Column="1" Margin="2" Content="Locked" IsChecked="{Binding IsLocked, Mode=TwoWay}"/>
                    </Grid>
                </Grid>

                <StackPanel Orientation="Horizontal" HorizontalAlignment="Right" Grid.Row="3" Margin="0,6,0,0">
                    <Button Margin="4" Width="100" Height="24" Content="OK" Click="Ok_Click" Visibility="{Binding IsCancelable, Converter={StaticResource boolToVisibilityConverter}}"/>
                    <Button Margin="4" Width="100" Height="24" Content="Cancel" Click="Cancel_Click" Visibility="{Binding IsCancelable, Converter={StaticResource boolToVisibilityConverter}}"/>
                    <Button Margin="4" Width="100" Height="24" Content="Close" Click="Ok_Click" Visibility="{Binding IsCancelable, Converter={StaticResource reverseBoolToVisibilityConverter}}"/>
                </StackPanel>
            </Grid>
        </Grid>
    </Grid>
</UserControl>