Click here to Skip to main content
15,885,985 members
Articles / Desktop Programming / WPF

WPF Diagram Designer: Part 1

Rate me:
Please Sign up or sign in to vote.
4.97/5 (297 votes)
23 Aug 2008CPOL7 min read 929.5K   62.4K   680  
Drag, resize and rotate elements on a Canvas
<Window x:Class="DragAndResizeControl.Window1"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:s="clr-namespace:DragAndResizeControl"
        Title="Diagram Designer - Part 1"
        Height="500" Width="750">
  <Window.Resources>
    <ResourceDictionary>
      <ResourceDictionary.MergedDictionaries>
        <ResourceDictionary Source="./DesignerItem.xaml"/>
        <ResourceDictionary Source="./Shared.xaml"/>
      </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>
  </Window.Resources>
  <Canvas>
    <!-- Ellipse -->
    <ContentControl Width="130" Height="130" Canvas.Top="50" Canvas.Left="70"
                    Template="{StaticResource DragableAndResizableDesignerItem}">
      <Ellipse Fill="{StaticResource Orange}" IsHitTestVisible="False"/>
    </ContentControl>
    <!-- Ellipse with shadow-->
    <ContentControl Width="130" Height="130" Canvas.Top="50" Canvas.Left="530"
                    Template="{StaticResource DragableDesignerItem}">
      <Ellipse Fill="{StaticResource Blue}" IsHitTestVisible="False">
        <Ellipse.BitmapEffect>
          <DropShadowBitmapEffect Color="Gray" Direction="320" ShadowDepth="25"
                                  Softness="1" Opacity="0.5"/>
        </Ellipse.BitmapEffect>
      </Ellipse>
    </ContentControl>
    <!-- Weather Sun -->
    <ContentControl Width="130" Height="130" Canvas.Top="50" Canvas.Left="300"
                    Template="{StaticResource DragableDesignerItem}">
      <Image IsHitTestVisible="false" Stretch="Fill">
        <Image.Source>
          <DrawingImage Drawing="{StaticResource SunDrawingResource}" />
        </Image.Source>
      </Image>
    </ContentControl>
    <!-- FlowChart PaperTape -->
    <ContentControl Width="130" Height="130" Canvas.Top="250" Canvas.Left="70"
                    Template="{StaticResource DragableDesignerItem}">
      <Path Stroke="Black" Stretch="Fill" StrokeThickness="6"
                    StrokeLineJoin="Round" IsHitTestVisible="False"
                    Data="M 100,200 C 200,180 200,220 300,200 V 300 C 200,320
                    200,280 100,300 Z"/>
    </ContentControl>
    <!-- Star -->
    <ContentControl Width="130" Height="130" Canvas.Top="250" Canvas.Left="530"
                    Template="{StaticResource DragableAndResizableDesignerItem}">
      <Path Stroke="Red" Stretch="Fill" StrokeThickness="8" StrokeLineJoin="Round"
                    IsHitTestVisible="False" Data="M 9,2 11,7 17,7 12,10 14,15 9,12
                    4,15 6,10 1,7 7,7 Z" />
    </ContentControl>
    <!-- Weather Rain -->
    <ContentControl Width="130" Height="130" Canvas.Top="250" Canvas.Left="300"
                    Template="{StaticResource DragableDesignerItem}">
      <Image IsHitTestVisible="false">
        <Image.Source>
          <DrawingImage Drawing="{StaticResource RainDrawingResource}" />
        </Image.Source>
      </Image>
    </ContentControl>
  </Canvas>
</Window>

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)


Written By
Austria Austria
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions