<UserControl x:Class="HavenSoft.HexManiac.WPF.Controls.ImageEditorView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:sys="clr-namespace:System;assembly=System.Runtime"
             xmlns:hshmcvm="clr-namespace:HavenSoft.HexManiac.Core.ViewModels;assembly=HexManiac.Core"
             xmlns:hshmwpfc="clr-namespace:HavenSoft.HexManiac.WPF.Controls"
             xmlns:hshmwpfr="clr-namespace:HavenSoft.HexManiac.WPF.Resources"
             xmlns:local="clr-namespace:HavenSoft.HexManiac.WPF.Controls"
             Focusable="True">
   <UserControl.Resources>
      <sys:Boolean x:Key="True">True</sys:Boolean>
      <sys:Boolean x:Key="False">False</sys:Boolean>
   </UserControl.Resources>
   <UserControl.InputBindings>
      <KeyBinding Key="Add" Command="{Binding ZoomInCommand}"/>
      <KeyBinding Key="Subtract" Command="{Binding ZoomOutCommand}"/>
      <KeyBinding Key="Delete" Command="{Binding DeleteCommand}"/>
      <KeyBinding Key="A" CommandParameter="{x:Static hshmcvm:ImageEditorTools.Pan}" Command="{Binding SelectTool}"/>
      <KeyBinding Key="S" CommandParameter="{x:Static hshmcvm:ImageEditorTools.Select}" Command="{Binding SelectTool}"/>
      <KeyBinding Key="D" CommandParameter="{x:Static hshmcvm:ImageEditorTools.Draw}" Command="{Binding SelectTool}"/>
      <KeyBinding Key="F" CommandParameter="{x:Static hshmcvm:ImageEditorTools.Fill}" Command="{Binding SelectTool}"/>
      <KeyBinding Key="G" CommandParameter="{x:Static hshmcvm:ImageEditorTools.EyeDropper}" Command="{Binding SelectTool}"/>
      <KeyBinding Key="H" CommandParameter="{x:Static hshmcvm:ImageEditorTools.TilePalette}" Command="{Binding SelectTool}"/>
      <KeyBinding Key="C" Modifiers="Ctrl" CommandParameter="{DynamicResource FileSystem}" Command="{Binding Copy}"/>
      <KeyBinding Key="V" Modifiers="Ctrl" CommandParameter="{DynamicResource FileSystem}" Command="{Binding Paste}"/>
      <KeyBinding Key="A" Modifiers="Ctrl" Command="{Binding SelectAll}"/>
      <KeyBinding Key="Space" CommandParameter="0" Command="{Binding SelectColor}"/>
      <KeyBinding Key="D0" CommandParameter="0" Command="{Binding SelectColor}"/>
      <KeyBinding Key="D1" CommandParameter="1" Command="{Binding SelectColor}"/>
      <KeyBinding Key="D2" CommandParameter="2" Command="{Binding SelectColor}"/>
      <KeyBinding Key="D3" CommandParameter="3" Command="{Binding SelectColor}"/>
      <KeyBinding Key="D4" CommandParameter="4" Command="{Binding SelectColor}"/>
      <KeyBinding Key="D5" CommandParameter="5" Command="{Binding SelectColor}"/>
      <KeyBinding Key="D6" CommandParameter="6" Command="{Binding SelectColor}"/>
      <KeyBinding Key="D7" CommandParameter="7" Command="{Binding SelectColor}"/>
      <KeyBinding Key="D1" Modifiers="Shift" Command="{Binding SetCursorSize}" CommandParameter="1" />
      <KeyBinding Key="D2" Modifiers="Shift" Command="{Binding SetCursorSize}" CommandParameter="2" />
      <KeyBinding Key="D3" Modifiers="Shift" Command="{Binding SetCursorSize}" CommandParameter="4" />
      <KeyBinding Key="D4" Modifiers="Shift" Command="{Binding SetCursorSize}" CommandParameter="8" />
   </UserControl.InputBindings>
   <DockPanel>
      <DockPanel DockPanel.Dock="Left" MouseLeftButtonDown="ClearPopups" Background="Transparent">
         <DockPanel.Resources>
            <Style TargetType="Path">
               <Setter Property="Fill" Value="{DynamicResource Primary}"/>
               <Setter Property="Stretch" Value="Uniform"/>
               <Setter Property="Width" Value="24"/>
               <Setter Property="Height" Value="24"/>
               <Style.Triggers>
                  <DataTrigger Binding="{Binding IsChecked, RelativeSource={RelativeSource AncestorType=RadioButton}}" Value="True">
                     <Setter Property="Fill" Value="{DynamicResource Accent}"/>
                  </DataTrigger>
               </Style.Triggers>
            </Style>
         </DockPanel.Resources>
         <Rectangle Width="1" DockPanel.Dock="Right" Fill="{DynamicResource Backlight}"/>
         <ComboBox DockPanel.Dock="Top" HorizontalAlignment="Center"
            ItemsSource="{Binding EditOptions}"
            SelectedIndex="{Binding SelectedEditOption}"
            Visibility="{Binding HasMultipleEditOptions, Converter={StaticResource BoolToVisibility}}">
            <ComboBox.ItemTemplate>
               <DataTemplate>
                  <local:PixelImage/>
               </DataTemplate>
            </ComboBox.ItemTemplate>
         </ComboBox>
         <Slider DockPanel.Dock="Top" Margin="5"
            Visibility="{Binding CanEditTilesetWidth, Converter={StaticResource BoolToVisibility}}"
            Minimum="{Binding MinimumTilesetWidth}"
            Maximum="{Binding MaximumTilesetWidth}"
            Value="{Binding CurrentTilesetWidth}">
            <Slider.ToolTip>
               <ToolTip>
                  <TextBlock>
                     <Bold>Adjust Tileset Width</Bold><LineBreak/>
                     <LineBreak/>
                     Tilesets aren't images, so they don't have a<LineBreak/>
                     natural width and height. <LineBreak/>
                     Use this slider to adjust the displayed width/height of<LineBreak/>
                     the tileset. This can line tiles up in a way that makes<LineBreak/>
                     them easier to edit.
                  </TextBlock>
               </ToolTip>
            </Slider.ToolTip>
         </Slider>
         <StackPanel Orientation="Horizontal" DockPanel.Dock="Top" HorizontalAlignment="Center">
            <StackPanel.Resources>
               <Style TargetType="RadioButton" BasedOn="{StaticResource {x:Type ToggleButton}}">
                  <Setter Property="Command" Value="{Binding SelectTool}"/>
                  <Setter Property="Width" Value="30"/>
                  <Setter Property="Height" Value="30"/>
                  <Setter Property="HorizontalContentAlignment" Value="Center"/>
                  <Setter Property="VerticalContentAlignment" Value="Center"/>
               </Style>
            </StackPanel.Resources>
            <Decorator ToolTip="Undo (Ctrl+Z)">
               <Button Command="{Binding Undo}">
                  <Path Data="{hshmwpfr:Icon UndoArrow}"/>
               </Button>
            </Decorator>
            <Decorator ToolTip="Redo (Ctrl+Y)">
               <Button Command="{Binding Redo}">
                  <Path Data="{hshmwpfr:Icon RedoArrow}"/>
               </Button>
            </Decorator>
            <StackPanel>
               <Button Command="{Binding ZoomInCommand}" Width="30" Height="15">
                  <Button.Content>
                     <TextBlock VerticalAlignment="Center" Foreground="{DynamicResource Primary}">+</TextBlock>
                  </Button.Content>
                  <Button.ToolTip>
                     <ToolTip>
                        <DockPanel>
                           <Path Data="{hshmwpfr:Icon MiddleMouseButton}" Fill="{DynamicResource Secondary}" DockPanel.Dock="Right" VerticalAlignment="Top"/>
                           <TextBlock>
                              (+) Zoom In<LineBreak/>
                              <Italic Foreground="{DynamicResource Secondary}">
                                 Increase the apparent size of each pixel in the image.
                              </Italic>
                           </TextBlock>
                        </DockPanel>
                     </ToolTip>
                  </Button.ToolTip>
               </Button>
               <Button Command="{Binding ZoomOutCommand}" Width="30" Height="15">
                  <Button.Content>
                     <TextBlock VerticalAlignment="Center" Foreground="{DynamicResource Primary}">-</TextBlock>
                  </Button.Content>
                  <Button.ToolTip>
                     <ToolTip>
                        <DockPanel>
                           <Path Data="{hshmwpfr:Icon MiddleMouseButton}" Fill="{DynamicResource Secondary}" DockPanel.Dock="Right" VerticalAlignment="Top"/>
                           <TextBlock>
                              (-) Zoom Out<LineBreak/>
                              <Italic Foreground="{DynamicResource Secondary}">
                                 Decrease the apparent size of each pixel in the image.
                              </Italic>
                           </TextBlock>
                        </DockPanel>
                     </ToolTip>
                  </Button.ToolTip>
               </Button>
            </StackPanel>
            <RadioButton CommandParameter="{x:Static hshmcvm:ImageEditorTools.Pan}"
               IsChecked="{Binding SelectedTool, Mode=OneWay, Converter={StaticResource EqualityCheck}, ConverterParameter={x:Static hshmcvm:ImageEditorTools.Pan}}">
               <RadioButton.Content>
                  <Path Data="{hshmwpfr:Icon FourDirectionArrows}"/>
               </RadioButton.Content>
               <RadioButton.ToolTip>
                  <ToolTip>
                     <DockPanel>
                        <Path Data="{hshmwpfr:Icon MiddleMouseButton}" Fill="{DynamicResource Secondary}" DockPanel.Dock="Right" VerticalAlignment="Top"/>
                        <TextBlock>
                        (A)rrange Position <LineBreak/>
                        <Italic Foreground="{DynamicResource Secondary}">
                           Move the sprite around on the screen to see it better.
                        </Italic>
                        </TextBlock>
                     </DockPanel>
                  </ToolTip>
               </RadioButton.ToolTip>
            </RadioButton>
            <RadioButton CommandParameter="{x:Static hshmcvm:ImageEditorTools.Select}"
               IsChecked="{Binding SelectedTool, Mode=OneWay, Converter={StaticResource EqualityCheck}, ConverterParameter={x:Static hshmcvm:ImageEditorTools.Select}}">
               <RadioButton.Content>
                  <Path Data="{hshmwpfr:Icon Selection}"/>
               </RadioButton.Content>
               <RadioButton.ToolTip>
                  <ToolTip>
                     <TextBlock>
                     (S)elect Section<LineBreak/>
                     <Italic Foreground="{DynamicResource Secondary}">
                        Drag to select a rectangle of pixels. <LineBreak/>
                        Then drag again to move them around. <LineBreak/>
                        You can also use Copy/Paste with the selection, or <LineBreak/>
                        Ctrl+Drag to make a copy of the selection.
                     </Italic>
                     </TextBlock>
                  </ToolTip>
               </RadioButton.ToolTip>
            </RadioButton>
            <RadioButton CommandParameter="{x:Static hshmcvm:ImageEditorTools.Draw}"
               IsChecked="{Binding SelectedTool, Mode=OneWay, Converter={StaticResource EqualityCheck}, ConverterParameter={x:Static hshmcvm:ImageEditorTools.Draw}}">
               <RadioButton.Content>
                  <Path Data="{hshmwpfr:Icon Pencil}"/>
               </RadioButton.Content>
               <RadioButton.ToolTip>
                  <ToolTip>
                     <TextBlock>
                     (D)raw Pixels <LineBreak/>
                     <Italic Foreground="{DynamicResource Secondary}">
                        Draw individual pixels by selecting a color. <LineBreak/>
                        If you use (g)rab color to select a block, <LineBreak/>
                        you can draw entire blocks or patterns at once.
                     </Italic>
                     </TextBlock>
                  </ToolTip>
               </RadioButton.ToolTip>
            </RadioButton>
            <RadioButton CommandParameter="{x:Static hshmcvm:ImageEditorTools.Fill}"
               IsChecked="{Binding SelectedTool, Mode=OneWay, Converter={StaticResource EqualityCheck}, ConverterParameter={x:Static hshmcvm:ImageEditorTools.Fill}}">
               <RadioButton.Content>
                  <Path Data="{hshmwpfr:Icon FillBucket}"/>
               </RadioButton.Content>
               <RadioButton.ToolTip>
                  <ToolTip>
                     <TextBlock>
                     (F)ill Area<LineBreak/>
                     <Italic Foreground="{DynamicResource Secondary}">
                        Fill an entire region with a color. <LineBreak/>
                        Click and drag to fill a region with a gradient.
                     </Italic>
                     </TextBlock>
                  </ToolTip>
               </RadioButton.ToolTip>
            </RadioButton>
            <RadioButton CommandParameter="{x:Static hshmcvm:ImageEditorTools.EyeDropper}"
               IsChecked="{Binding SelectedTool, Mode=OneWay, Converter={StaticResource EqualityCheck}, ConverterParameter={x:Static hshmcvm:ImageEditorTools.EyeDropper}}">
               <RadioButton.Content>
                  <Path Data="{hshmwpfr:Icon EyeDropper}"/>
               </RadioButton.Content>
               <RadioButton.ToolTip>
                  <ToolTip>
                     <DockPanel>
                        <Path Data="{hshmwpfr:Icon RightMouseButton}" Fill="{DynamicResource Secondary}" DockPanel.Dock="Right" VerticalAlignment="Top"/>
                        <TextBlock>
                        (G)rab Color <LineBreak/>
                        <Italic Foreground="{DynamicResource Secondary}">
                           Select a specific color by clicking it. <LineBreak/>
                           Click and drag to grab a block of colors instead.
                        </Italic>
                        </TextBlock>
                     </DockPanel>
                  </ToolTip>
               </RadioButton.ToolTip>
            </RadioButton>
            <RadioButton CommandParameter="{x:Static hshmcvm:ImageEditorTools.TilePalette}"
               Visibility="{Binding CanEditTilePalettes, Converter={StaticResource BoolToVisibility}}"
               IsChecked="{Binding SelectedTool, Mode=OneWay, Converter={StaticResource EqualityCheck}, ConverterParameter={x:Static hshmcvm:ImageEditorTools.TilePalette}}">
               <RadioButton.Content>
                  <Path Data="{hshmwpfr:Icon Tiles}"/>
               </RadioButton.Content>
               <RadioButton.ToolTip>
                  <ToolTip>
                     <TextBlock>
                        C(h)ange Tile Palette<LineBreak/>
                        <Italic Foreground="{DynamicResource Secondary}">
                           Change which palette applies to each tile. <LineBreak/>
                           Right-click to select a specific palette. <LineBreak/>
                           Left-click to apply that palette to a tile.
                        </Italic>
                     </TextBlock>
                  </ToolTip>
               </RadioButton.ToolTip>
            </RadioButton>
         </StackPanel>

         <StackPanel Height="30" HorizontalAlignment="Center" DockPanel.Dock="Top">
            <StackPanel Orientation="Horizontal">
               <StackPanel.Style>
                  <Style TargetType="StackPanel">
                     <Setter Property="Visibility" Value="Collapsed"/>
                     <Style.Triggers>
                        <DataTrigger Binding="{Binding SelectedTool}" Value="Draw">
                           <Setter Property="Visibility" Value="Visible"/>
                        </DataTrigger>
                        <DataTrigger Binding="{Binding SelectedTool}" Value="EyeDropper">
                           <Setter Property="Visibility" Value="Visible"/>
                        </DataTrigger>
                     </Style.Triggers>
                  </Style>
               </StackPanel.Style>
               <StackPanel.Resources>
                  <Style TargetType="RadioButton" BasedOn="{StaticResource {x:Type ToggleButton}}">
                     <Setter Property="Command" Value="{Binding SetCursorSize}"/>
                     <Setter Property="Width" Value="30"/>
                     <Setter Property="Height" Value="30"/>
                     <Setter Property="HorizontalContentAlignment" Value="Center"/>
                     <Setter Property="VerticalContentAlignment" Value="Center"/>
                  </Style>
               </StackPanel.Resources>
               <RadioButton CommandParameter="1" Content="1"
                  IsChecked="{Binding CursorSize, Mode=OneWay, Converter={StaticResource EqualityCheck}, ConverterParameter=1}">
                  <RadioButton.ToolTip>
                     <ToolTip>
                        <TextBlock>
                           1 pixel cursor
                           <Italic Foreground="{DynamicResource Secondary}">
                              (Shift+1)
                           </Italic>
                        </TextBlock>
                     </ToolTip>
                  </RadioButton.ToolTip>
               </RadioButton>
               <RadioButton CommandParameter="2" Content="2"
                  IsChecked="{Binding CursorSize, Mode=OneWay, Converter={StaticResource EqualityCheck}, ConverterParameter=2}">
                  <RadioButton.ToolTip>
                     <ToolTip>
                        <TextBlock>
                           2 pixel cursor
                           <Italic Foreground="{DynamicResource Secondary}">
                              (Shift+2)
                           </Italic>
                        </TextBlock>
                     </ToolTip>
                  </RadioButton.ToolTip>
               </RadioButton>
               <RadioButton CommandParameter="4" Content="4"
                  IsChecked="{Binding CursorSize, Mode=OneWay, Converter={StaticResource EqualityCheck}, ConverterParameter=4}">
                  <RadioButton.ToolTip>
                     <ToolTip>
                        <TextBlock>
                           4 pixel cursor
                           <Italic Foreground="{DynamicResource Secondary}">
                              (Shift+3)
                           </Italic>
                        </TextBlock>
                     </ToolTip>
                  </RadioButton.ToolTip>
               </RadioButton>
               <RadioButton CommandParameter="8" Content="8" Margin="0,0,30,0"
                  IsChecked="{Binding CursorSize, Mode=OneWay, Converter={StaticResource EqualityCheck}, ConverterParameter=8}">
                  <RadioButton.ToolTip>
                     <ToolTip>
                        <TextBlock>
                           8 pixel cursor
                           <Italic Foreground="{DynamicResource Secondary}">
                              (Shift+4)
                           </Italic>
                        </TextBlock>
                     </ToolTip>
                  </RadioButton.ToolTip>
               </RadioButton>
            </StackPanel>

            <StackPanel Orientation="Horizontal"
                  Visibility="{Binding Tag, RelativeSource={RelativeSource Self}, Converter={StaticResource BoolToVisibility}}"
                  Tag="{Binding SelectedTool, Mode=OneWay, Converter={StaticResource EqualityCheck}, ConverterParameter={x:Static hshmcvm:ImageEditorTools.TilePalette}}">
               <StackPanel.Resources>
                  <Style TargetType="RadioButton" BasedOn="{StaticResource {x:Type ToggleButton}}">
                     <Setter Property="Command" Value="{Binding SelectTilePaletteMode}"/>
                     <Setter Property="Width" Value="30"/>
                     <Setter Property="Height" Value="30"/>
                     <Setter Property="HorizontalContentAlignment" Value="Center"/>
                     <Setter Property="VerticalContentAlignment" Value="Center"/>
                  </Style>
               </StackPanel.Resources>
               <RadioButton CommandParameter="{x:Static hshmcvm:TilePaletteMode.Draw}" IsChecked="{Binding TilePaletteMode, Mode=OneWay, Converter={StaticResource EqualityCheck}, ConverterParameter={x:Static hshmcvm:TilePaletteMode.Draw}}">
                  <Path Data="{hshmwpfr:Icon Pencil}"/>
               </RadioButton>
               <RadioButton CommandParameter="{x:Static hshmcvm:TilePaletteMode.Fill}" IsChecked="{Binding TilePaletteMode, Mode=OneWay, Converter={StaticResource EqualityCheck}, ConverterParameter={x:Static hshmcvm:TilePaletteMode.Fill}}">
                  <Path Data="{hshmwpfr:Icon FillBucket}"/>
               </RadioButton>
               <RadioButton CommandParameter="{x:Static hshmcvm:TilePaletteMode.EyeDropper}" IsChecked="{Binding TilePaletteMode, Mode=OneWay, Converter={StaticResource EqualityCheck}, ConverterParameter={x:Static hshmcvm:TilePaletteMode.EyeDropper}}">
                  <Path Data="{hshmwpfr:Icon EyeDropper}"/>
               </RadioButton>
            </StackPanel>
            
            <StackPanel Orientation="Horizontal"
                  Visibility="{Binding Tag, RelativeSource={RelativeSource Self}, Converter={StaticResource BoolToVisibility}}"
                  Tag="{Binding SelectedTool, Mode=OneWay, Converter={StaticResource EqualityCheck}, ConverterParameter={x:Static hshmcvm:ImageEditorTools.Select}}">
               <StackPanel.Resources>
                  <Style TargetType="Button" BasedOn="{StaticResource {x:Type Button}}">
                     <Setter Property="Width" Value="30"/>
                     <Setter Property="Height" Value="30"/>
                     <Setter Property="HorizontalContentAlignment" Value="Center"/>
                     <Setter Property="VerticalContentAlignment" Value="Center"/>
                     <Setter Property="Padding" Value="0"/>
                  </Style>
               </StackPanel.Resources>
               <Decorator>
                  <Button Command="{Binding FlipVertical}">
                     <Path Data="{hshmwpfr:Icon ArrowsUpDown}"/>
                  </Button>
                  <Decorator.ToolTip>
                     <ToolTip Content="Flip the currently selected pixels top-to-bottom."/>
                  </Decorator.ToolTip>
               </Decorator>
               <Decorator>
                  <Button Command="{Binding FlipHorizontal}">
                     <Path Data="{hshmwpfr:Icon ArrowsLeftRight}"/>
                  </Button>
                  <Decorator.ToolTip>
                     <ToolTip Content="Flip the currently selected pixels left-to-right."/>
                  </Decorator.ToolTip>
               </Decorator>
            </StackPanel>
         </StackPanel>

         <local:PixelImage DataContext="{Binding BlockPreview}"
            Visibility="{Binding Enabled, Converter={StaticResource BoolToVisibility}, ConverterParameter={x:Static Visibility.Hidden}}"
            DockPanel.Dock="Top"/>

         <ItemsControl ItemsSource="{Binding SpritePageOptions}"
                       Visibility="{Binding HasMultipleSpritePages, Converter={StaticResource BoolToVisibility}}"
                       HorizontalAlignment="Center"
                       DockPanel.Dock="Top">
            <ItemsControl.ItemsPanel>
               <ItemsPanelTemplate>
                  <StackPanel Orientation="Horizontal"/>
               </ItemsPanelTemplate>
            </ItemsControl.ItemsPanel>
            <ItemsControl.ItemTemplate>
               <DataTemplate>
                  <RadioButton IsChecked="{Binding Selected}">
                     <RadioButton.ToolTip>
                        <ToolTip>
                           <DockPanel>
                              <StackPanel Margin="5,0,0,0" Orientation="Horizontal" DockPanel.Dock="Right" VerticalAlignment="Top">
                                 <TextBlock Text="Shift + " VerticalAlignment="Center"/>
                                 <Path Stretch="Uniform" Data="{hshmwpfr:Icon MiddleMouseButton}" Fill="{DynamicResource Secondary}"/>
                              </StackPanel>
                              <TextBlock>
                                 <Run Text="Sprite Page "/>
                                 <Run Text="{Binding Name}"/>
                                 <LineBreak/>
                                 <Run Foreground="{DynamicResource Secondary}" FontStyle="Italic" Text="(Shift+Scroll to change pages)"/>
                              </TextBlock>
                           </DockPanel>
                        </ToolTip>
                     </RadioButton.ToolTip>
                  </RadioButton>
               </DataTemplate>
            </ItemsControl.ItemTemplate>
         </ItemsControl>

         <ItemsControl ItemsSource="{Binding PalettePageOptions}"
                       Visibility="{Binding HasMultiplePalettePages, Converter={StaticResource BoolToVisibility}}"
                       HorizontalAlignment="Center"
                       DockPanel.Dock="Top">
            <ItemsControl.ItemsPanel>
               <ItemsPanelTemplate>
                  <StackPanel Orientation="Horizontal"/>
               </ItemsPanelTemplate>
            </ItemsControl.ItemsPanel>
            <ItemsControl.ItemTemplate>
               <DataTemplate>
                  <RadioButton IsChecked="{Binding Selected}">
                     <RadioButton.ToolTip>
                        <TextBlock>
                           <Run Text="Palette Page "/>
                           <Run Text="{Binding Name}"/>
                        </TextBlock>
                     </RadioButton.ToolTip>
                  </RadioButton>
               </DataTemplate>
            </ItemsControl.ItemTemplate>
         </ItemsControl>

         <Expander DockPanel.Dock="Bottom" Header="Color Mixer" ExpandDirection="Down" DataContext="{DynamicResource IsPaletteMixerExpanded}" IsExpanded="{Binding Value}">
            <Expander.ToolTip>
               <ToolTip>
                  <TextBlock>
                     An extra palette separate from the file. <LineBreak/>
                     Copy colors to save colors between images.
                  </TextBlock>
               </ToolTip>
            </Expander.ToolTip>
            <hshmwpfc:PaletteControl x:Name="PaletteMixer" LoseKeyboardFocusCausesLoseMultiSelect="False" DataContext="{DynamicResource PaletteMixer}" DockPanel.Dock="Bottom"/>
         </Expander>

         <hshmwpfc:PaletteControl x:Name="PaletteControl" LoseKeyboardFocusCausesLoseMultiSelect="False" DataContext="{Binding Palette}" VerticalAlignment="Center" />
      </DockPanel>

      <Grid Name="ImageContainer" Background="Transparent" ClipToBounds="True"
         MouseLeftButtonDown="MousePrimaryDown"
         MouseLeftButtonUp="MousePrimaryUp"
         MouseDown="MouseMiddleDown"
         MouseUp="MouseMiddleUp"
         MouseRightButtonDown="MouseSecondaryDown"
         MouseRightButtonUp="MouseSecondaryUp"
         MouseMove="MoveMouse"
         MouseWheel="WheelMouse">
         <!-- Wrapping the PixelImage in a canvas to prevent clipping -->
         <Canvas
            VerticalAlignment="Center"
            HorizontalAlignment="Center"
            Width="{Binding ActualWidth, ElementName=EditImage}"
            Height="{Binding ActualHeight, ElementName=EditImage}">
            <local:PixelImage x:Name="EditImage" LayoutTransform="{x:Null}" RenderTransformOrigin=".5,.5">
               <local:PixelImage.RenderTransform>
                  <TransformGroup>
                     <ScaleTransform ScaleX="{Binding SpriteScale}" ScaleY="{Binding SpriteScale}"/>
                     <TranslateTransform X="{Binding XOffset}" Y="{Binding YOffset}"/>
                  </TransformGroup>
               </local:PixelImage.RenderTransform>
            </local:PixelImage>
         </Canvas>
         <!-- Wrapping the selection render in a canvas to prevent clipping -->
         <Canvas
            IsHitTestVisible="False"
            VerticalAlignment="Center"
            HorizontalAlignment="Center"
            Width="{Binding ActualWidth, ElementName=SelectionRender}"
            Height="{Binding ActualHeight, ElementName=SelectionRender}">
            <Grid
               Tag="{Binding SelectedTool, Converter={StaticResource EqualityCheck}, ConverterParameter={x:Static hshmcvm:ImageEditorTools.TilePalette}}"
               VerticalAlignment="Center"
               HorizontalAlignment="Center"
               Visibility="{Binding Tag, RelativeSource={RelativeSource Self}, Converter={StaticResource BoolToVisibility}}"
               Width="{Binding ActualWidth, ElementName=SelectionRender}"
               Height="{Binding ActualHeight, ElementName=SelectionRender}"
               IsHitTestVisible="False">
               <Grid.RenderTransform>
                  <TranslateTransform X="{Binding XOffset}" Y="{Binding YOffset}"/>
               </Grid.RenderTransform>
               <Border Background="{DynamicResource Background}" Opacity=".5"/>
               <ItemsControl ItemsSource="{Binding TilePalettes}" FontSize="{Binding FontSize}">
                  <ItemsControl.ItemsPanel>
                     <ItemsPanelTemplate>
                        <UniformGrid Columns="{Binding TileWidth}" Rows="{Binding TileHeight}"/>
                     </ItemsPanelTemplate>
                  </ItemsControl.ItemsPanel>
                  <ItemsControl.ItemTemplate>
                     <DataTemplate>
                        <Border Background="{Binding Converter={StaticResource TilePaletteHueConverter}}">
                           <TextBlock Text="{Binding}" HorizontalAlignment="Center" VerticalAlignment="Center"/>
                        </Border>
                     </DataTemplate>
                  </ItemsControl.ItemTemplate>
               </ItemsControl>
            </Grid>
            <local:GridDecorator>
               <local:GridDecorator.RenderTransform>
                  <TranslateTransform X="{Binding XOffset}" Y="{Binding YOffset}"/>
               </local:GridDecorator.RenderTransform>
               <local:SelectionRender x:Name="SelectionRender" Stretch="None" />
            </local:GridDecorator>
         </Canvas>
      </Grid>
   </DockPanel>
</UserControl>
