<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:dd="clr-namespace:AIStudio.Wpf.DiagramDesigner"
                    xmlns:c="clr-namespace:AIStudio.Wpf.DiagramDesigner.Controls">
    <dd:ColorBrushConverter x:Key="ColorBrushConverter" />
    <dd:ConectorOrientationConverter  x:Key="ConectorOrientationConverter" />
    <dd:ConectorValueConverter x:Key="ConectorValueConverter"/>
    
    <DataTemplate DataType="{x:Type dd:FullyCreatedConnectorInfo}">
        <Grid Width="{Binding ConnectorWidth}" Height="{Binding ConnectorHeight}"  Cursor="Cross">
            <Grid.ContextMenu>
                <ContextMenu ItemsSource="{Binding MenuOptions}" >
                    <ContextMenu.ItemContainerStyle>
                        <Style TargetType="MenuItem">
                            <Setter Property="MenuItem.Header" Value="{Binding Text}" />
                            <Setter Property="MenuItem.ItemsSource" Value="{Binding Children}" />
                            <Setter Property="MenuItem.Command" Value="{Binding Command}" />
                            <Setter Property="MenuItem.Icon" Value="{Binding Icon}" />
                            <Setter Property="CommandParameter" Value="{Binding CommandParameter}" />
                            <Setter Property="MenuItem.IsCheckable" Value="{Binding IsCheckable}" />
                            <Setter Property="MenuItem.IsChecked" Value="{Binding IsChecked}" />
                        </Style>
                    </ContextMenu.ItemContainerStyle>
                </ContextMenu>
            </Grid.ContextMenu>
            <!-- transparent extra space makes connector easier to hit -->
            <Ellipse x:Name="outer" Fill="Transparent" Opacity="0.3" Margin="-3" />
            <Ellipse x:Name="innter" Fill="{Binding ColorViewModel.FillColor,Converter={StaticResource ColorBrushConverter}}" StrokeThickness="1" Stroke="{Binding ColorViewModel.LineColor,Converter={StaticResource ColorBrushConverter}}" />
        </Grid>
        <DataTemplate.Triggers>
            <Trigger Property="IsMouseOver" Value="True">
                <Setter TargetName="outer" Property="Margin" Value="-6" />
                <Setter TargetName="outer" Property="Fill" Value="#f73438" />
                <Setter TargetName="innter" Property="Fill" Value="#f73438" />
                <Setter TargetName="innter" Property="Stroke" Value="#f73438" />
            </Trigger>
            <DataTrigger Binding="{Binding BeAttachTo}" Value="True">
                <Setter TargetName="outer" Property="Margin" Value="-6" />
                <Setter TargetName="outer" Property="Fill" Value="#f73438" />
                <Setter TargetName="innter" Property="Fill" Value="#f73438" />
                <Setter TargetName="innter" Property="Stroke" Value="#f73438" />
            </DataTrigger>
            <DataTrigger Binding="{Binding DisableAttachTo}" Value="True">
                <Setter TargetName="outer" Property="Margin" Value="-6" />
                <Setter TargetName="outer" Property="Fill" Value="Gray" />
                <Setter TargetName="innter" Property="Fill" Value="Gray" />
                <Setter TargetName="innter" Property="Stroke" Value="Gray" />
            </DataTrigger>
        </DataTemplate.Triggers>
    </DataTemplate>

    <DataTemplate DataType="{x:Type dd:LogicalConnectorInfo}">
        <Grid >
            <Grid ToolTip="{Binding Name}" Width="{Binding ConnectorWidth}" Height="{Binding ConnectorHeight}"  HorizontalAlignment="Left" VerticalAlignment="Top"  Cursor="Cross">
                <Grid.ContextMenu>
                    <ContextMenu ItemsSource="{Binding MenuOptions}">
                        <ContextMenu.ItemContainerStyle>
                            <Style TargetType="MenuItem">
                                <Setter Property="MenuItem.Header" Value="{Binding Text}" />
                                <Setter Property="MenuItem.ItemsSource" Value="{Binding Children}" />
                                <Setter Property="MenuItem.Command" Value="{Binding Command}" />
                                <Setter Property="MenuItem.Icon" Value="{Binding Icon}" />
                                <Setter Property="CommandParameter" Value="{Binding CommandParameter}" />
                                <Setter Property="MenuItem.IsCheckable" Value="{Binding IsCheckable}" />
                                <Setter Property="MenuItem.IsChecked" Value="{Binding IsChecked}" />
                            </Style>
                        </ContextMenu.ItemContainerStyle>
                    </ContextMenu>
                </Grid.ContextMenu>
                <!-- transparent extra space makes connector easier to hit -->
                <Ellipse x:Name="outer" Fill="Transparent" Opacity="0.3" Margin="-3" />
                <Ellipse x:Name="innter" Fill="{Binding ColorViewModel.FillColor,Converter={StaticResource ColorBrushConverter}}" StrokeThickness="1" Stroke="{Binding ColorViewModel.LineColor,Converter={StaticResource ColorBrushConverter}}" />
            </Grid>          

            <Control x:Name="label">
                <Control.Template>
                    <ControlTemplate>
                        <TextBlock x:Name="txtleft" FontSize="10" RenderTransformOrigin="0.5,0.5" TextTrimming="CharacterEllipsis">
                            <TextBlock.Text>
                                <MultiBinding Converter="{StaticResource ConectorValueConverter}">
                                    <Binding Path="." />
                                    <Binding Path="ConnectorChanged" />
                                </MultiBinding>
                            </TextBlock.Text>
                            <TextBlock.ToolTip>
                                <MultiBinding Converter="{StaticResource ConectorValueConverter}" ConverterParameter="ToolTip">
                                    <Binding Path="." />
                                    <Binding Path="ConnectorChanged" />
                                </MultiBinding>
                            </TextBlock.ToolTip>
                            <TextBlock.RenderTransform>
                                <TransformGroup>
                                    <ScaleTransform/>
                                    <SkewTransform/>
                                    <RotateTransform/>
                                    <TranslateTransform Y="10" X="{Binding ElementName=txtleft,Path=Text,Converter={StaticResource ConectorOrientationConverter}}"/>
                                </TransformGroup>
                            </TextBlock.RenderTransform>
                        </TextBlock>
                    </ControlTemplate>
                </Control.Template>
            </Control>

        </Grid>
        <DataTemplate.Triggers>
            <Trigger Property="IsMouseOver" Value="True">
                <Setter TargetName="outer" Property="Margin" Value="-6" />
                <Setter TargetName="outer" Property="Fill" Value="#f73438" />
                <Setter TargetName="innter" Property="Fill" Value="#f73438" />
                <Setter TargetName="innter" Property="Stroke" Value="#f73438" />
            </Trigger>
            <DataTrigger Value="Right" Binding="{Binding Orientation}">
                <Setter TargetName="label" Property="Template">
                    <Setter.Value>
                        <ControlTemplate>
                            <TextBlock x:Name="txtRight" FontSize="10" RenderTransformOrigin="0.5,0.5" TextTrimming="CharacterEllipsis">
                                <TextBlock.Text>
                                    <MultiBinding Converter="{StaticResource ConectorValueConverter}">                                      
                                        <Binding Path="." />
                                        <Binding Path="ConnectorChanged" />
                                    </MultiBinding>
                                </TextBlock.Text>
                                <TextBlock.ToolTip>
                                    <MultiBinding Converter="{StaticResource ConectorValueConverter}" ConverterParameter="ToolTip">
                                        <Binding Path="." />
                                        <Binding Path="ConnectorChanged" />
                                    </MultiBinding>
                                </TextBlock.ToolTip>
                                <TextBlock.RenderTransform>
                                    <TransformGroup>
                                        <ScaleTransform/>
                                        <SkewTransform/>
                                        <RotateTransform/>
                                        <TranslateTransform Y="10" X="5"/>
                                    </TransformGroup>
                                </TextBlock.RenderTransform>
                            </TextBlock>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </DataTrigger>
        </DataTemplate.Triggers>
    </DataTemplate>

    <!-- DragThumb Default Template -->
    <Style TargetType="{x:Type c:DragThumb}">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type c:DragThumb}">
                    <Rectangle Fill="Transparent" />
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>


</ResourceDictionary>