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

  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="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
    xmlns:xb="clr-namespace:Cube.Xui.Behaviors;assembly=Cube.Xui"
    xmlns:my="clr-namespace:Cube.Pdf.App.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="None"
                    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 IsSelected, 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 Data.Images.Preferences.ItemSize}"
                ItemHeight="{Binding Data.Images.Preferences.ItemSize}"
                MinWidth="{Binding Data.Images.Preferences.ItemSize}"
                Width="{Binding FrameworkElement.ActualWidth,
                RelativeSource={RelativeSource AncestorType=ScrollContentPresenter}}"
                IsItemsHost="True" />

            <i:Interaction.Behaviors>
                <my:VisibleRange
                    First="{Binding Data.Images.Preferences.VisibleFirst, Mode=TwoWay}"
                    Last="{Binding Data.Images.Preferences.VisibleLast, Mode=TwoWay}"
                    Unit="{Binding Data.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>