Click here to Skip to main content
12,298,379 members (46,830 online)
Click here to Skip to main content

Stats

439.2K views
16K downloads
535 bookmarked
Posted

WPF Diagram Designer - Part 3

, 29 Feb 2008 CPOL
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">

  <!-- Connector Style -->
  <Style TargetType="{x:Type s:Connector}">
    <Setter Property="Width" Value="8"/>
    <Setter Property="Height" Value="8"/>
    <Setter Property="Cursor" Value="Cross"/>
    <Setter Property="SnapsToDevicePixels" Value="true"/>
    <Setter Property="Template">
      <Setter.Value>
        <ControlTemplate TargetType="{x:Type s:Connector}">
          <Grid>
            <!-- transparent extra space makes connector easier to hit -->
            <Rectangle Fill="Transparent" Margin="-2"/>
            <Rectangle Fill="Lavender" StrokeThickness="1" Stroke="#AA000080"/>
          </Grid>
        </ControlTemplate>
      </Setter.Value>
    </Setter>
  </Style>

  <!-- ConnectorDecoratorTemplate Default Template -->
  <ControlTemplate x:Key="ConnectorDecoratorTemplate" TargetType="{x:Type Control}">
    <Grid Margin="-5">
      <s:Connector Orientation="Left" VerticalAlignment="Center" HorizontalAlignment="Left"/>
      <s:Connector Orientation="Top" VerticalAlignment="Top" HorizontalAlignment="Center"/>
      <s:Connector Orientation="Right" VerticalAlignment="Center" HorizontalAlignment="Right"/>
      <s:Connector Orientation="Bottom" VerticalAlignment="Bottom" HorizontalAlignment="Center"/>
    </Grid>
  </ControlTemplate>

  <!-- ResizeDecorator Default Template -->
  <ControlTemplate x:Key="ResizeDecoratorTemplate" TargetType="{x:Type Control}">
    <Grid Opacity="0.7" SnapsToDevicePixels="true">
      <c:ResizeThumb Height="3" Cursor="SizeNS" Margin="0 -4 0 0"
                     VerticalAlignment="Top" HorizontalAlignment="Stretch"/>
      <c:ResizeThumb Width="3" Cursor="SizeWE" Margin="-4 0 0 0"
                     VerticalAlignment="Stretch" HorizontalAlignment="Left"/>
      <c:ResizeThumb Width="3" Cursor="SizeWE" Margin="0 0 -4 0"
                     VerticalAlignment="Stretch" HorizontalAlignment="Right"/>
      <c:ResizeThumb Height="3" Cursor="SizeNS" Margin="0 0 0 -4"
                     VerticalAlignment="Bottom" HorizontalAlignment="Stretch"/>
      <c:ResizeThumb Width="7" Height="7" Cursor="SizeNWSE" Margin="-6 -6 0 0"
                     VerticalAlignment="Top" HorizontalAlignment="Left"/>
      <c:ResizeThumb Width="7" Height="7" Cursor="SizeNESW" Margin="0 -6 -6 0"
                     VerticalAlignment="Top" HorizontalAlignment="Right"/>
      <c:ResizeThumb Width="7" Height="7" Cursor="SizeNESW" Margin="-6 0 0 -6"
                     VerticalAlignment="Bottom" HorizontalAlignment="Left"/>
      <c:ResizeThumb Width="7" Height="7" Cursor="SizeNWSE" Margin="0 0 -6 -6"
                     VerticalAlignment="Bottom" HorizontalAlignment="Right"/>
    </Grid>
  </ControlTemplate>

  <!-- 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>

  <!-- DesignerItem Style -->
  <Style TargetType="{x:Type s:DesignerItem}">
    <Setter Property="MinWidth" Value="25"/>
    <Setter Property="MinHeight" Value="25"/>
    <Setter Property="SnapsToDevicePixels" Value="True"/>
    <Setter Property="Template">
      <Setter.Value>
        <ControlTemplate TargetType="{x:Type s:DesignerItem}">
          <Grid DataContext="{Binding RelativeSource={RelativeSource TemplatedParent}}">
            <!-- PART_DragThumb -->
            <c:DragThumb x:Name="PART_DragThumb" Cursor="SizeAll"/>
            <!-- PART_ResizeDecorator -->
            <Control x:Name="PART_ResizeDecorator"
                     Visibility="Collapsed"
                     Template="{StaticResource ResizeDecoratorTemplate}"/>
            <!-- PART_ContentPresenter -->
            <ContentPresenter x:Name="PART_ContentPresenter"
                              HorizontalAlignment="Stretch"
                              VerticalAlignment="Stretch"
                              Content="{TemplateBinding ContentControl.Content}"
                              Margin="{TemplateBinding ContentControl.Padding}"/>
            <!-- PART_ConnectorDecorator -->
            <Control x:Name="PART_ConnectorDecorator"
                     Visibility="Hidden"
                     Template="{StaticResource ConnectorDecoratorTemplate}"/>
          </Grid>
          <ControlTemplate.Triggers>
            <DataTrigger Value="True" Binding="{Binding RelativeSource={RelativeSource Self},Path=IsSelected}">
              <Setter TargetName="PART_ResizeDecorator" Property="Visibility" Value="Visible"/>
            </DataTrigger>
            <Trigger Property="IsMouseOver" Value="true">
              <Setter TargetName="PART_ConnectorDecorator" Property="Visibility" Value="Visible"/>
            </Trigger>
            <DataTrigger Value="True" Binding="{Binding RelativeSource={RelativeSource Self},Path=IsDragConnectionOver}">
              <Setter TargetName="PART_ConnectorDecorator" Property="Visibility" Value="Visible"/>
            </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

You may also be interested in...

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.160525.2 | Last Updated 29 Feb 2008
Article Copyright 2008 by sukram
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid