<!-- **************************************************************************

  Copyright (c) 2010 CubeSoft, Inc.

  This program is free software: you can redistribute it and/or modify
  it under the terms of the GNU Affero General Public License as published
  by the Free Software Foundation, either version 3 of the License, or
  (at your option) any later version.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU Affero General Public License for more details.

  You should have received a copy of the GNU Affero General Public License
  along with this program.  If not, see <http://www.gnu.org/licenses/>.

*************************************************************************** -->
<ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
    xmlns:my="clr-namespace:Cube.Pdf.Editor">

    <!-- **********************************************************************
      Import
    *********************************************************************** -->
    <ResourceDictionary.MergedDictionaries>
        <ResourceDictionary Source="pack://application:,,,/Themes/ScrollStyle.xaml" />
    </ResourceDictionary.MergedDictionaries>

    <!-- **********************************************************************
      ListViewItem (DataTemplate)
    *********************************************************************** -->
    <DataTemplate x:Key="PageTemplate" DataType="{x:Type my:ImageItem}">
        <Grid>
            <Grid.RowDefinitions>
                <RowDefinition Height="*" />
                <RowDefinition Height="Auto" />
            </Grid.RowDefinitions>

            <Border
                Width="{Binding Width}"
                Height="{Binding Height}"
                BorderThickness="1"
                BorderBrush="{StaticResource DarkBorderBrush}"
                HorizontalAlignment="Center"
                VerticalAlignment="Center">
                <Image
                    Source="{Binding Image}"
                    Stretch="{Binding Stretch}"
                    HorizontalAlignment="Center"
                    VerticalAlignment="Center" />
            </Border>

            <TextBlock
                Grid.Row="1"
                Text="{Binding Index, Converter={my:IndexToText}}"
                TextAlignment="Center"
                Foreground="{StaticResource DarkForegroundBrush}" />
        </Grid>
    </DataTemplate>

    <!-- **********************************************************************
      ListViewItem
    *********************************************************************** -->
    <Style x:Key="PageStyle" TargetType="{x:Type ListViewItem}">
        <Setter Property="Margin" Value="3" />
        <Setter Property="IsSelected" Value="{Binding Selected, Mode=OneWay}" />
    </Style>

    <!-- **********************************************************************
      ListView (Template)
    *********************************************************************** -->
    <ControlTemplate x:Key="PageCollectionTemplate" TargetType="{x:Type ListView}">
        <ScrollViewer
            Background="{StaticResource DarkBackgroundBrush}"
            Template="{StaticResource ScrollViewerTemplate}"
            HorizontalScrollBarVisibility="Disabled">
            <WrapPanel
                ItemWidth="{Binding Value.Images.Preferences.ItemSize}"
                ItemHeight="{Binding Value.Images.Preferences.ItemSize}"
                MinWidth="{Binding Value.Images.Preferences.ItemSize}"
                Width="{Binding FrameworkElement.ActualWidth,
                RelativeSource={RelativeSource AncestorType=ScrollContentPresenter}}"
                IsItemsHost="True" />

            <i:Interaction.Behaviors>
                <my:VisibleRange
                    First="{Binding Value.Images.Preferences.VisibleFirst, Mode=TwoWay}"
                    Last="{Binding Value.Images.Preferences.VisibleLast, Mode=TwoWay}"
                    Unit="{Binding Value.Images.Preferences.ItemSize}" />
            </i:Interaction.Behaviors>
        </ScrollViewer>
    </ControlTemplate>

    <!-- **********************************************************************
      ListView
    *********************************************************************** -->
    <Style x:Key="PageCollectionStyle" TargetType="{x:Type ListView}">
        <Setter Property="Background" Value="{StaticResource DarkBackgroundBrush}" />
        <Setter Property="BorderThickness" Value="0" />
        <Setter Property="HorizontalContentAlignment" Value="Center" />
        <Setter Property="VerticalContentAlignment" Value="Center" />
        <Setter Property="SelectionMode" Value="Extended" />
        <Setter Property="VirtualizingStackPanel.IsVirtualizing" Value="True" />
        <Setter Property="VirtualizingStackPanel.VirtualizationMode" Value="Recycling" />
        <Setter Property="ItemContainerStyle" Value="{StaticResource PageStyle}" />
        <Setter Property="ItemTemplate" Value="{StaticResource PageTemplate}" />
        <Setter Property="Template" Value="{StaticResource PageCollectionTemplate}" />
    </Style>
</ResourceDictionary>