Click here to Skip to main content
15,881,559 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 928.3K   62.4K   680  
Drag, resize and rotate elements on a Canvas
<Window x:Class="DragResizeRotateItems.Window1"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        SnapsToDevicePixels="True"
        Height="500" Width="800"
        WindowStartupLocation="CenterScreen"
        Title="Diagram Designer - Part I">
  
  <Window.Resources>
    <ResourceDictionary>
      <ResourceDictionary.MergedDictionaries>
        <ResourceDictionary Source="./DesignerItem.xaml"/>
      </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>
  </Window.Resources>

  <Grid>
    <Canvas Name="DesignerCanvas" Background="White">

      <!-- Image -->
      <ContentControl Width="130" Height="130" Canvas.Top="100" Canvas.Left="70">
        <Image IsHitTestVisible="False"  Stretch="Fill" Source="./media/iPod.png"/>
      </ContentControl>

      <!-- Image -->
      <ContentControl Width="130" Height="130" Canvas.Top="100" Canvas.Left="320">
        <Image IsHitTestVisible="False"  Stretch="Fill" Source="./media/Phone.png"/>
      </ContentControl>

      <!-- ProgressBar and Slider -->
      <ContentControl Width="130" Height="130" Canvas.Top="100" Canvas.Left="570">
        <Grid>
          <Rectangle Fill="{StaticResource RectBackground}" RadiusX="8" RadiusY="8" IsHitTestVisible="False"/>
          <Border BorderBrush="#77305C88" BorderThickness="1" CornerRadius="8">
            <StackPanel Margin="5,20,5,5">
              <Slider Margin="5"/>
              <ProgressBar Name="progressBar" Maximum="100" Height="20" Margin="5">
                <ProgressBar.Triggers>
                  <EventTrigger RoutedEvent="ProgressBar.Loaded">
                    <BeginStoryboard>
                      <Storyboard>
                        <DoubleAnimation Storyboard.TargetName="progressBar"
                                         Storyboard.TargetProperty="Value"
                                         RepeatBehavior="Forever"
                                         AutoReverse="True"
                                         Duration="0:0:2" From="0" To="100" />
                      </Storyboard>
                    </BeginStoryboard>
                  </EventTrigger>
                </ProgressBar.Triggers>
              </ProgressBar>
            </StackPanel>
          </Border>
        </Grid>
      </ContentControl>

      <!--MediaElement -->
      <ContentControl Width="130" Height="130" Canvas.Top="300" Canvas.Left="320">
        <Grid>
          <Rectangle Fill="Black" RadiusX="8" RadiusY="8" IsHitTestVisible="False"/>
          <TextBlock Text="Video" HorizontalAlignment="Center" VerticalAlignment="Bottom" Foreground="#AAFFFFFF" FontSize="18" IsHitTestVisible="False" Margin="10" />
          <MediaElement IsHitTestVisible="False" Name="mediaElement" Margin="10,10,10,30" Stretch="Fill" >
            <MediaElement.Triggers>
              <EventTrigger RoutedEvent="MediaElement.Loaded">
                <EventTrigger.Actions>
                  <BeginStoryboard>
                    <Storyboard>
                      <MediaTimeline Source="./media/intro.wmv" Storyboard.TargetName="mediaElement"
                        RepeatBehavior="Forever" />
                    </Storyboard>
                  </BeginStoryboard>
                </EventTrigger.Actions>
              </EventTrigger>
            </MediaElement.Triggers>
          </MediaElement>
        </Grid>
      </ContentControl>

      <!-- Image -->
      <ContentControl Width="130" Height="130" Canvas.Top="300" Canvas.Left="70">
        <Image IsHitTestVisible="False"  Stretch="Fill" Source="./media/Graph.png"/>
      </ContentControl>

      <!-- Image -->
      <ContentControl Width="130" Height="130" Canvas.Top="300" Canvas.Left="570">
        <Image IsHitTestVisible="False"  Stretch="Fill" Source="./media/Excavator.png"/>
      </ContentControl>

    </Canvas>

    <CheckBox Name="checkBox" IsThreeState="False" IsChecked="True" Margin="10"
              Content="select all" Click="OnClicked" FontSize="14" Foreground="Gray"
              VerticalAlignment="Top" HorizontalAlignment="Center"/>
  </Grid>
</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