Welcome to Windows Presentation Foundation (WPF)
Top Tasks :

Dragable Objects

File Details
Downloads: 1090 File Size: 34.1kB
Posted By: aatwal Views: 3314
Date Added: 19 Oct 2006

Simply create a Thumb control and override its template to achieve whatever visual you wish.  In this case I have made the Thumb’s visual an Ellipse.  Then create a handler for the DragDelta event and change the Thumb’s position.  Note that I have chosen to use the Canvas.SetLeft and SetTop properties meaning that the dragable object needs to be contained within a Canvas.

 

<Window x:Class="DragableObject.Window1"

    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

    Title="DragableObject" Height="300" Width="300"

    >

  <Window.Resources>

    <ResourceDictionary>

      <ControlTemplate x:Key="template1">

        <Ellipse Width="60" Height="30" Fill="Black"/>

      </ControlTemplate>

    </ResourceDictionary>

  </Window.Resources>

 

  <Canvas Name="myCanvas">

    <Thumb Name="myThumb" DragDelta="onDragDelta" Canvas.Left="0" Canvas.Top="0" Template="{StaticResource template1}"/>

  </Canvas>

</Window>

 

 

void onDragDelta(object sender, DragDeltaEventArgs e)

{

  Canvas.SetLeft(myThumb, Canvas.GetLeft(myThumb) +

    e.HorizontalChange);

  Canvas.SetTop(myThumb, Canvas.GetTop(myThumb) +

    e.VerticalChange);

}

Comments
No comments exist for this file.

Add Comment

Name (required)
Web Site (optional)
Comment (required)
Add

Copyright © 2006 Microsoft Corporation. All Rights Reserved. | Terms of Use | Privacy Statement | Contact Us