Click here to Skip to main content
12,747,151 members (27,985 online)
Click here to Skip to main content
Add your own
alternative version


2 bookmarked
Posted 29 Aug 2010

How to make any UI element drag-able using Behaviors in WPF

, 29 Aug 2010 CPOL
Rate this:
Please Sign up or sign in to vote.
in order to make your UI element drag-able without any extra code, all what you have to do is just selecting behaviors from Assets panel in Expression Blend then drag and drop the MouseDragElementBehavior to your UI element.
for example we will do this to a rectangle here you are the XAML code:

<Rectangle Fill="Red" Stroke="Black" Margin="230,218,172,132"> 

don't forget to include these namespaces:
xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity" xmlns:il="clr-namespace:Microsoft.Expression.Interactivity.Layout;assembly=Microsoft.Expression.Interactions"

if you are working with Blend, they will be placed automatically after setting the drag behavior, and if you are using Visual Studio you will need to set them manually


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Software Developer Asset Technology Group
Egypt Egypt
I'm a professional components designer, web developer, UX engineer and 3d designer as well, I'm 4 years experienced .net software engineer and 7 years experienced 3d designer using 3D Max. I'm very interested in RIA technologies, prototyping and UX engineering.

Ahmed Said
Senior .Net Software Engineer

You may also be interested in...


Comments and Discussions

QuestionThank you Pin
André Canha1-Jul-12 8:02
memberAndré Canha1-Jul-12 8:02 
Generalthe drag behavior enables you to drag the element you want, ... Pin
Ahmed_Said31-Aug-10 2:34
memberAhmed_Said31-Aug-10 2:34 
GeneralIt will only allow you to drag a UI Element inside its conta... Pin
Simon Dufour30-Aug-10 3:09
memberSimon Dufour30-Aug-10 3:09 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170215.1 | Last Updated 29 Aug 2010
Article Copyright 2010 by Ahmed_Said
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid