Drop Event on LibraryBar

95 views Asked by At

I am trying to attach an event handler to the drop event on some LibraryBars on the Surface table (v1.0, .NET 3.5) so that I can move elements to various ObservableCollections.

I can fire events on all the related drag n' drop events (such as PreviewDrop, DragEnter) EXCEPT the Drop event itself - the most important part. When I took a look into who was handling the event through Snoop, it seems to be marked as handled by the Grid.

XAML:

 <Grid Background="{StaticResource WindowBackground}">

    <s:LibraryBar 
        x:Name="startingBar"
        HorizontalAlignment="Left" 
        VerticalAlignment="Top"
        ItemsSource="{Binding Path=sourceList}"
        ItemTemplate="{StaticResource LibraryBarTemp}"
        AllowDrop="True">
    </s:LibraryBar>

    <s:LibraryBar 
        x:Name="destinationBar"
        HorizontalAlignment="Right" 
        VerticalAlignment="Bottom" 
        AllowDrop="True"
        s:SurfaceDragDrop.PreviewDrop="OnPreviewDrop"
        s:SurfaceDragDrop.Drop="OnDropCompleted"
        ItemTemplate="{StaticResource LibraryBarTemp}"
        ItemsSource="{Binding Path=testList}">
    </s:LibraryBar>
</Grid>

And C#:

public SurfaceWindow1()
    {
        InitializeComponent();

        // Add handlers for Application activation events
        AddActivationHandlers();

        sourceList.Add(new Player("Jane"));
        sourceList.Add(new Player("Joe"));
        sourceList.Add(new Player("Jill"));
        sourceList.Add(new Player("Julia"));
        sourceList.Add(new Player("John"));

        startingBar.ItemsSource = sourceList;
    }


    #region OnPreviewDrop
    private void OnPreviewDrop(object sender, SurfaceDragDropEventArgs e)
    {
        if (startingBar.IsAncestorOf(e.Cursor.DragSource))
        {
            e.Effects = DragDropEffects.Move;
        }
    }

    private void OnDropCompleted(object sender, SurfaceDragDropEventArgs e)
    {
        sourceList.Remove(e.Cursor.Data as Player);
        testList.Add(e.Cursor.Data as Player);
    }

Maybe I have been staring at this too long and there's a simple solution. The MSDN says that LibraryBars come ready to handle drag and drop, so I am confused why the event would be bubbling up. How do I get the event to fire so I can add to the lists?

Thanks for any help!

EDIT: Added some more information -When "OnDropCompleted" is attached to anything else (such as the DragEnter event), the ObservableCollections are added to and removed from, but I need it on the Drop event itself.

0

There are 0 answers