<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:bpa="clr-namespace:BPA.UIControl">

    <ResourceDictionary.MergedDictionaries>
        <ResourceDictionary Source="pack://application:,,,/BPA.UIControl;component/Themes/ScrollViewer.xaml" />
    </ResourceDictionary.MergedDictionaries>

    <Style x:Key="FlipViewArrowButton"
           BasedOn="{StaticResource RubyerButton}"
           TargetType="Button">
        <Setter Property="Foreground" Value="{DynamicResource DefaultForeground}" />
        <Setter Property="Background" Value="{DynamicResource HeaderBackground}" />
        <Setter Property="bpa:ButtonHelper.Shape" Value="Circle" />
    </Style>

    <!--  滚动视图默认样式  -->
    <Style x:Key="RubyerFlipViewItem" TargetType="{x:Type bpa:FlipViewItem}">
        <Setter Property="Height" Value="{Binding ViewportHeight, RelativeSource={RelativeSource AncestorType=ScrollViewer}}" />
        <Setter Property="Width" Value="{Binding ViewportWidth, RelativeSource={RelativeSource AncestorType=ScrollViewer}}" />
        <Setter Property="HorizontalContentAlignment" Value="Stretch" />
        <Setter Property="VerticalContentAlignment" Value="Stretch" />
        <Setter Property="SnapsToDevicePixels" Value="True" />
        <Setter Property="bpa:ControlHelper.CornerRadius" Value="{Binding Path=(bpa:ControlHelper.CornerRadius), RelativeSource={RelativeSource AncestorType=bpa:FlipView}}" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type bpa:FlipViewItem}">
                    <Border x:Name="rootBorder"
                            Background="{TemplateBinding Background}"
                            BorderBrush="{TemplateBinding BorderBrush}"
                            BorderThickness="{TemplateBinding BorderThickness}"
                            CornerRadius="{Binding Path=(bpa:ControlHelper.CornerRadius), RelativeSource={RelativeSource Mode=TemplatedParent}}">
                        <ContentPresenter x:Name="PART_ContentPresenter"
                                          HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                                          VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                                          Focusable="False"
                                          RecognizesAccessKey="True"
                                          SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
                    </Border>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style x:Key="RubyerFlipView" TargetType="{x:Type bpa:FlipView}">
        <Setter Property="BorderBrush" Value="{DynamicResource Border}" />
        <Setter Property="BorderThickness" Value="0" />
        <Setter Property="Height" Value="400" />
        <Setter Property="ItemContainerStyle" Value="{StaticResource RubyerFlipViewItem}" />
        <Setter Property="SnapsToDevicePixels" Value="True" />
        <Setter Property="ArrowButtonStyle" Value="{StaticResource FlipViewArrowButton}" />
        <Setter Property="AnimateDuration" Value="0:0:0.5" />
        <Setter Property="AnimateEasingFunction">
            <Setter.Value>
                <CubicEase EasingMode="EaseOut" />
            </Setter.Value>
        </Setter>
        <Setter Property="bpa:ControlHelper.CornerRadius" Value="0" />
        <Setter Property="IsManipulationEnabled" Value="True" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type bpa:FlipView}">
                    <Border x:Name="rootBorder"
                            Background="{TemplateBinding Background}"
                            BorderBrush="{TemplateBinding BorderBrush}"
                            BorderThickness="{TemplateBinding BorderThickness}"
                            CornerRadius="{Binding Path=(bpa:ControlHelper.CornerRadius), RelativeSource={RelativeSource Mode=TemplatedParent}}">
                        <Grid x:Name="root">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="Auto" />
                                <ColumnDefinition Width="*" />
                                <ColumnDefinition Width="Auto" />
                            </Grid.ColumnDefinitions>
                            <Grid.RowDefinitions>
                                <RowDefinition Height="Auto" />
                                <RowDefinition Height="*" />
                                <RowDefinition Height="Auto" />
                            </Grid.RowDefinitions>
                            <ScrollViewer Name="PART_ContentScrollViewer"
                                          Grid.Row="1"
                                          Grid.Column="1"
                                          bpa:ScrollViewerHelper.HorizontalOffset="{TemplateBinding HorizontalOffset}"
                                          bpa:ScrollViewerHelper.VerticalOffset="{TemplateBinding VerticalOffset}"
                                          CanContentScroll="False"
                                          HorizontalScrollBarVisibility="Hidden"
                                          PanningMode="None"
                                          VerticalScrollBarVisibility="Hidden">
                                <ItemsPresenter SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
                            </ScrollViewer>

                            <Button x:Name="PART_LeftButton"
                                    Style="{TemplateBinding ArrowButtonStyle}"
                                    Grid.Row="1"
                                    Margin="0 0 5 0"
                                    Visibility="Collapsed">
                                <bpa:Icon Type="ArrowLeftSLine" />
                            </Button>

                            <Button x:Name="PART_RightButton"
                                    Style="{TemplateBinding ArrowButtonStyle}"
                                    Grid.Row="1"
                                    Grid.Column="2"
                                    Margin="5 0 0 0"
                                    Visibility="Collapsed">
                                <bpa:Icon Type="ArrowRightSLine" />
                            </Button>

                            <Button x:Name="PART_UpButton"
                                    Style="{TemplateBinding ArrowButtonStyle}"
                                    Grid.Column="1"
                                    Margin="0 0 0 5"
                                    Visibility="Collapsed">
                                <bpa:Icon Type="ArrowUpSLine" />
                            </Button>

                            <Button x:Name="PART_DownButton"
                                    Style="{TemplateBinding ArrowButtonStyle}"
                                    Grid.Row="2"
                                    Grid.Column="1"
                                    Margin="0 5 0 0"
                                    Visibility="Collapsed">
                                <bpa:Icon Type="ArrowDownSLine" />
                            </Button>
                        </Grid>
                    </Border>

                    <ControlTemplate.Triggers>
                        <Trigger Property="Orientation" Value="Horizontal">
                            <Setter TargetName="PART_LeftButton" Property="Visibility" Value="Visible" />
                            <Setter TargetName="PART_RightButton" Property="Visibility" Value="Visible" />
                            <Setter Property="ItemsPanel">
                                <Setter.Value>
                                    <ItemsPanelTemplate>
                                        <StackPanel Orientation="Horizontal" />
                                    </ItemsPanelTemplate>
                                </Setter.Value>
                            </Setter>
                        </Trigger>
                        <Trigger Property="Orientation" Value="Vertical">
                            <Setter TargetName="PART_UpButton" Property="Visibility" Value="Visible" />
                            <Setter TargetName="PART_DownButton" Property="Visibility" Value="Visible" />
                            <Setter Property="ItemsPanel">
                                <Setter.Value>
                                    <ItemsPanelTemplate>
                                        <StackPanel />
                                    </ItemsPanelTemplate>
                                </Setter.Value>
                            </Setter>
                        </Trigger>

                        <Trigger Property="IsButtonFloat" Value="True">
                            <Setter TargetName="PART_ContentScrollViewer" Property="Grid.Row" Value="0" />
                            <Setter TargetName="PART_ContentScrollViewer" Property="Grid.Column" Value="0" />
                            <Setter TargetName="PART_ContentScrollViewer" Property="Grid.RowSpan" Value="3" />
                            <Setter TargetName="PART_ContentScrollViewer" Property="Grid.ColumnSpan" Value="3" />
                        </Trigger>

                        <MultiTrigger>
                            <MultiTrigger.Conditions>
                                <Condition Property="IsButtonFloat" Value="True" />
                                <Condition Property="IsMouseOver" Value="False" />
                            </MultiTrigger.Conditions>
                            <Setter TargetName="PART_LeftButton" Property="Opacity" Value="0" />
                            <Setter TargetName="PART_RightButton" Property="Opacity" Value="0" />
                            <Setter TargetName="PART_UpButton" Property="Opacity" Value="0" />
                            <Setter TargetName="PART_DownButton" Property="Opacity" Value="0" />
                        </MultiTrigger>

                        <Trigger Property="SelectedIndex" Value="0">
                            <Setter TargetName="PART_LeftButton" Property="Opacity" Value="0" />
                            <Setter TargetName="PART_UpButton" Property="Opacity" Value="0" />
                            <Setter TargetName="PART_LeftButton" Property="IsEnabled" Value="False" />
                            <Setter TargetName="PART_UpButton" Property="IsEnabled" Value="False" />
                        </Trigger>

                        <DataTrigger Value="1">
                            <DataTrigger.Binding>
                                <MultiBinding Converter="{StaticResource MathSubtractConverter}">
                                    <MultiBinding.Bindings>
                                        <Binding Path="Items.Count" RelativeSource="{RelativeSource Self}" />
                                        <Binding Path="SelectedIndex" RelativeSource="{RelativeSource Self}" />
                                    </MultiBinding.Bindings>
                                </MultiBinding>
                            </DataTrigger.Binding>
                            <Setter TargetName="PART_RightButton" Property="Opacity" Value="0" />
                            <Setter TargetName="PART_DownButton" Property="Opacity" Value="0" />
                            <Setter TargetName="PART_RightButton" Property="IsEnabled" Value="False" />
                            <Setter TargetName="PART_DownButton" Property="IsEnabled" Value="False" />
                        </DataTrigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <!--  轮播图样式  -->
    <Style x:Key="CarouselFlipViewItem"
           BasedOn="{StaticResource RubyerFlipViewItem}"
           TargetType="bpa:FlipViewItem">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type bpa:FlipViewItem}">
                    <Border x:Name="rootBorder"
                            Background="{TemplateBinding Background}"
                            BorderBrush="{TemplateBinding BorderBrush}"
                            BorderThickness="{TemplateBinding BorderThickness}"
                            CornerRadius="{Binding Path=(bpa:ControlHelper.CornerRadius), RelativeSource={RelativeSource Mode=TemplatedParent}}"
                            RenderTransformOrigin="0.5,0.5">
                        <Border.RenderTransform>
                            <ScaleTransform x:Name="scale" ScaleY="{Binding ScaleX, RelativeSource={RelativeSource Self}}">
                                <ScaleTransform.ScaleX>
                                    <MultiBinding Converter="{StaticResource CarouselScaleConvereter}">
                                        <MultiBinding.Bindings>
                                            <Binding RelativeSource="{RelativeSource AncestorType=bpa:FlipViewItem}" />
                                            <Binding ElementName="scale" />
                                            <Binding Path="Orientation" RelativeSource="{RelativeSource AncestorType=bpa:FlipView}" />
                                            <Binding Path="HorizontalOffset" RelativeSource="{RelativeSource AncestorType=ScrollViewer}" />
                                            <Binding Path="VerticalOffset" RelativeSource="{RelativeSource AncestorType=ScrollViewer}" />
                                        </MultiBinding.Bindings>
                                    </MultiBinding>
                                </ScaleTransform.ScaleX>
                            </ScaleTransform>
                        </Border.RenderTransform>
                        <Border.Opacity>
                            <MultiBinding Converter="{StaticResource MathMultiplyConverter}">
                                <MultiBinding.Bindings>
                                    <Binding ElementName="scale" Path="ScaleX" />
                                    <Binding Source="0.5" />
                                </MultiBinding.Bindings>
                            </MultiBinding>
                        </Border.Opacity>
                        <ContentPresenter x:Name="PART_ContentPresenter"
                                          HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                                          VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                                          Focusable="False"
                                          RecognizesAccessKey="True"
                                          SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
                    </Border>
                    <ControlTemplate.Triggers>
                        <DataTrigger Binding="{Binding Orientation, RelativeSource={RelativeSource AncestorType=bpa:FlipView}}" Value="Horizontal">
                            <Setter Property="Height" Value="{Binding ViewportHeight, RelativeSource={RelativeSource AncestorType=ScrollViewer}, Converter={StaticResource DivideConverter}, ConverterParameter=2}" />
                            <Setter Property="Width" Value="{Binding ViewportWidth, RelativeSource={RelativeSource AncestorType=ScrollViewer}, Converter={StaticResource DivideConverter}, ConverterParameter=3}" />

                        </DataTrigger>
                        <DataTrigger Binding="{Binding Orientation, RelativeSource={RelativeSource AncestorType=bpa:FlipView}}" Value="Vertical">
                            <Setter Property="Height" Value="{Binding ViewportHeight, RelativeSource={RelativeSource AncestorType=ScrollViewer}, Converter={StaticResource DivideConverter}, ConverterParameter=3}" />
                            <Setter Property="Width" Value="{Binding ViewportWidth, RelativeSource={RelativeSource AncestorType=ScrollViewer}, Converter={StaticResource DivideConverter}, ConverterParameter=2}" />
                        </DataTrigger>

                        <Trigger Property="IsSelected" Value="True">
                            <Setter Property="Panel.ZIndex" Value="1" />
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style x:Key="CarouselFlipView"
           BasedOn="{StaticResource RubyerFlipView}"
           TargetType="bpa:FlipView">
        <Setter Property="IsLoop" Value="True" />
        <Setter Property="IsAutoPlay" Value="True" />
        <Setter Property="ItemContainerStyle" Value="{StaticResource CarouselFlipViewItem}" />
    </Style>

    <!--  滚动选泽器样式  -->
    <Style x:Key="SelecterFlipViewItem"
           BasedOn="{StaticResource RubyerFlipViewItem}"
           TargetType="bpa:FlipViewItem">
        <Setter Property="Height" Value="Auto" />
        <Setter Property="Width" Value="Auto" />
        <Setter Property="HorizontalContentAlignment" Value="{Binding HorizontalContentAlignment, RelativeSource={RelativeSource AncestorType=bpa:FlipView}}" />
        <Setter Property="VerticalContentAlignment" Value="{Binding VerticalContentAlignment, RelativeSource={RelativeSource AncestorType=bpa:FlipView}}" />
        <Setter Property="Padding" Value="{Binding Path=(bpa:ItemsControlHelper.ItemPadding), RelativeSource={RelativeSource AncestorType=bpa:FlipView}}" />
        <Setter Property="Margin" Value="{Binding Path=(bpa:ItemsControlHelper.ItemMargin), RelativeSource={RelativeSource AncestorType=bpa:FlipView}}" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type bpa:FlipViewItem}">
                    <Grid>
                        <bpa:ControlMask Background="{Binding Path=(bpa:ControlHelper.FocusedBrush), RelativeSource={RelativeSource AncestorType=ItemsControl}}"
                                         CornerRadius="{Binding Path=(bpa:ControlHelper.CornerRadius), RelativeSource={RelativeSource AncestorType=ItemsControl}}"
                                         MaskOpacity="{Binding Path=(bpa:ControlHelper.MaskOpacity), RelativeSource={RelativeSource AncestorType=ItemsControl}}" />

                        <Border x:Name="rootBorder"
                                Background="{TemplateBinding Background}"
                                BorderBrush="{TemplateBinding BorderBrush}"
                                BorderThickness="{TemplateBinding BorderThickness}"
                                CornerRadius="{Binding Path=(bpa:ControlHelper.CornerRadius), RelativeSource={RelativeSource Mode=TemplatedParent}}"
                                RenderTransformOrigin="0.5,0.5">
                            <ContentPresenter x:Name="PART_ContentPresenter"
                                              Margin="{TemplateBinding Padding}"
                                              HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                                              VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                                              Focusable="False"
                                              RecognizesAccessKey="True"
                                              SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
                        </Border>
                    </Grid>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsSelected" Value="True">
                            <Setter Property="Panel.ZIndex" Value="1" />
                            <Setter Property="Foreground" Value="{Binding Path=(bpa:ControlHelper.FocusedForegroundBrush), RelativeSource={RelativeSource AncestorType=ItemsControl}}" />
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style x:Key="SelecterRepeatButton"
           BasedOn="{StaticResource RubyerRepeatButton}"
           TargetType="RepeatButton">
        <Setter Property="Background" Value="{DynamicResource DefaultBackground}" />
        <Setter Property="Foreground" Value="{DynamicResource DefaultForeground}" />
        <Setter Property="bpa:ControlHelper.FocusedBrush" Value="{DynamicResource Primary}" />
    </Style>

    <Style x:Key="SelecterFlipView"
           BasedOn="{StaticResource RubyerFlipView}"
           TargetType="bpa:FlipView">
        <Setter Property="Orientation" Value="Vertical" />
        <Setter Property="IsLoop" Value="True" />
        <Setter Property="IsContinuousSwitching" Value="True" />
        <Setter Property="HorizontalContentAlignment" Value="Center" />
        <Setter Property="VerticalContentAlignment" Value="Center" />
        <Setter Property="ItemContainerStyle" Value="{StaticResource SelecterFlipViewItem}" />
        <Setter Property="ArrowButtonStyle" Value="{StaticResource SelecterRepeatButton}" />
        <Setter Property="AnimateDuration" Value="0:0:0.25" />
        <Setter Property="bpa:ControlHelper.FocusedBrush" Value="{DynamicResource Primary}" />
        <Setter Property="bpa:ControlHelper.FocusedForegroundBrush" Value="{DynamicResource WhiteForeground}" />
        <Setter Property="bpa:ControlHelper.CornerRadius" Value="{DynamicResource AllControlCornerRadius}" />
        <Setter Property="bpa:ItemsControlHelper.ItemMargin" Value="5 0" />
        <Setter Property="bpa:ItemsControlHelper.ItemPadding" Value="5 6" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type bpa:FlipView}">
                    <Border x:Name="rootBorder"
                            Background="{TemplateBinding Background}"
                            BorderBrush="{TemplateBinding BorderBrush}"
                            BorderThickness="{TemplateBinding BorderThickness}"
                            CornerRadius="{Binding Path=(bpa:ControlHelper.CornerRadius), RelativeSource={RelativeSource Mode=TemplatedParent}}">
                        <Grid x:Name="root">
                            <Grid.RowDefinitions>
                                <RowDefinition Height="Auto" />
                                <RowDefinition Height="*" />
                                <RowDefinition Height="Auto" />
                            </Grid.RowDefinitions>

                            <Border Grid.RowSpan="3"
                                    Height="{TemplateBinding FontSize, Converter={StaticResource AddConverter}, ConverterParameter=20}"
                                    Margin="{Binding Path=(bpa:ItemsControlHelper.ItemMargin), RelativeSource={RelativeSource Mode=TemplatedParent}}"
                                    Background="{Binding Path=(bpa:ControlHelper.FocusedBrush), RelativeSource={RelativeSource Mode=TemplatedParent}}"
                                    CornerRadius="{Binding Path=(bpa:ControlHelper.CornerRadius), RelativeSource={RelativeSource Mode=TemplatedParent}}" />
                            <ScrollViewer Name="PART_ContentScrollViewer"
                                          Grid.RowSpan="3"
                                          bpa:ScrollViewerHelper.HorizontalOffset="{TemplateBinding HorizontalOffset}"
                                          bpa:ScrollViewerHelper.VerticalOffset="{TemplateBinding VerticalOffset}"
                                          CanContentScroll="False"
                                          HorizontalScrollBarVisibility="Hidden"
                                          PanningMode="None"
                                          VerticalScrollBarVisibility="Hidden">
                                <ItemsPresenter SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
                            </ScrollViewer>

                            <RepeatButton x:Name="PART_UpButton"
                                          Style="{TemplateBinding ArrowButtonStyle}"
                                          Visibility="Collapsed">
                                <bpa:Icon Type="ArrowUpSLine" />
                            </RepeatButton>

                            <RepeatButton x:Name="PART_DownButton"
                                          Style="{TemplateBinding ArrowButtonStyle}"
                                          Grid.Row="2"
                                          Visibility="Collapsed">
                                <bpa:Icon Type="ArrowDownSLine" />
                            </RepeatButton>
                        </Grid>
                    </Border>

                    <ControlTemplate.Triggers>
                        <Trigger Property="IsMouseOver" Value="True">
                            <Setter TargetName="PART_UpButton" Property="Visibility" Value="Visible" />
                            <Setter TargetName="PART_DownButton" Property="Visibility" Value="Visible" />
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
</ResourceDictionary>