locked
DragOver event doesn't work RRS feed

  • Question

  • Hello,

    I'm implementing simple excerise with DragOver event. Please have a look on the code below and let me know what's wrong? The event is not being fired. In "Rectangle_DragOver" event handler I have a simple Message.Show statement.

    Thanks in advance

    cheers
    Pete

    <StackPanel AllowDrop="True" DragOver="Rectangle_DragOver">
    
                <Rectangle AllowDrop="True" DragOver="Rectangle_DragOver">
                    
        			<i:Interaction.Behaviors>
        				<ei:MouseDragElementBehavior/>
        			</i:Interaction.Behaviors>
                    
        		</Rectangle>
    
    </StackPanel>


     

    Wednesday, December 1, 2010 9:27 AM

All replies

  • Hi

    Is the "Rectangle_DragOver" event handler just in the code behind? If so, try this:

    <StackPanel>
       <Rectangle AllowDrop="True" DragOver="Rectangle_DragOver" Height="400" Fill="White" />
    </StackPanel>


    I just have the height attribute in there to make sure there was a rectangle area to drag to.  You can also change the Fill colour to anything you like, including "Transparent", but this appears to be the attribute you need to get the event to fire when using a Rectangle.

    Hope this helps.

    Thanks.

    Thursday, December 2, 2010 4:39 AM
  • Adding Height and Background attributes to Rectangle didn't help. The even is still not fired :(

    thanks

    Thursday, December 2, 2010 5:32 AM
  • Oh I've got the following in my Page.xaml:

    .........
    <Grid x:Name="LayoutRoot">
      <StackPanel>
        <Rectangle AllowDrop="True" DragOver="Rectangle_DragOver" Height="400" Fill="Transparent" />
      </StackPanel>
    </Grid>
    ..........


    And the following in the code behind Page.xaml.cs:

    private void Rectangle_DragOver(object sender, System.Windows.DragEventArgs e)
    {
        MessageBox.Show("This drag over works");
    }

    And the event fires fine.  Where is you event handler, in your code behind or are you using MVVM?

    Thanks

    Thursday, December 2, 2010 6:02 AM
  • Ahhh I see what you mean now.

    Yes, it works fine with i.e. images you are dragging but I want ti to fire the event when I drag over other UIElement within the same Silverlight application.

    Thursday, December 2, 2010 6:13 AM