Search code examples
c#drag-and-dropwindows-runtime

Is there an Drag/Drop Cancelled Event in WinRT?


im looking for an Drag/Drop cancelled event in Metro, this means if the user drags an item and drops it outside of an droppable area.

how can i achieve this or is there any workaround?


Solution

  • I have not found such an event (for c#/XAML)! Perhaps (hopefully) an event will exists in the final release!

    As a temporary workaround, I have registered to the Window.Current.CoreWindow.PointerReleased-event.
    On drag start then, I set a boolean indicator to true, and if drag ends, the PointerReleased-event will be fired and I can test for the boolean indicator.

    Workaround
    In the constructor of the Page (or whatever element) register to PointerReleased:

    Window.Current.CoreWindow.PointerReleased+=CoreWindow_PointerReleased;
    

    The eventhandler could look somehow like this:

    void CoreWindow_PointerReleased(CoreWindow sender, PointerEventArgs args) {
         if (m_isDragging) {
               m_isDragging = false;
               // Here you know that a drag-operation came to a end
         }
    }
    

    And the indicator you can set for example as follows;

        private void Entries_DragStarting(object sender, DragItemsStartingEventArgs e){            
            m_isDragging = true;
            // ...
        }