locked
UIElements collisions RRS feed

  • Question

  • Hi,

    In my application I need to check if one dragable UI element (in this case simple Rectangle) 'touches' other (not dragable) UI element (Other simple Rectangle). I tried to set drag events (DragEnter, DragLeave, DragOver) but it didn't work. I have also set AlloDrop to 'true'.

    Not sure what else I could do. Please help.

    cheers

    pete

     

    <Rectangle AllowDrop="True" Fill="#FFD21C1C" DragEnter="Rectangle_DragEnter" Width="100" Height="100">

    <i:Interaction.Behaviors>
    <ei:MouseDragElementBehavior/>
    </i:Interaction.Behaviors> 

    </Rectangle>

    Tuesday, November 16, 2010 11:31 AM

Answers

  • Hi pete. Are you looking for the right event to hook where you can place your collision detection algorithm, or are you looking for the collision detection algorithm itself? I think you could hook the mouse move event, and based on a flag that is set when you drag objects, check for collisions in that.

    If you're looking for an algorithm, then I recommend one of the gaming tutorials out there, because this is a common problem in game programming. For best performance, I'd use a bounding box algorithm like that (it's really only a few lines). If you need more accuracy and have e.g. transparent parts in your elements, use a per-pixel algorithm like that one.

    Wednesday, November 17, 2010 12:41 AM