<UserControl
    x:Class="PixiEditor.Views.UserControls.Viewport"
    x:ClassModifier="internal"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:local="clr-namespace:PixiEditor.Views.UserControls"
    xmlns:zoombox="clr-namespace:PixiEditor.Zoombox;assembly=PixiEditor.Zoombox"
    xmlns:sys="clr-namespace:System;assembly=System.Runtime"
    xmlns:transformOverlay="clr-namespace:PixiEditor.Views.UserControls.Overlays.TransformOverlay"
    xmlns:lineOverlay="clr-namespace:PixiEditor.Views.UserControls.Overlays.LineToolOverlay"
    xmlns:uc="clr-namespace:PixiEditor.Views.UserControls"
    xmlns:overlays="clr-namespace:PixiEditor.Views.UserControls.Overlays"
    xmlns:symOverlay="clr-namespace:PixiEditor.Views.UserControls.Overlays.SymmetryOverlay"
    xmlns:brushOverlay="clr-namespace:PixiEditor.Views.UserControls.Overlays.BrushShapeOverlay"
    xmlns:i="http://schemas.microsoft.com/xaml/behaviors"
    xmlns:vm="clr-namespace:PixiEditor.ViewModels"
    xmlns:converters="clr-namespace:PixiEditor.Helpers.Converters"
    xmlns:cmds="clr-namespace:PixiEditor.Models.Commands.XAML"
    xmlns:tools ="clr-namespace:PixiEditor.ViewModels.SubViewModels.Tools.Tools"
    xmlns:views="clr-namespace:PixiEditor.Views"
    xmlns:subviews="clr-namespace:PixiEditor.ViewModels.SubViewModels.Document"
    xmlns:ui="clr-namespace:PixiEditor.Extensions.UI;assembly=PixiEditor.Extensions"
    mc:Ignorable="d"
    x:Name="vpUc"
    d:DesignHeight="450"
    d:DesignWidth="800">
    <Grid 
        x:Name="mainGrid"
        MouseDown="Image_MouseDown"
        MouseUp="Image_MouseUp"
        PreviewMouseDown="Grid_PreviewMouseDown">
        <i:Interaction.Triggers>
            <i:EventTrigger EventName="StylusButtonDown">
                <i:InvokeCommandAction Command="{Binding StylusButtonDownCommand, ElementName=vpUc}"
                                        PassEventArgsToCommand="True"/>
            </i:EventTrigger>
            <i:EventTrigger EventName="StylusButtonUp">
                <i:InvokeCommandAction Command="{Binding StylusButtonUpCommand, ElementName=vpUc}"
                                        PassEventArgsToCommand="True"/>
            </i:EventTrigger>
            <i:EventTrigger EventName="StylusSystemGesture">
                <i:InvokeCommandAction Command="{Binding StylusGestureCommand, ElementName=vpUc}"
                                        PassEventArgsToCommand="True"/>
            </i:EventTrigger>
            <i:EventTrigger EventName="StylusOutOfRange">
                <i:InvokeCommandAction Command="{Binding StylusOutOfRangeCommand, ElementName=vpUc}"
                                        PassEventArgsToCommand="True"/>
            </i:EventTrigger>
        </i:Interaction.Triggers>
        <views:TogglableFlyout Margin="5" IconPath="/Images/Settings.png" ui:Translator.TooltipKey="VIEWPORT_SETTINGS"
                               Panel.ZIndex="2" HorizontalAlignment="Right" VerticalAlignment="Top">
            <views:TogglableFlyout.Child>
                <Border BorderThickness="1" CornerRadius="5" Padding="5" Background="#C8202020" Panel.ZIndex="2">
        <StackPanel Orientation="Vertical">
            <StackPanel Orientation="Horizontal">
            <TextBlock Margin="5 0" TextAlignment="Center"
                       Text="{Binding Path=Angle, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=local:Viewport}, 
             Converter={converters:RadiansToDegreesConverter}, StringFormat={}{0}°}"
                       Width="35" Foreground="White" VerticalAlignment="Center" FontSize="16"/>
            <Button Width="32" Height="32" ui:Translator.TooltipKey="RESET_VIEWPORT"
                    Style="{StaticResource OverlayButton}"
                    Click="ResetViewportClicked"
                    Cursor="Hand">
            <Button.Content>
                <Image Width="28" Height="28" Source="/Images/Layout.png"/>
            </Button.Content>
            </Button>
        </StackPanel>
            <Separator/>
            <StackPanel HorizontalAlignment="Right" Orientation="Horizontal">
                <ToggleButton Width="32" Height="32" ui:Translator.TooltipKey="TOGGLE_VERTICAL_SYMMETRY"
                        Style="{StaticResource OverlayToggleButton}"
                        IsChecked="{Binding Document.VerticalSymmetryAxisEnabledBindable, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=local:Viewport}, Mode=TwoWay}"
                        Cursor="Hand">
                    <ToggleButton.Content>
                        <Image Width="28" Height="28" Source="/Images/SymmetryVertical.png"/>
                    </ToggleButton.Content>
                </ToggleButton>
                <ToggleButton Margin="10 0 0 0" Width="32" Height="32" ui:Translator.TooltipKey="TOGGLE_HORIZONTAL_SYMMETRY"
                              Style="{StaticResource OverlayToggleButton}"
                              IsChecked="{Binding Document.HorizontalSymmetryAxisEnabledBindable, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=local:Viewport}, Mode=TwoWay}"
                              Cursor="Hand">
                    <ToggleButton.Content>
                        <Image Width="28" Height="28" Source="/Images/SymmetryVertical.png">
                            <Image.LayoutTransform>
                                <RotateTransform Angle="90"/>
                            </Image.LayoutTransform>
                        </Image>
                    </ToggleButton.Content>
                </ToggleButton>
            </StackPanel>
            <Separator/>
            <StackPanel HorizontalAlignment="Right" Orientation="Horizontal">
                <ToggleButton Width="32" Height="32" ui:Translator.TooltipKey="FLIP_VIEWPORT_HORIZONTALLY"
                              Style="{StaticResource OverlayToggleButton}"
                              IsChecked="{Binding FlipX, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=local:Viewport}, Mode=TwoWay}"
                              Cursor="Hand">
                    <ToggleButton.Content>
                        <Image Width="28" Height="28" Source="/Images/FlipHorizontal.png"/>
                    </ToggleButton.Content>
                </ToggleButton>
                <ToggleButton Margin="10 0 0 0" Width="32" Height="32" ui:Translator.TooltipKey="FLIP_VIEWPORT_VERTICALLY"
                              Style="{StaticResource OverlayToggleButton}"
                              IsChecked="{Binding FlipY, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=local:Viewport}, Mode=TwoWay}"
                              Cursor="Hand">
                    <ToggleButton.Content>
                        <Image Width="28" Height="28" Source="/Images/FlipHorizontal.png">
                            <Image.LayoutTransform>
                                <RotateTransform Angle="90"/>
                            </Image.LayoutTransform>
                        </Image>
                    </ToggleButton.Content>
                </ToggleButton>
            </StackPanel>
        </StackPanel>
        </Border>
            </views:TogglableFlyout.Child>
        </views:TogglableFlyout>
        <zoombox:Zoombox
            Tag="{Binding ElementName=vpUc}"
            x:Name="zoombox"
            UseTouchGestures="{Binding UseTouchGestures, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=local:Viewport}, Mode=OneWay}"
            Scale="{Binding ZoomboxScale, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=local:Viewport}, Mode=OneWayToSource}"
            Center="{Binding Center, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=local:Viewport}, Mode=OneWayToSource}"
            Angle="{Binding Angle, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=local:Viewport}, Mode=OneWayToSource}"
            RealDimensions="{Binding RealDimensions, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=local:Viewport}, Mode=OneWayToSource}"
            Dimensions="{Binding Dimensions, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=local:Viewport}, Mode=OneWayToSource}"
            ZoomMode="{Binding ZoomMode, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=local:Viewport}, Mode=TwoWay}"
            ZoomOutOnClick="{Binding ZoomOutOnClick, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=local:Viewport}, Mode=TwoWay}"
            FlipX="{Binding FlipX, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=local:Viewport}, Mode=TwoWay}"
            FlipY="{Binding FlipY, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=local:Viewport}, Mode=TwoWay}">
            <Border
                d:Width="64"
                d:Height="64"
                HorizontalAlignment="Center"
                VerticalAlignment="Center"
                DataContext="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=local:Viewport}}"
                RenderOptions.BitmapScalingMode="NearestNeighbor">
                <Border.Background>
                    <ImageBrush ImageSource="/Images/CheckerTile.png" TileMode="Tile" ViewportUnits="Absolute">
                        <ImageBrush.Viewport>
                            <Binding Path="Scale" RelativeSource="{RelativeSource FindAncestor, AncestorType={x:Type zoombox:Zoombox}}" Converter="{converters:ZoomToViewportConverter}">
                                <Binding.ConverterParameter>
                                    <sys:Double>16</sys:Double>
                                </Binding.ConverterParameter>
                            </Binding>
                        </ImageBrush.Viewport>
                    </ImageBrush>
                </Border.Background>
                <Grid>
                    <Canvas
                        ZIndex="{Binding Document.ReferenceLayerViewModel.ShowHighest, Converter={converters:BoolToIntConverter}}"
                        IsHitTestVisible="{Binding Document.ReferenceLayerViewModel.IsTransforming}">
                        <Image
                            Focusable="False"
                            Width="{Binding Document.ReferenceLayerViewModel.ReferenceBitmap.Width}"
                            Height="{Binding Document.ReferenceLayerViewModel.ReferenceBitmap.Height}"
                            Source="{Binding Document.ReferenceLayerViewModel.ReferenceBitmap, Mode=OneWay}"
                            Visibility="{Binding Document.ReferenceLayerViewModel.IsVisibleBindable, Converter={converters:BoolToHiddenVisibilityConverter}}"
                            SizeChanged="OnReferenceImageSizeChanged"
                            RenderOptions.BitmapScalingMode="{Binding ReferenceLayerScale, Converter={converters:ScaleToBitmapScalingModeConverter}}"
                            FlowDirection="LeftToRight">
                            <Image.RenderTransform>
                                <TransformGroup>
                                    <MatrixTransform
                                        Matrix="{Binding Document.ReferenceLayerViewModel.ReferenceTransformMatrix}" />
                                </TransformGroup>
                            </Image.RenderTransform>
                            <Image.Style>
                                <Style>
                                    <Style.Triggers>
                                        <DataTrigger Binding="{Binding Document.ReferenceLayerViewModel.ShowHighest, Mode=OneWay}" Value="True">
                                            <DataTrigger.EnterActions>
                                                <BeginStoryboard>
                                                    <Storyboard>
                                                        <DoubleAnimation 
                                                            Storyboard.TargetProperty="(Button.Opacity)" 
                                                            From="1" To="{x:Static subviews:ReferenceLayerViewModel.TopMostOpacity}" Duration="0:0:0.1" /> 
                                                    </Storyboard>
                                                </BeginStoryboard>
                                            </DataTrigger.EnterActions>
                                            <DataTrigger.ExitActions>
                                                <BeginStoryboard>
                                                    <Storyboard>
                                                        <DoubleAnimation 
                                                            Storyboard.TargetProperty="(Button.Opacity)" 
                                                            From="{x:Static subviews:ReferenceLayerViewModel.TopMostOpacity}" To="1" Duration="0:0:0.1" /> 
                                                    </Storyboard>
                                                </BeginStoryboard>
                                            </DataTrigger.ExitActions>
                                        </DataTrigger>
                                    </Style.Triggers>
                                </Style>
                            </Image.Style>
                        </Image>
                        <Canvas.Style>
                            <Style>
                                <Style.Triggers>
                                    <DataTrigger Binding="{Binding Source={vm:ToolVM ColorPickerToolViewModel}, Path=PickFromReferenceLayer, Mode=OneWay}" Value="False">
                                        <DataTrigger.EnterActions>
                                            <BeginStoryboard>
                                                <Storyboard>
                                                    <DoubleAnimation 
                                                        Storyboard.TargetProperty="(Button.Opacity)" 
                                                        From="1" To="0" Duration="0:0:0.1" /> 
                                                </Storyboard>
                                            </BeginStoryboard>
                                        </DataTrigger.EnterActions>
                                        <DataTrigger.ExitActions>
                                            <BeginStoryboard>
                                                <Storyboard>
                                                    <DoubleAnimation 
                                                        Storyboard.TargetProperty="(Button.Opacity)" 
                                                        From="0" To="1" Duration="0:0:0.1" /> 
                                                </Storyboard>
                                            </BeginStoryboard>
                                        </DataTrigger.ExitActions>
                                    </DataTrigger>
                                </Style.Triggers>
                            </Style>
                        </Canvas.Style>
                    </Canvas>
                    <Image
                        Focusable="False"
                        Width="{Binding Document.Width}"
                        Height="{Binding Document.Height}"
                        Source="{Binding TargetBitmap}"
                        RenderOptions.BitmapScalingMode="{Binding Zoombox.Scale, Converter={converters:ScaleToBitmapScalingModeConverter}}"
                        FlowDirection="LeftToRight">
                        <Image.Style>
                            <Style>
                                <Style.Triggers>
                                    <DataTrigger Binding="{Binding Source={vm:ToolVM ColorPickerToolViewModel}, Path=PickOnlyFromReferenceLayer, Mode=OneWay}" Value="True">
                                        <DataTrigger.EnterActions>
                                            <BeginStoryboard>
                                                <Storyboard>
                                                    <DoubleAnimation 
                                                        Storyboard.TargetProperty="(Button.Opacity)" 
                                                        From="1" To="0" Duration="0:0:0.1" /> 
                                                </Storyboard>
                                            </BeginStoryboard>
                                        </DataTrigger.EnterActions>
                                        <DataTrigger.ExitActions>
                                            <BeginStoryboard>
                                                <Storyboard>
                                                    <DoubleAnimation 
                                                        Storyboard.TargetProperty="(Button.Opacity)" 
                                                        From="0" To="1" Duration="0:0:0.1" /> 
                                                </Storyboard>
                                            </BeginStoryboard>
                                        </DataTrigger.ExitActions>
                                    </DataTrigger>
                                </Style.Triggers>
                            </Style>
                        </Image.Style>
                    </Image>
                    <Grid ZIndex="5">
                        <symOverlay:SymmetryOverlay
                            Focusable="False"
                            IsHitTestVisible="{Binding ZoomMode, Converter={converters:ZoomModeToHitTestVisibleConverter}}"
                            ZoomboxScale="{Binding Zoombox.Scale}"
                            HorizontalAxisVisible="{Binding Document.HorizontalSymmetryAxisEnabledBindable}"
                            VerticalAxisVisible="{Binding Document.VerticalSymmetryAxisEnabledBindable}"
                            HorizontalAxisY="{Binding Document.HorizontalSymmetryAxisYBindable, Mode=OneWay}"
                            VerticalAxisX="{Binding Document.VerticalSymmetryAxisXBindable, Mode=OneWay}"
                            DragCommand="{cmds:Command PixiEditor.Document.DragSymmetry, UseProvided=True}"
                            DragEndCommand="{cmds:Command PixiEditor.Document.EndDragSymmetry, UseProvided=True}"
                            DragStartCommand="{cmds:Command PixiEditor.Document.StartDragSymmetry, UseProvided=True}"
                            FlowDirection="LeftToRight" />
                        <overlays:SelectionOverlay
                            Focusable="False"
                            ShowFill="{Binding ToolsSubViewModel.ActiveTool, Source={vm:MainVM}, Converter={converters:IsSelectionToolConverter}}"
                            Path="{Binding Document.SelectionPathBindable}"
                            ZoomboxScale="{Binding Zoombox.Scale}"
                            FlowDirection="LeftToRight" />
                        <brushOverlay:BrushShapeOverlay
                            Focusable="False"
                            IsHitTestVisible="False"
                            Visibility="{Binding Document.TransformViewModel.TransformActive, Converter={converters:InverseBoolToVisibilityConverter}}"
                            ZoomboxScale="{Binding Zoombox.Scale}"
                            MouseEventSource="{Binding Zoombox.Tag.BackgroundGrid, Mode=OneTime}"
                            MouseReference="{Binding Zoombox.Tag.MainImage, Mode=OneTime}"
                            BrushSize="{Binding ToolsSubViewModel.ActiveBasicToolbar.ToolSize, Source={vm:MainVM}}"
                            BrushShape="{Binding ToolsSubViewModel.ActiveTool.BrushShape, Source={vm:MainVM}, FallbackValue={x:Static brushOverlay:BrushShape.Hidden}}"
                            FlowDirection="LeftToRight"/>
                        <transformOverlay:TransformOverlay
                            Focusable="False"
                            Cursor="Arrow"
                            IsHitTestVisible="{Binding ZoomMode, Converter={converters:ZoomModeToHitTestVisibleConverter}}"
                            HorizontalAlignment="Stretch"
                            VerticalAlignment="Stretch"
                            Visibility="{Binding Document.TransformViewModel.TransformActive, Converter={converters:BoolToVisibilityConverter}}"
                            ActionCompleted="{Binding Document.TransformViewModel.ActionCompletedCommand}"
                            Corners="{Binding Document.TransformViewModel.Corners, Mode=TwoWay}"
                            RequestedCorners="{Binding Document.TransformViewModel.RequestedCorners, Mode=TwoWay}"
                            CornerFreedom="{Binding Document.TransformViewModel.CornerFreedom}"
                            SideFreedom="{Binding Document.TransformViewModel.SideFreedom}"
                            LockRotation="{Binding Document.TransformViewModel.LockRotation}"
                            CoverWholeScreen="{Binding Document.TransformViewModel.CoverWholeScreen}"
                            SnapToAngles="{Binding Document.TransformViewModel.SnapToAngles}"
                            InternalState="{Binding Document.TransformViewModel.InternalState, Mode=TwoWay}"
                            ZoomboxScale="{Binding Zoombox.Scale}"
                            ZoomboxAngle="{Binding Zoombox.Angle}" />
                        <lineOverlay:LineToolOverlay
                            Focusable="False"
                            Visibility="{Binding Document.LineToolOverlayViewModel.IsEnabled, Converter={converters:BoolToVisibilityConverter}}"
                            ActionCompleted="{Binding Document.LineToolOverlayViewModel.ActionCompletedCommand}"
                            LineStart="{Binding Document.LineToolOverlayViewModel.LineStart, Mode=TwoWay}"
                            LineEnd="{Binding Document.LineToolOverlayViewModel.LineEnd, Mode=TwoWay}"
                            ZoomboxScale="{Binding Zoombox.Scale}"
                            FlowDirection="LeftToRight"/>
                    </Grid>
                    <Grid IsHitTestVisible="False" 
                        ShowGridLines="True" Width="{Binding Document.Width}" Height="{Binding Document.Height}" Panel.ZIndex="10" 
                        Visibility="{Binding GridLinesVisible, Converter={converters:BoolToVisibilityConverter}, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=local:Viewport}}">
                        <Grid.Resources>
                            <converters:ThresholdVisibilityConverter Threshold="10" x:Key="ThresholdVisibilityConverter"/>
                        </Grid.Resources>
                        <Rectangle Focusable="False" Visibility="{Binding Zoombox.Scale, Converter={StaticResource ThresholdVisibilityConverter}}">
                            <Rectangle.Fill>
                                <VisualBrush Viewport="{Binding Document.Width, Converter={converters:IntToViewportRectConverter}, ConverterParameter=vertical}" ViewboxUnits="Absolute" TileMode="Tile" >
                                    <VisualBrush.Visual>
                                        <Line X1="0" Y1="0" X2="0" Y2="1" Stroke="Black" 
                                              StrokeThickness="{Binding Zoombox.Scale, Converter={converters:ReciprocalConverter}}"/>
                                    </VisualBrush.Visual>
                                </VisualBrush>
                            </Rectangle.Fill>
                        </Rectangle>
                        <Rectangle Focusable="False" Visibility="{Binding Zoombox.Scale, Converter={StaticResource ThresholdVisibilityConverter}}">
                            <Rectangle.Fill>
                                <VisualBrush Viewport="{Binding Document.Height, Converter={converters:IntToViewportRectConverter}}" ViewboxUnits="Absolute" TileMode="Tile" >
                                    <VisualBrush.Visual>
                                        <Line X1="0" Y1="0" X2="1" Y2="0" Stroke="Black" StrokeThickness="{Binding Zoombox.Scale, Converter={converters:ReciprocalConverter}}"/>
                                    </VisualBrush.Visual>
                                </VisualBrush>
                            </Rectangle.Fill>
                        </Rectangle>
                        <Rectangle Focusable="False" Visibility="{Binding Zoombox.Scale, Converter={StaticResource ThresholdVisibilityConverter}}">
                            <Rectangle.Fill>
                                <VisualBrush Viewport="{Binding Document.Width, Converter={converters:IntToViewportRectConverter}, ConverterParameter=vertical}" ViewboxUnits="Absolute" TileMode="Tile" >
                                    <VisualBrush.Visual>
                                        <Line X1="0" Y1="0" X2="0" Y2="1" Stroke="White">
                                            <Line.StrokeThickness>
                                                <Binding Converter="{converters:ReciprocalConverter}">
                                                    <Binding.Path>Zoombox.Scale</Binding.Path>
                                                    <Binding.ConverterParameter>
                                                        <sys:Double>
                                                            1.1
                                                        </sys:Double>
                                                    </Binding.ConverterParameter>
                                                </Binding>
                                            </Line.StrokeThickness>
                                        </Line>
                                    </VisualBrush.Visual>
                                </VisualBrush>
                            </Rectangle.Fill>
                        </Rectangle>
                        <Rectangle Focusable="False" Visibility="{Binding Zoombox.Scale, Converter={StaticResource ThresholdVisibilityConverter}}">
                            <Rectangle.Fill>
                                <VisualBrush Viewport="{Binding Document.Height, Converter={converters:IntToViewportRectConverter}}" ViewboxUnits="Absolute" TileMode="Tile" >
                                    <VisualBrush.Visual>
                                        <Line X1="0" Y1="0" X2="1" Y2="0" Stroke="White">
                                            <Line.StrokeThickness>
                                                <Binding Converter="{converters:ReciprocalConverter}">
                                                    <Binding.Path>Zoombox.Scale</Binding.Path>
                                                    <Binding.ConverterParameter>
                                                        <sys:Double>
                                                            1.1
                                                        </sys:Double>
                                                    </Binding.ConverterParameter>
                                                </Binding>
                                            </Line.StrokeThickness>
                                        </Line>
                                    </VisualBrush.Visual>
                                </VisualBrush>
                            </Rectangle.Fill>
                        </Rectangle>
                    </Grid>
                    <Rectangle Stroke="{StaticResource AccentColor}" Opacity=".8" Panel.ZIndex="2" Visibility="{Binding Document.ReferenceLayerViewModel.IsVisibleBindable, Converter={converters:BoolToHiddenVisibilityConverter}}">
                        <Rectangle.StrokeThickness>
                            <Binding Converter="{converters:ReciprocalConverter}">
                                <Binding.Path>Zoombox.Scale</Binding.Path>
                                <Binding.ConverterParameter>
                                    <sys:Double>
                                        3
                                    </sys:Double>
                                </Binding.ConverterParameter>
                            </Binding>
                        </Rectangle.StrokeThickness>
                        <Rectangle.Margin>
                            <Binding Converter="{converters:ReciprocalConverter}">
                                <Binding.Path>Zoombox.Scale</Binding.Path>
                                <Binding.ConverterParameter>
                                    <sys:Double>
                                        -3
                                    </sys:Double>
                                </Binding.ConverterParameter>
                            </Binding>
                        </Rectangle.Margin>
                    </Rectangle>
                </Grid>
            </Border>
        </zoombox:Zoombox>
        <Button 
            Panel.ZIndex="99999"
            DockPanel.Dock="Bottom"
            Margin="5"
            Padding="8,5,5,5"
            VerticalAlignment="Bottom" 
            HorizontalAlignment="Center"
            Style="{StaticResource GrayRoundButton}"
            Command="{cmds:Command PixiEditor.Tools.ApplyTransform}">
            <Button.Visibility>
                <MultiBinding Converter="{converters:BoolOrToVisibilityConverter}">
                    <MultiBinding.Bindings>
                        <Binding ElementName="vpUc" Path="Document.TransformViewModel.ShowTransformControls"/>
                        <Binding ElementName="vpUc" Path="Document.LineToolOverlayViewModel.IsEnabled"/>
                    </MultiBinding.Bindings>
                </MultiBinding>
            </Button.Visibility>
            <StackPanel Orientation="Horizontal">
                <TextBlock ui:Translator.Key="APPLY_TRANSFORM" VerticalAlignment="Center" Margin="0,0,5,0" />
                <Border Padding="10,3" CornerRadius="5" Background="{StaticResource AccentColor}" Visibility="{cmds:ShortcutBinding PixiEditor.Tools.ApplyTransform, Converter={converters:NotNullToVisibilityConverter}}">
                    <TextBlock Text="{cmds:ShortcutBinding PixiEditor.Tools.ApplyTransform}" />
                </Border>
            </StackPanel>
        </Button>
    </Grid>
</UserControl>
