Expression Blend 4: Gaming the system: Moving an object on the screen

Expression Blend 4: Gaming the system: Moving an object on the screen

Rate This
  • Comments 1

We all know that guy who is always gaming the system, it’s so irritating, you don’t quite know how he does it, and his career kind of sucks, but somehow he figures it out.  Of course in software there are a lot of people who game the system, here is a clue: Software is about gaming the system.

So let’s talk about creating a simple moving object thingie using XAML in the Windows Phone, because like my name, we must not mention Silverlight these days.  Weird, Silverlight seems to be hanging around and the HTML 5 is trying to figure out just how does that Silverlight games the system.  But let’s face it, unless Silverlight gangs up with XNA, it takes a lot of work to make Silverlight do games all by itself. 

Thanks to Jerry Nixon, http://blogs.msdn.com/jerrynixon, he doesn’t really need the hits, but take a look anyway, he has a bunch of really well written and excellent examples that I am tempted to use in my blogs.  But I won’t, I refuse to increase the quality of this blog.  (And we can mention Jerry Nixon’s name. Smile )

Moving an object on the screen

Ok, let’s take a look at a quick way to move an object on the screen.  It might be cool to be able move an object without writing any code, unless you are writing articles, then it takes longer.  This might be reason we don’t see much being done with codeless programming, maybe not.

Open Expression, remove the existing Grid and stack panel, change the layout to canvas and add an image, I have a dorky stick figure and changed the background to an ugly green.  Now we want to add a MouseDragElementBehavior (which is supported on the phone). 

Do this by:

  1. Changing to the Assets tab
  2. Select Behaviors
  3. Drag the MouseDragElementBehavior to the image, that’s it
  4. Run your application and the image will be dragged by the mouse

Before dragging the MouseDragElementBehavior

image

 

After dragging the MouseDragElementBehavior

image

No C# code was generated, the drag did add XAML lines of  and two references.

Run your code and have some fun.  Note that the image will go off the side of the screen and if you add other images the dragged image just moves through it.

No promises on what I will write about next.

Leave a Comment
  • Please add 1 and 2 and type the answer here:
  • Post
  • Hey Jerry,

    Thanks for the post, I am wondering if you could help me with moving the object as we drag our touch in Windows phone. and animate as we drag to left or right according to it. Thanks in advance.

    Pranam Manandhar

Page 1 of 1 (1 items)