<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
                    xmlns:dd="clr-namespace:AIStudio.Wpf.DiagramDesigner"
                    xmlns:c="clr-namespace:AIStudio.Wpf.DiagramDesigner.Controls"
                    xmlns:sys="clr-namespace:System;assembly=mscorlib"
                    xmlns:gif="http://wpfanimatedgif.codeplex.com" >

    <BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter"/>
    <dd:ColorBrushConverter x:Key="ColorBrushConverter" />
    <dd:ClipConverter x:Key="ClipConverter"/>
    <dd:NegativeConverter x:Key="NegativeConverter"/>

    <DataTemplate DataType="{x:Type dd:DefaultDesignerItemViewModel}">
        <Grid IsHitTestVisible="False">
            <Rectangle StrokeThickness="1" Fill="{Binding ColorViewModel.FillColor,Converter={StaticResource ColorBrushConverter}}" Stroke="{Binding ColorViewModel.LineColor,Converter={StaticResource ColorBrushConverter}}" />
        </Grid>
    </DataTemplate>

    <DataTemplate DataType="{x:Type dd:TextDesignerItemViewModel}">
        <Grid >
            <Border Background="{Binding ColorViewModel.FillColor,Converter={StaticResource ColorBrushConverter}}" IsHitTestVisible="False"/>
            <Grid  Margin="5">
                <dd:TextControl dd:ControlAttachProperty.Watermark="{Binding Watermark}" />
            </Grid>
        </Grid>
    </DataTemplate>

    <DataTemplate DataType="{x:Type dd:DrawingDesignerItemViewModelBase}">
        <Grid IsHitTestVisible="False">
            <Control x:Name="control" />
        </Grid>
        <DataTemplate.Triggers>
            <DataTrigger Binding="{Binding Erasable}" Value="True">
                <Setter TargetName="control" Property="Template">
                    <Setter.Value>
                        <ControlTemplate>
                            <Path Fill="{Binding ColorViewModel.LineColor,Converter={StaticResource ColorBrushConverter}}"
                              Data="{Binding Geometry}">
                            </Path>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </DataTrigger>
            <DataTrigger Binding="{Binding Erasable}" Value="False">
                <Setter TargetName="control" Property="Template">
                    <Setter.Value>
                        <ControlTemplate>
                            <Path StrokeThickness="{Binding ColorViewModel.LineWidth}"  
                                  StrokeDashArray="{Binding ColorViewModel.LineDashStyle,Converter={StaticResource LineDashConverter}}"
                                  Stroke="{Binding ColorViewModel.LineColor,Converter={StaticResource ColorBrushConverter}}"
                                  Fill="{Binding ColorViewModel.LineColor,Converter={StaticResource ColorBrushConverter}}"
                                  Data="{Binding Geometry}">
                            </Path>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </DataTrigger>
        </DataTemplate.Triggers>
    </DataTemplate>

    <DataTemplate DataType="{x:Type dd:GroupDesignerItemViewModel}">
        <Grid IsHitTestVisible="False">

        </Grid>
    </DataTemplate>

    <DataTemplate DataType="{x:Type dd:GifImageItemViewModel}">
        <Grid IsHitTestVisible="False">
            <Image Name="PART_Image_run" gif:ImageBehavior.AnimatedSource="{Binding Icon}" gif:ImageBehavior.AutoStart="True" VerticalAlignment="Center" HorizontalAlignment="Center"  Visibility="Visible"/>
            <Control x:Name="control" />
        </Grid>
        <DataTemplate.Triggers>
            <DataTrigger Binding="{Binding IsRunning}" Value="false">
                <Setter TargetName="PART_Image_run" Property="gif:ImageBehavior.AutoStart" Value="False" />
            </DataTrigger>
        </DataTemplate.Triggers>
    </DataTemplate>

    <DataTemplate DataType="{x:Type dd:VideoItemViewModel}">
        <Grid IsHitTestVisible="False">
            <MediaElement x:Name="MediaPlayer" LoadedBehavior="Play" Source="{Binding Icon}" VerticalAlignment="Center" HorizontalAlignment="Center"  Visibility="Visible"/>
        </Grid>
    </DataTemplate>

    <DataTemplate DataType="{x:Type dd:ImageItemViewModel}">
        <Grid ToolTip="{Binding Icon}">
            <Grid IsHitTestVisible="False" ClipToBounds="True">
                <Image x:Name="image" Source="{Binding Icon}" Stretch="Fill" 
                           Margin="{Binding Object,Converter={StaticResource ClipConverter},ConverterParameter='Margin'}" 
                           Clip="{Binding Object,Converter={StaticResource ClipConverter},ConverterParameter='Clip'}">
                </Image>
                <Image x:Name="gif" gif:ImageBehavior.AnimatedSource="{Binding Icon}" gif:ImageBehavior.AutoStart="True" Visibility="Collapsed" Stretch="Fill"/>
            </Grid>
            <!-- PART_ResizeDecorator -->
            <Border x:Name="PART_ResizeDecorator" SnapsToDevicePixels="true" Margin="{Binding ResizeMargin,Mode=TwoWay}" Visibility="Collapsed">
                <Grid x:Name="Grid" Margin="-2">
                    <c:BorderResizeThumb Height="5" Cursor="SizeAll" Margin="-3" ResizeMode="DragMargin" BorderBrush="Blue" BorderThickness="5" ResizeElement="{Binding ElementName=PART_ResizeDecorator}"
                     VerticalAlignment="Top" HorizontalAlignment="Stretch"/>
                    <c:BorderResizeThumb Width="5" Cursor="SizeAll" Margin="-3" ResizeMode="DragMargin" BorderBrush="Blue" BorderThickness="5" ResizeElement="{Binding ElementName=PART_ResizeDecorator}"
                     VerticalAlignment="Stretch" HorizontalAlignment="Left"/>
                    <c:BorderResizeThumb Width="5" Cursor="SizeAll" Margin="-3" ResizeMode="DragMargin" BorderBrush="Blue" BorderThickness="5" ResizeElement="{Binding ElementName=PART_ResizeDecorator}"
                     VerticalAlignment="Stretch" HorizontalAlignment="Right"/>
                    <c:BorderResizeThumb Height="5" Cursor="SizeAll" Margin="-3" ResizeMode="DragMargin" BorderBrush="Blue" BorderThickness="5" ResizeElement="{Binding ElementName=PART_ResizeDecorator}"
                     VerticalAlignment="Bottom" HorizontalAlignment="Stretch"/>
                    <c:BorderResizeThumb Width="5" Height="5" Cursor="SizeNS" ResizeMode="Margin" Margin="-3" ResizeElement="{Binding ElementName=PART_ResizeDecorator}"
                     VerticalAlignment="Top" HorizontalAlignment="Center"/>
                    <c:BorderResizeThumb Width="5" Height="5" Cursor="SizeWE" ResizeMode="Margin" Margin="-3" ResizeElement="{Binding ElementName=PART_ResizeDecorator}"
                     VerticalAlignment="Center" HorizontalAlignment="Left"/>
                    <c:BorderResizeThumb Width="5" Height="5" Cursor="SizeWE" ResizeMode="Margin" Margin="-3" ResizeElement="{Binding ElementName=PART_ResizeDecorator}"
                     VerticalAlignment="Center" HorizontalAlignment="Right"/>
                    <c:BorderResizeThumb Width="5" Height="5" Cursor="SizeNS" ResizeMode="Margin" Margin="-3" ResizeElement="{Binding ElementName=PART_ResizeDecorator}"
                     VerticalAlignment="Bottom" HorizontalAlignment="Center"/>
                    <c:BorderResizeThumb Width="5" Height="5" Cursor="SizeNWSE" ResizeMode="Margin" Margin="-3" ResizeElement="{Binding ElementName=PART_ResizeDecorator}"
                     VerticalAlignment="Top" HorizontalAlignment="Left"/>
                    <c:BorderResizeThumb Width="5" Height="5" Cursor="SizeNESW" ResizeMode="Margin" Margin="-3" ResizeElement="{Binding ElementName=PART_ResizeDecorator}"
                     VerticalAlignment="Top" HorizontalAlignment="Right"/>
                    <c:BorderResizeThumb Width="5" Height="5" Cursor="SizeNESW" ResizeMode="Margin" Margin="-3" ResizeElement="{Binding ElementName=PART_ResizeDecorator}"
                     VerticalAlignment="Bottom" HorizontalAlignment="Left"/>
                    <c:BorderResizeThumb Width="5" Height="5" Cursor="SizeNWSE" ResizeMode="Margin" Margin="-3" ResizeElement="{Binding ElementName=PART_ResizeDecorator}"
                     VerticalAlignment="Bottom" HorizontalAlignment="Right"/>
                </Grid>
            </Border>
        </Grid>
        <DataTemplate.Triggers>
            <DataTrigger Binding="{Binding Suffix}" Value=".gif">
                <Setter TargetName="gif" Property="Visibility" Value="Visible"/>
                <Setter TargetName="image" Property="Visibility" Value="Collapsed"/>
            </DataTrigger>
            <DataTrigger Binding="{Binding ResizeMode}" Value="True">
                <Setter TargetName="PART_ResizeDecorator" Property="Visibility" Value="Visible"/>
            </DataTrigger>
            <DataTrigger Binding="{Binding Suffix}" Value=".txt">
                <Setter TargetName="image" Property="Source" Value="pack://application:,,,/AIStudio.Wpf.DiagramDesigner;component/Images/file.png"/>
                <Setter TargetName="image" Property="Margin" Value="0"/>
                <Setter TargetName="image" Property="Clip" Value="{x:Null}"/>
            </DataTrigger>
        </DataTemplate.Triggers>
    </DataTemplate>
</ResourceDictionary>