Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version
Go to top

WPF Diagram Designer - Part 3

, 29 Feb 2008
Connecting items
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:s="clr-namespace:DiagramDesigner"
                    xmlns:c="clr-namespace:DiagramDesigner.Controls">
  <Style TargetType="{x:Type s:Connection}">
    <Style.Resources>
      <!-- Style for the ConnectorAdorner thumbs -->
      <Style x:Key="ConnectionAdornerThumbStyle" TargetType="{x:Type Thumb}">
        <Setter Property="Width" Value="12"/>
        <Setter Property="Height" Value="12"/>
        <Setter Property="SnapsToDevicePixels" Value="true"/>
        <Setter Property="RenderTransform">
          <Setter.Value>
            <TranslateTransform X="-6" Y="-6"/>
          </Setter.Value>
        </Setter>
        <Setter Property="Template">
          <Setter.Value>
            <ControlTemplate TargetType="{x:Type Thumb}">
              <Rectangle Fill="#AADCDCDC" Stroke="DodgerBlue" StrokeThickness="1" RadiusX="0" RadiusY="0"/>
            </ControlTemplate>
          </Setter.Value>
        </Setter>
      </Style>
      <!-- Arrow Grid Style -->
      <Style x:Key="ArrowGridStyle" TargetType="Grid">
        <Setter Property="Width" Value="10"/>
        <Setter Property="Height" Value="10"/>
        <Setter Property="RenderTransform">
          <Setter.Value>
            <TranslateTransform X="-5" Y="-5"/>
          </Setter.Value>
        </Setter>
      </Style>
      <!-- base style for all arrow shapes -->
      <Style x:Key="ArrowSymbolBaseStyle" TargetType="Path">
        <Setter Property="Fill" Value="{StaticResource SolidBorderBrush}"/>
        <Setter Property="Stretch" Value="Fill"/>
      </Style>
      <!-- Arrow -->
      <Style x:Key="Arrow" TargetType="Path" BasedOn="{StaticResource ArrowSymbolBaseStyle}">
        <Setter Property="Data" Value="M0,0 8,4 0,8 Z"/>
      </Style>
      <!-- Diamond  -->
      <Style x:Key="Diamond" TargetType="Path" BasedOn="{StaticResource ArrowSymbolBaseStyle}">
        <Setter Property="Data" Value="M-5,0 0,-5 5,0 0,5 Z"/>
      </Style>
    </Style.Resources>
    <Setter Property="SnapsToDevicePixels" Value="True"/>
    <Setter Property="Template">
      <Setter.Value>
        <ControlTemplate TargetType="{x:Type s:Connection}">
          <Canvas DataContext="{Binding RelativeSource={RelativeSource TemplatedParent}}" >
            <Path Name="PART_ConnectionPath"
                  StrokeThickness="2"
                  Stroke="{StaticResource SolidBorderBrush}"
                  StrokeStartLineCap="Round"
                  StrokeEndLineCap="Round"
                  StrokeLineJoin="Round"
                  StrokeDashArray="{Binding StrokeDashArray}"
                  SnapsToDevicePixels="True"
                  Data="{Binding PathGeometry}">
            </Path>
            <Grid Style="{StaticResource ArrowGridStyle}"
                  Canvas.Left="{Binding AnchorPositionSource.X}"
                  Canvas.Top="{Binding AnchorPositionSource.Y}">
              <Path Name="PART_SourceAnchorPath"/>
              <Grid.LayoutTransform>
                <RotateTransform Angle="{Binding AnchorAngleSource}"/>
              </Grid.LayoutTransform>
            </Grid>
            <Grid Style="{StaticResource ArrowGridStyle}"
                  Canvas.Left="{Binding AnchorPositionSink.X}"
                  Canvas.Top="{Binding AnchorPositionSink.Y}">
              <Path Name="PART_SinkAnchorPath"/>
              <Grid.LayoutTransform>
                <RotateTransform Angle="{Binding AnchorAngleSink}"/>
              </Grid.LayoutTransform>
            </Grid>

            <!--Uncomment this to show default label text-->
            <!--<TextBlock Width="100" Height="35" Text="Label"                       
                       Canvas.Left="{Binding LabelPosition.X}"
                       Canvas.Top="{Binding LabelPosition.Y}">
              <TextBlock.RenderTransform>
                <TranslateTransform X="5" Y="5"/>
              </TextBlock.RenderTransform>
            </TextBlock>-->

            <Canvas.BitmapEffect>
              <DropShadowBitmapEffect Color="Gray" Direction="315" ShadowDepth="10" Softness="0" Opacity="0.1"/>
            </Canvas.BitmapEffect>
          </Canvas>
          <ControlTemplate.Triggers>
            <DataTrigger Value="Arrow" Binding="{Binding RelativeSource={RelativeSource Self},Path=SourceArrowSymbol}">
              <Setter TargetName="PART_SourceAnchorPath" Property="Style" Value="{StaticResource Arrow}"/>
            </DataTrigger>
            <DataTrigger Value="Diamond" Binding="{Binding RelativeSource={RelativeSource Self},Path=SourceArrowSymbol}">
              <Setter TargetName="PART_SourceAnchorPath" Property="Style" Value="{StaticResource Diamond}"/>
            </DataTrigger>
            <DataTrigger Value="Arrow" Binding="{Binding RelativeSource={RelativeSource Self},Path=SinkArrowSymbol}">
              <Setter TargetName="PART_SinkAnchorPath" Property="Style" Value="{StaticResource Arrow}"/>
            </DataTrigger>
            <DataTrigger Value="Diamond" Binding="{Binding RelativeSource={RelativeSource Self},Path=SinkArrowSymbol}">
              <Setter TargetName="PART_SinkAnchorPath" Property="Style" Value="{StaticResource Diamond}"/>
            </DataTrigger>
          </ControlTemplate.Triggers>
        </ControlTemplate>
      </Setter.Value>
    </Setter>
  </Style>
</ResourceDictionary>

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

sukram

Austria Austria
No Biography provided

| Advertise | Privacy | Mobile
Web04 | 2.8.140916.1 | Last Updated 29 Feb 2008
Article Copyright 2008 by sukram
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid