<Window 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"
    Title="ListBox Properties" Height="380" Width="500">
    
    <Window.Resources>
        <local:PDFDeviceColorToSolidColorBrushConverter x:Key="pdfDeviceColorToSolidColorBrushConverter"/>
        <local:BoolToVisibilityConverter x:Key="boolToVisibilityConverter"/>
        <local:ReverseBoolToVisibilityConverter x:Key="reverseBoolToVisibilityConverter"/>
    </Window.Resources>
    
    <Grid>
        <Grid.RowDefinitions>
            <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>
            
            <Label Content="Field name:"/>
            <TextBox Grid.Column="1" Margin="2" Text="{Binding Path=ListBoxField.Name}"/>
            
            <Label Grid.Row="1" Content="Tooltip:"/>
            <TextBox Grid.Row="1" Grid.Column="1" Margin="2" Text="{Binding Path=ListBoxField.Tooltip}"/>
        </Grid>
        
        <TabControl Grid.Row="1" Margin="2">
            <TabItem Header="Appearance">
                <Grid>
                    <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>

                        <Label Content="Visibility:"/>
                        <ComboBox Grid.Column="1" Margin="2" ItemsSource="{Binding PDFFieldWidgetVisibilityStatuses}" SelectedItem="{Binding Path=ListBoxWidget.VisibilityStatus}"/>

                        <Label Grid.Column="2" Content="Orientation:"/>
                        <ComboBox Grid.Column="3" Margin="2" ItemsSource="{Binding PDFRotationModes}" SelectedItem="{Binding Path=ListBoxWidget.Rotation}"/>
                    </Grid>
                    
                    <GroupBox Grid.Row="1" Header="Borders and colors">
                        <Grid>
                            <Grid.RowDefinitions>
                                <RowDefinition Height="30"/>
                                <RowDefinition Height="30"/>
                            </Grid.RowDefinitions>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="110"/>
                                <ColumnDefinition Width="*"/>
                                <ColumnDefinition Width="110"/>
                                <ColumnDefinition Width="*"/>
                            </Grid.ColumnDefinitions>

                            <Label Content="Border width:"/>
                            <ComboBox Grid.Column="1" Margin="2" ItemsSource="{Binding BorderWidths}" SelectedIndex="{Binding Path=ListBoxWidget.BorderWidth}"/>

                            <Label Grid.Row="1" Content="Border style:"/>
                            <ComboBox Grid.Row="1" Grid.Column="1" Margin="2" ItemsSource="{Binding PDFBorderStyles}" SelectedItem="{Binding Path=ListBoxWidget.BorderStyle}"/>

                            <Label Grid.Column="2" Content="Border color:"/>
                            <local:ColorUserControl Grid.Column="3" Margin="2" SelectedColor="{Binding Path=ListBoxWidget.BorderColor, Mode=TwoWay, Converter={StaticResource pdfDeviceColorToSolidColorBrushConverter}}"/>
                            
                            <Label Grid.Row="1" Grid.Column="2" Content="Fill color:"/>
                            <local:ColorUserControl Grid.Row="1" Grid.Column="3" Margin="2" SelectedColor="{Binding Path=ListBoxWidget.BackColor, Mode=TwoWay, Converter={StaticResource pdfDeviceColorToSolidColorBrushConverter}}"/>
                        </Grid>
                    </GroupBox>

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

                            <Label Content="Font:"/>
                            <ComboBox Grid.Column="1" Grid.ColumnSpan="3" Margin="2" ItemsSource="{Binding Fonts}" SelectedIndex="{Binding SelectedFontIndex}"/>

                            <Label Grid.Row="1" Content="Size:"/>
                            <ComboBox Grid.Row="1" Grid.Column="1" Margin="2" ItemsSource="{Binding FontSizes}" SelectedValue="{Binding SelectedFontSize}"/>

                            <Label Grid.Row="1" Grid.Column="2" Content="Color:"/>
                            <local:ColorUserControl Grid.Row="1" Grid.Column="3" Margin="2" SelectedColor="{Binding Path=ListBoxWidget.TextColor, Mode=TwoWay, Converter={StaticResource pdfDeviceColorToSolidColorBrushConverter}}"/>
                        </Grid>
                    </GroupBox>
                </Grid>
            </TabItem>
            
            <TabItem Header="Options">
                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto"/>
                        <RowDefinition Height="Auto"/>
                    </Grid.RowDefinitions>
                    
                    <GroupBox>
                        <!--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>
                                    
                                    <Label Grid.Column="0" Content="Name:"/>
                                    <TextBox Grid.Column="1" Margin="2" Name="NameTextBox"/>
                                    
                                    <Label Grid.Column="2" Content="Value:"/>
                                    <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>
                    </GroupBox>
                    
                    <!--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}"/>
                        <CheckBox Grid.Row="1" Grid.Column="0" Margin="2" Content="Multiple selection" IsChecked="{Binding Path=ListBoxField.MultipleSelection}"/>
                        <CheckBox Grid.Row="2" Grid.Column="0" Margin="2" Content="Commit selected value immediately" IsChecked="{Binding Path=ListBoxField.CommitOnSelChange}"/>
                        
                        <CheckBox Grid.Row="0" Grid.Column="1" Margin="2" Content="Read only" IsChecked="{Binding Path=ListBoxField.ReadOnly}"/>
                        <CheckBox Grid.Row="1" Grid.Column="1" Margin="2" Content="No export" IsChecked="{Binding Path=ListBoxField.NoExport}"/>
                        <CheckBox Grid.Row="2" Grid.Column="1" Margin="2" Content="Locked" IsChecked="{Binding IsLocked}"/>
                    </Grid>
                </Grid>
            </TabItem>
        </TabControl>
        
        <StackPanel Orientation="Horizontal" HorizontalAlignment="Right" Grid.Row="2" 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>
</Window>
