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 4

, 26 Mar 2008
A Frankenbuild
diagramdesignerpart4.zip
DiagramDesigner
Controls
DiagramDesigner.csproj.user
Properties
Settings.settings
Resources
Images
AlignObjectsBottom.png
AlignObjectsCenteredHorizontal.png
AlignObjectsCenteredVertical.png
AlignObjectsLeft.png
AlignObjectsRight.png
AlignObjectsTop.png
BringForward.png
BringToFront.png
Copy.png
Cut.png
Delete.png
DistributeObjectsHorizontal.png
DistributeObjectsVertical.png
GenericDocument.png
Group.png
OpenFolder.png
Paste.png
PasteBig.png
Print.png
Save.png
SendBackward.png
SendToBack.png
Ungroup.png
Stencils
Styles
<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">

    <ContextMenu x:Key="ConnectionContextMenu">
        <MenuItem Header="Delete" Command="{x:Static ApplicationCommands.Delete}">
            <MenuItem.Icon>
                <Image Source="Images/Delete.png" Width="16"/>
            </MenuItem.Icon>
        </MenuItem>
        <Separator/>
        <MenuItem Header="Order">
            <MenuItem Header="Bring Forward" Command="{x:Static s:DesignerCanvas.BringForward}">
                <MenuItem.Icon>
                    <Image Source="Images/BringForward.png" Width="16"/>
                </MenuItem.Icon>
            </MenuItem>
            <MenuItem Header="Bring To Front" Command="{x:Static s:DesignerCanvas.BringToFront}">
                <MenuItem.Icon>
                    <Image Source="Images/BringToFront.png" Width="16"/>
                </MenuItem.Icon>
            </MenuItem>
            <MenuItem Header="Send Backward" Command="{x:Static s:DesignerCanvas.SendBackward}">
                <MenuItem.Icon>
                    <Image Source="Images/SendBackward.png" Width="16"/>
                </MenuItem.Icon>
            </MenuItem>
            <MenuItem Header="Send To Back" Command="{x:Static s:DesignerCanvas.SendToBack}">
                <MenuItem.Icon>
                    <Image Source="Images/SendToBack.png" Width="16"/>
                </MenuItem.Icon>
            </MenuItem>
        </MenuItem>
    </ContextMenu>

    <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}}"
                            ContextMenu="{StaticResource ConnectionContextMenu}">
                        <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="{Binding Path=(Canvas.ZIndex)}"
                                       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
Web01 | 2.8.140926.1 | Last Updated 26 Mar 2008
Article Copyright 2008 by sukram
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid