<UserControl
	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:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk"
	xmlns:toolkit="http://schemas.microsoft.com/winfx/2006/xaml/presentation/toolkit"
    xmlns:layoutToolkit="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Layout.Toolkit"
    xmlns:controlsInputToolkit="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Input.Toolkit" 
    xmlns:controls="clr-namespace:PDFTron.SilverDox.Samples.Controls"
	mc:Ignorable="d"
	x:Class="PDFTron.SilverDox.Samples.AnnotationWindowControl"
    x:Name="annotationWindowControl"
	d:DesignWidth="210" d:DesignHeight="400" >

    <UserControl.Resources>
        <ResourceDictionary Source="/ReaderControl;component/Resources/ResourceDictionary.xaml"/>
    </UserControl.Resources>

    <Grid x:Name="LayoutRoot" Background="{Binding Background, ElementName=MyAnotationWindowControl}">
        <Grid.RowDefinitions>
            <RowDefinition Height="auto" />
            <RowDefinition Height="auto" />
            <RowDefinition Height="*"/>
            <RowDefinition Height="auto"/>
        </Grid.RowDefinitions>

        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*"/>
        </Grid.ColumnDefinitions>

        <!-- Tool Picker -->
        <StackPanel Grid.Column="0" Grid.Row="0">
            <Border Grid.Row="0" Style="{StaticResource AnnotationTitleBorderStyle}">
                <TextBlock Text="Annotations" Style="{StaticResource AnnotationWindowTitleTextBlockStyle}"/>
            </Border>
            <controls:AnnotationToolModePickerControl />
        </StackPanel>

        <!-- Annotation Property Controls -->
        <StackPanel Grid.Column="0" Grid.Row="3" Margin="0,10,0,0">
            <Border Style="{StaticResource AnnotationTitleBorderStyle}" >
                <TextBlock Text="Annotation Properties" Style="{StaticResource AnnotationWindowTitleTextBlockStyle}"/>
            </Border>
            <controls:AnnotationPropertiesControl  />
        </StackPanel>

        <!-- Annotation Navigator -->
        <StackPanel Grid.Row="1" Margin="0,20,0,0">
            <Border Style="{StaticResource AnnotationTitleBorderStyle}">
                <TextBlock Text="Annotations List" Style="{StaticResource AnnotationWindowTitleTextBlockStyle}"/>
            </Border>
        </StackPanel>
        <StackPanel Grid.Row="1" Margin="0,45,0,0">
            <Border Style="{StaticResource AnnotationTitleBorderStyle}">
                <Button x:Name="SaveButton" Content="Save" Click="SaveButton_Click"/>
            </Border>
        </StackPanel>
        <controls:AnnotationsListBox  x:Name="annotationsListBox" 
                                     SelectionChanged="annotationsListBox_SelectionChanged"
                                      SelectionMode="Extended" Grid.Row="2">

                <ListBox.ItemContainerStyle>
                    <Style TargetType="ListBoxItem">
                        <Setter Property="HorizontalAlignment" Value="Stretch"/>
                        <Setter Property="HorizontalContentAlignment" Value="Stretch"/>
                    </Style>
                </ListBox.ItemContainerStyle>
                <ListBox.ItemTemplate>
                    <DataTemplate>
                        <Border BorderThickness="1" CornerRadius="2" BorderBrush="Gray" HorizontalAlignment="Stretch" Padding="5">
                            <StackPanel Orientation="Vertical" HorizontalAlignment="Stretch">
                                <TextBlock>
                                    <Run Text="{Binding Path=Subject}"/>
                                    <Run Text=" Page:"/>
                                    <Run Text="{Binding Path=PageNumber}"/>
                                </TextBlock>
                                <TextBlock Visibility="{Binding Path=Author, Converter={StaticResource HideIfNullConverter}}">
                                    <Run Text="Author: "/>
                                    <Run Text="{Binding Path=Author}"/>
                                </TextBlock>
                                <TextBlock TextWrapping="Wrap" Visibility="{Binding Path=PopupContents, Converter={StaticResource HideIfNullConverter}}">
                                    <Run FontStyle="Italic"  Text="{Binding Path=PopupContents}"/>
                                </TextBlock>
                                
                                <!-- Commented out this context menu, it's really bad for performance -->
                                <!--<controlsInputToolkit:ContextMenuService.ContextMenu>
                                    <controlsInputToolkit:ContextMenu x:Name="annotationListContextMenu" Opened="annotationListContextMenu_Opened">
                                        <controlsInputToolkit:MenuItem x:Name="removeAnnotationMenuItem" 
                                                                       Header="Remove" 
                                                                       Command="{Binding RemoveAnnotationCommand, ElementName=annotationWindowControl}"/>
                                    </controlsInputToolkit:ContextMenu>
                                </controlsInputToolkit:ContextMenuService.ContextMenu>-->

                            </StackPanel>
                        </Border>
                    </DataTemplate>
                </ListBox.ItemTemplate>
            </controls:AnnotationsListBox>
    </Grid>
</UserControl>