<UserControl x:Class="HaRepacker.GUI.Panels.MainPanel"
             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:sys="clr-namespace:System;assembly=mscorlib"
             
             xmlns:wf="clr-namespace:System.Windows.Forms;assembly=System.Windows.Forms"  
             
             xmlns:local="clr-namespace:HaRepacker"
             xmlns:converter="clr-namespace:HaRepacker.Converter"
             xmlns:sharedLib="clr-namespace:HaSharedLibrary.GUI;assembly=HaSharedLibrary"
             xmlns:sharedLibConverter="clr-namespace:HaSharedLibrary.Converter;assembly=HaSharedLibrary"
             xmlns:guiControls="clr-namespace:HaRepacker.GUI.Controls"
             xmlns:localgui ="clr-namespace:HaRepacker.GUI"
             xmlns:localSubPanels ="clr-namespace:HaRepacker.GUI.Panels.SubPanels"
             
             xmlns:xctk="http://schemas.xceed.com/wpf/xaml/toolkit"

             mc:Ignorable="d" 
             d:DesignHeight="661" d:DesignWidth="1599">

    <UserControl.Resources>
        <Storyboard x:Key="Storyboard_Find_FadeIn">
            <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="grid_FindPanel">
                <DiscreteObjectKeyFrame KeyTime="0" Value="{x:Static Visibility.Visible}"/>
            </ObjectAnimationUsingKeyFrames>
            <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="grid_FindPanel">
                <EasingDoubleKeyFrame KeyTime="0" Value="80"/>
                <EasingDoubleKeyFrame KeyTime="0:0:0.3" Value="1"/>
            </DoubleAnimationUsingKeyFrames>
            <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.Y)" Storyboard.TargetName="grid_FindPanel">
                <EasingDoubleKeyFrame KeyTime="0" Value="80"/>
                <EasingDoubleKeyFrame KeyTime="0:0:0.3" Value="0"/>
            </DoubleAnimationUsingKeyFrames>
        </Storyboard>
        <Storyboard x:Key="Storyboard_Find_FadeOut">
            <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="grid_FindPanel">
                <EasingDoubleKeyFrame KeyTime="0" Value="100"/>
                <EasingDoubleKeyFrame KeyTime="0:0:0.3" Value="50"/>
            </DoubleAnimationUsingKeyFrames>
            <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.Y)" Storyboard.TargetName="grid_FindPanel">
                <EasingDoubleKeyFrame KeyTime="0" Value="0"/>
                <EasingDoubleKeyFrame KeyTime="0:0:0.3" Value="80"/>
            </DoubleAnimationUsingKeyFrames>
            <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="grid_FindPanel">
                <DiscreteObjectKeyFrame KeyTime="0" Value="{x:Static Visibility.Visible}"/>
                <DiscreteObjectKeyFrame KeyTime="0:0:0.3" Value="{x:Static Visibility.Collapsed}"/>
            </ObjectAnimationUsingKeyFrames>
        </Storyboard>
        <Style x:Key="FocusVisual">
            <Setter Property="Control.Template">
                <Setter.Value>
                    <ControlTemplate>
                        <Rectangle Margin="2" SnapsToDevicePixels="true" Stroke="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}" StrokeThickness="1" StrokeDashArray="1 2"/>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
        <SolidColorBrush x:Key="Button.Static.Background" Color="#FFDDDDDD"/>
        <SolidColorBrush x:Key="Button.Static.Border" Color="#FF707070"/>
        <SolidColorBrush x:Key="Button.MouseOver.Background" Color="#FFBEE6FD"/>
        <SolidColorBrush x:Key="Button.MouseOver.Border" Color="#FF3C7FB1"/>
        <SolidColorBrush x:Key="Button.Pressed.Background" Color="#FFC4E5F6"/>
        <SolidColorBrush x:Key="Button.Pressed.Border" Color="#FF2C628B"/>
        <SolidColorBrush x:Key="Button.Disabled.Background" Color="#FFF4F4F4"/>
        <SolidColorBrush x:Key="Button.Disabled.Border" Color="#FFADB2B5"/>
        <SolidColorBrush x:Key="Button.Disabled.Foreground" Color="#FF838383"/>

        <sharedLibConverter:BooleanToVisibilityConverter x:Key="booleanToVisibilityConverter"/>

        <Style x:Key="ButtonStyle_MoreOption" TargetType="{x:Type Button}">
            <Setter Property="FocusVisualStyle" Value="{StaticResource FocusVisual}"/>
            <Setter Property="Background" Value="{StaticResource Button.Static.Background}"/>
            <Setter Property="BorderBrush" Value="{StaticResource Button.Static.Border}"/>
            <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/>
            <Setter Property="BorderThickness" Value="0"/>
            <Setter Property="HorizontalContentAlignment" Value="Center"/>
            <Setter Property="VerticalContentAlignment" Value="Center"/>
            <Setter Property="Padding" Value="0,0,0,0"/>
            <Setter Property="FontWeight" Value="Bold"/>
            <Setter Property="FontSize" Value="30"/>
            
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type Button}">
                        <ContentPresenter x:Name="contentPresenter" Focusable="True" Margin="0" 
                                          HorizontalAlignment="Center"  VerticalAlignment="Center"
                                          RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" RenderTransformOrigin="0.5,0.5" >
                            <ContentPresenter.RenderTransform>
                                <TransformGroup>
                                    <ScaleTransform/>
                                    <SkewTransform/>
                                    <RotateTransform/>
                                    <TranslateTransform/>
                                </TransformGroup>
                            </ContentPresenter.RenderTransform>
                            <VisualStateManager.VisualStateGroups>
                                <VisualStateGroup x:Name="CommonStates">
                                    <VisualState x:Name="Normal"/>
                                    <VisualState x:Name="MouseOver">
                                        <Storyboard>
                                            <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleX)" Storyboard.TargetName="contentPresenter">
                                                <EasingDoubleKeyFrame KeyTime="0" Value="1.1"/>
                                            </DoubleAnimationUsingKeyFrames>
                                            <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleY)" Storyboard.TargetName="contentPresenter">
                                                <EasingDoubleKeyFrame KeyTime="0" Value="1.1"/>
                                            </DoubleAnimationUsingKeyFrames>
                                        </Storyboard>
                                    </VisualState>
                                    <VisualState x:Name="Pressed">
                                        <Storyboard>
                                            <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleX)" Storyboard.TargetName="contentPresenter">
                                                <EasingDoubleKeyFrame KeyTime="0" Value="1.2"/>
                                            </DoubleAnimationUsingKeyFrames>
                                            <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleY)" Storyboard.TargetName="contentPresenter">
                                                <EasingDoubleKeyFrame KeyTime="0" Value="1.2"/>
                                            </DoubleAnimationUsingKeyFrames>
                                        </Storyboard>
                                    </VisualState>
                                    <VisualState x:Name="Disabled"/>
                                </VisualStateGroup>
                            </VisualStateManager.VisualStateGroups>
                        </ContentPresenter>
                        
                        <ControlTemplate.Triggers>
                            <Trigger Property="IsEnabled" Value="false">
                                <Setter Property="TextElement.Foreground" TargetName="contentPresenter" Value="{StaticResource Button.Disabled.Foreground}"/>
                            </Trigger>

                            <Trigger Property="IsMouseOver" Value="true">

                            </Trigger>
                            <Trigger Property="IsPressed" Value="true">
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>

 
        <Style TargetType="{x:Type guiControls:PointFEditorControl}">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type guiControls:PointFEditorControl}">
                        <StackPanel Orientation="Horizontal" Visibility="{Binding DataContext.IsXYPanelReadOnly, RelativeSource={RelativeSource AncestorType=xctk:PropertyGrid},Converter={StaticResource booleanToVisibilityConverter}}">
                            <TextBlock Text="X:" Margin="0,0,2,0"/>
                            <TextBox Text="{Binding PointF.X, RelativeSource={RelativeSource TemplatedParent}, Mode=TwoWay}" 
                                Width="40"/>
                            <TextBlock Text="Y:" Margin="5,0,2,0"/>
                            <TextBox Text="{Binding PointF.Y, RelativeSource={RelativeSource TemplatedParent}, Mode=TwoWay}" 
                                Width="40"/>
                        </StackPanel>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
            <Style.Triggers>
                <DataTrigger Binding="{Binding DataContext.IsXYPanelReadOnly, RelativeSource={RelativeSource AncestorType=xctk:PropertyGrid}}" Value="True">
                    <Setter Property="IsReadOnly" Value="True"/>
                </DataTrigger>
                <DataTrigger Binding="{Binding DataContext.IsXYPanelReadOnly, RelativeSource={RelativeSource AncestorType=xctk:PropertyGrid}}" Value="False">
                    <Setter Property="IsReadOnly" Value="False"/>
                </DataTrigger>
            </Style.Triggers>

        </Style>
        
        <Storyboard x:Key="Storyboard_TreeviewItemSelectedAnimation">
            <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleX)" Storyboard.TargetName="button_MoreOption">
                <EasingDoubleKeyFrame KeyTime="0:0:0.2" Value="1.5"/>
                <EasingDoubleKeyFrame KeyTime="0:0:0.4" Value="1"/>
            </DoubleAnimationUsingKeyFrames>
            <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleY)" Storyboard.TargetName="button_MoreOption">
                <EasingDoubleKeyFrame KeyTime="0:0:0.2" Value="1.5"/>
                <EasingDoubleKeyFrame KeyTime="0:0:0.4" Value="1"/>
            </DoubleAnimationUsingKeyFrames>
        </Storyboard>
    </UserControl.Resources>
    
    <UserControl.Triggers>
        <EventTrigger RoutedEvent="FrameworkElement.Loaded">
            <BeginStoryboard Storyboard="{StaticResource Storyboard_Find_FadeIn}"/>
            <BeginStoryboard Storyboard="{StaticResource Storyboard_Find_FadeOut}"/>
            <BeginStoryboard Storyboard="{StaticResource Storyboard_TreeviewItemSelectedAnimation}"/>
        </EventTrigger>
    </UserControl.Triggers>

    <DockPanel>
        <VisualStateManager.VisualStateGroups>
            <VisualStateGroup x:Name="VisualStateGroup">
                <VisualState x:Name="Default">
                </VisualState>

                <VisualState x:Name="BlackTheme">
                    <Storyboard>
                        <ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(Panel.Background).(SolidColorBrush.Color)" Storyboard.TargetName="grid_FindPanel">
                            <EasingColorKeyFrame KeyTime="0" Value="Black"/>
                        </ColorAnimationUsingKeyFrames>
                        <ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(Panel.Background).(SolidColorBrush.Color)" Storyboard.TargetName="findBox">
                            <EasingColorKeyFrame KeyTime="0" Value="Black"/>
                        </ColorAnimationUsingKeyFrames>
                        <ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(TextElement.Foreground).(SolidColorBrush.Color)" Storyboard.TargetName="findBox">
                            <EasingColorKeyFrame KeyTime="0" Value="White"/>
                        </ColorAnimationUsingKeyFrames>
                        <ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(Panel.Background).(SolidColorBrush.Color)" Storyboard.TargetName="button_nextSearch">
                            <EasingColorKeyFrame KeyTime="0" Value="Black"/>
                        </ColorAnimationUsingKeyFrames>
                        <ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(Panel.Background).(SolidColorBrush.Color)" Storyboard.TargetName="button_allSearch">
                            <EasingColorKeyFrame KeyTime="0" Value="Black"/>
                        </ColorAnimationUsingKeyFrames>
                        <ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(Panel.Background).(SolidColorBrush.Color)" Storyboard.TargetName="button_closeSearch">
                            <EasingColorKeyFrame KeyTime="0" Value="Black"/>
                        </ColorAnimationUsingKeyFrames>
                        <ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(TextElement.Foreground).(SolidColorBrush.Color)" Storyboard.TargetName="button_closeSearch">
                            <EasingColorKeyFrame KeyTime="0" Value="White"/>
                        </ColorAnimationUsingKeyFrames>
                        <ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(TextElement.Foreground).(SolidColorBrush.Color)" Storyboard.TargetName="button_allSearch">
                            <EasingColorKeyFrame KeyTime="0" Value="White"/>
                        </ColorAnimationUsingKeyFrames>
                        <ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(TextElement.Foreground).(SolidColorBrush.Color)" Storyboard.TargetName="button_nextSearch">
                            <EasingColorKeyFrame KeyTime="0" Value="White"/>
                        </ColorAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(Panel.Background)" Storyboard.TargetName="grid">
                            <DiscreteObjectKeyFrame KeyTime="0">
                                <DiscreteObjectKeyFrame.Value>
                                    <SolidColorBrush Color="Black"/>
                                </DiscreteObjectKeyFrame.Value>
                            </DiscreteObjectKeyFrame>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(Panel.Background)" Storyboard.TargetName="grid1">
                            <DiscreteObjectKeyFrame KeyTime="0">
                                <DiscreteObjectKeyFrame.Value>
                                    <SolidColorBrush Color="Black"/>
                                </DiscreteObjectKeyFrame.Value>
                            </DiscreteObjectKeyFrame>
                        </ObjectAnimationUsingKeyFrames>
                        <ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(TextElement.Foreground).(SolidColorBrush.Color)" Storyboard.TargetName="button_MoreOption">
                            <EasingColorKeyFrame KeyTime="0" Value="White"/>
                        </ColorAnimationUsingKeyFrames>
                        <!--      <ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(Panel.Background).(SolidColorBrush.Color)" Storyboard.TargetName="statusBar">
                            <EasingColorKeyFrame KeyTime="0" Value="Black"/>
                        </ColorAnimationUsingKeyFrames>
                        <ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(TextElement.Foreground).(SolidColorBrush.Color)" Storyboard.TargetName="selectionLabel">
                            <EasingColorKeyFrame KeyTime="0" Value="White"/>
                        </ColorAnimationUsingKeyFrames>
                        <ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(TextElement.Foreground).(SolidColorBrush.Color)" Storyboard.TargetName="toolStripStatusLabel_additionalInfo">
                            <EasingColorKeyFrame KeyTime="0" Value="White"/>
                        </ColorAnimationUsingKeyFrames>
                        <ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(TextElement.Foreground).(SolidColorBrush.Color)" Storyboard.TargetName="statusBarItemLabel_Others">
                            <EasingColorKeyFrame KeyTime="0" Value="White"/>
                        </ColorAnimationUsingKeyFrames>
                        <ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(Panel.Background).(SolidColorBrush.Color)" Storyboard.TargetName="separator">
                            <EasingColorKeyFrame KeyTime="0" Value="White"/>
                        </ColorAnimationUsingKeyFrames>-->
                    </Storyboard>
                </VisualState>
            </VisualStateGroup>
        </VisualStateManager.VisualStateGroups>

        <StatusBar x:Name="statusBar" DockPanel.Dock="Bottom">
            <StatusBar.ItemsPanel>
                <ItemsPanelTemplate>
                    <Grid>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="5" />
                            <ColumnDefinition Width="105" />
                            <ColumnDefinition Width="105" />

                            <ColumnDefinition Width="5" />

                            <ColumnDefinition Width="Auto" />
                            <ColumnDefinition Width="200" />
                            <ColumnDefinition Width="*" />
                        </Grid.ColumnDefinitions>
                    </Grid>
                </ItemsPanelTemplate>
            </StatusBar.ItemsPanel>

            <Separator Grid.Column="0" />

            <StatusBarItem Grid.Column="1">
                <ProgressBar x:Name="mainProgressBar" Height="15" Width="100"/>
            </StatusBarItem>
            <StatusBarItem Grid.Column="2">
                <ProgressBar x:Name="secondaryProgressBar" Height="15" Width="100"/>
            </StatusBarItem>

            <Separator x:Name="separator" Grid.Column="3" />

            <StatusBarItem Grid.Column="4">
                <TextBlock x:Name="toolStripStatusLabel_debugMode" Width="90" Text="DEBUG MODE"/>
            </StatusBarItem>

            <StatusBarItem Grid.Column="5">
                <TextBlock x:Name="toolStripStatusLabel_additionalInfo" Text="-"/>
            </StatusBarItem>

            <StatusBarItem Grid.Column="6" HorizontalAlignment="Right">
                <TextBlock x:Name="statusBarItemLabel_Others" Text="-" Margin="0,0,30,0"/>
            </StatusBarItem>
        </StatusBar>


        <Grid Name="gridMain">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="2*" />
                <ColumnDefinition Width="4" />
                <ColumnDefinition Width="8*"/>
            </Grid.ColumnDefinitions>

            <!-- Main panel-->
            <Grid Grid.Column="0">
                <Grid.RowDefinitions>
                    <RowDefinition Height="*"/>
                    <RowDefinition Height="300"/>
                    <RowDefinition Height="Auto"/>
                </Grid.RowDefinitions>

                <WindowsFormsHost x:Name="treeView_WinFormsHost" Grid.Row="0">
                    <local:TreeViewMS x:Name="DataTree" x:FieldModifier="public" 
                                      AllowDrop="True"
                                      AfterSelect="DataTree_AfterSelect"
                                      BeforeExpand="DataTree_BeforeExpand"
                                      KeyDown="DataTree_KeyDown"
                                      DoubleClick="DataTree_DoubleClick"/>
                </WindowsFormsHost>

                <xctk:PropertyGrid x:Name="propertyGrid" 
                           Grid.Row="1"
                               IsCategorized="True"
                               SelectedObject="{Binding }"
                               ShowTitle="False" Background="#FFDDDDDD" Foreground="Black">
                    <xctk:PropertyGrid.EditorDefinitions>
                        <xctk:EditorTemplateDefinition TargetProperties="WzFileValue">
                            <xctk:EditorTemplateDefinition.EditingTemplate>
                                <DataTemplate>
                                    <!--<TextBox Text="{Binding Value}" IsReadOnly="{Binding Path=Value.IsReadOnly,  RelativeSource={RelativeSource AncestorType=xctk:PropertyItem}}"/> -->
                                    <!--Visibility="{Binding DataContext.IsWzValueReadOnly, RelativeSource={RelativeSource AncestorType=xctk:PropertyGrid}, Converter={StaticResource booleanToVisibilityConverter}}"-->
                                    <TextBox 
                                        Text="{Binding Value}" 
                                        IsReadOnly="{Binding DataContext.IsWzValueReadOnly, RelativeSource={RelativeSource AncestorType=xctk:PropertyGrid}}"
                                        BorderBrush="Transparent"
                                        />
                                </DataTemplate>
                            </xctk:EditorTemplateDefinition.EditingTemplate>
                        </xctk:EditorTemplateDefinition>

                       
                    </xctk:PropertyGrid.EditorDefinitions>
                </xctk:PropertyGrid>

                <!-- Find panel -->
                <Grid x:Name="grid_FindPanel" Grid.Row="2" Grid.RowSpan="2" Opacity="1"
                      Margin="0,0,0,0" Background="White" Height="40" VerticalAlignment="Top"
                      Visibility="Collapsed" RenderTransformOrigin="0.5,0.5">
                    <Grid.RenderTransform>
                        <TransformGroup>
                            <ScaleTransform/>
                            <SkewTransform/>
                            <RotateTransform/>
                            <TranslateTransform/>
                        </TransformGroup>
                    </Grid.RenderTransform>

                    <Grid Margin="0,0,0,5">
                        <TextBox x:Name="findBox" Text="" FontSize="15"  Margin="5,5,120,0" Height="27"
                             KeyDown="findBox_KeyDown"
                             TextChanged="findBox_TextChanged"/>

                        <StackPanel  Margin="0,5,5,0" Orientation="Horizontal" HorizontalAlignment="Right" VerticalAlignment="Center">
                            <Button x:Name="button_nextSearch" Background="White" Foreground="Black"
                                FontFamily="Segoe MDL2 Assets"  Content="&#xE721;"
                                Width="27" Height="27" 
                                Click="button_nextSearch_Click"/>

                            <Button x:Name="button_allSearch" Background="White" Foreground="Black"
                                FontFamily="Segoe MDL2 Assets"  Content="&#xE71D;"
                                Width="27" Height="27" Margin="16,0,7,0"
                                Click="button_allSearch_Click"/>

                            <Button x:Name="button_closeSearch" Background="White" Foreground="Black"
                                FontFamily="Segoe MDL2 Assets"  Content="&#xE711;"
                                Width="27" Height="27"
                                Click="button_closeSearch_Click"/>
                        </StackPanel>
                    </Grid>
                </Grid>
            </Grid>

            <GridSplitter Background="DarkGray"  ResizeDirection="Columns" Grid.Column="1" 
                  HorizontalAlignment="Stretch" VerticalAlignment="Stretch" 
                  ResizeBehavior="PreviousAndNext" />


            <Grid x:Name="grid" Grid.Column="2" Background="#FFF1F1F1">
                <Grid.RowDefinitions>
                    <RowDefinition Height="40"/>
                    <RowDefinition Height="*" />
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="9.5*"/>
                    <ColumnDefinition Width="0.5*"/>
                </Grid.ColumnDefinitions>

                <Grid x:Name="grid1" Grid.Row="0" Grid.RowSpan="2" Grid.ColumnSpan="2">
                    <!-- Map.wz/../fieldLimit-->
                    <WindowsFormsHost x:Name="fieldLimitPanelHost" Visibility="Collapsed" Margin="0,37,0,0">
                        <sharedLib:FieldLimitPanel x:Name="fieldLimitPanel1" />
                    </WindowsFormsHost>

                    <!-- Map.wz/../fieldType -->
                    <sharedLib:FieldTypePanel x:Name="fieldTypePanel" Visibility="Collapsed"/>

                    <sharedLib:SoundPlayer x:Name="mp3Player" Visibility="Collapsed"/>
                    
                    <!-- Lua script editor-->
                    <localSubPanels:AvalonTextEditor x:Name="textEditor" Visibility="Collapsed"/>

                    <!-- Image render -->
                    <Grid x:Name="Grid_ImageRender" Margin="10,0,0,10">
                        <localSubPanels:ImageRenderViewer x:Name="canvasPropBox"
                                                          HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
                                                          Visibility="Collapsed"
                                                         
                                                          AllowDrop="True"
                                                          DragEnter="canvasPropBox_DragEnter" DragLeave="canvasPropBox_DragLeave"
                                                          Drop="canvasPropBox_Drop">

                        </localSubPanels:ImageRenderViewer>
                    </Grid>
                </Grid>

                <!-- Context menu -->
                <Button x:Name="button_MoreOption" Content="..."  
                        Width="40" Height="40" 
                        Style="{DynamicResource ButtonStyle_MoreOption}"
                        Margin="0,0,0,0"
                        Grid.Row="0"  Grid.Column="1"
                        Visibility="Visible"
                                Click="button_MoreOption_Click" RenderTransformOrigin="0.5,0.5">
                    <Button.RenderTransform>
                        <TransformGroup>
                            <ScaleTransform/>
                            <SkewTransform/>
                            <RotateTransform/>
                            <TranslateTransform/>
                        </TransformGroup>
                    </Button.RenderTransform>
                    <Button.ContextMenu>
                        <ContextMenu Name="cm" StaysOpen="true">
                            <MenuItem Header="Change Image" x:Name="menuItem_changeImage" Click="MenuItem_changeImage_Click"/>
                            <MenuItem Header="Change Sound" x:Name="menuItem_changeSound" Click="MenuItem_changeSound_Click"/>
                            <MenuItem Header="Save Sound" x:Name="menuItem_saveSound" Click="MenuItem_saveSound_Click"/>
                            <MenuItem Header="Save Image" x:Name="menuItem_saveImage" Click="menuItem_saveImage_Click"/>
                            <MenuItem Header="Export file" x:Name="menuItem_exportFile" Click="menuItem_ExportFile_Click"/>
                            <!--  <MenuItem Header="Save Sound">
                                        <MenuItem Header="ReadMe.txt"/>
                                        <MenuItem Header="Schedule.xls"/>
                                    </MenuItem>-->
                        </ContextMenu>
                    </Button.ContextMenu>
                </Button>

            </Grid>


            <!-- Loading panel-->
            <Grid x:Name="grid_LoadingPanel" Visibility="Collapsed"
                      Grid.Column="0" Grid.ColumnSpan="3"
                      Background="White">
                <localSubPanels:LoadingPanel x:Name="loadingPanel" Height="350" Background="White"/>
            </Grid>

        </Grid>

    </DockPanel>
</UserControl>
