在LibraryBar上删除事件

时间:2013-12-09 07:19:01

标签: c# event-handling pixelsense

我正在尝试将事件处理程序附加到Surface表(v1.0,.NET 3.5)上的某些LibraryBars上的drop事件,以便我可以将元素移动到各种ObservableCollections。

我可以在所有相关的拖放事件(例如PreviewDrop,DragEnter)上触发事件,除了Drop事件本身 - 最重要的部分。当我通过Snoop查看谁正在处理事件时,它似乎被标记为由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>

和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);
    }

也许我一直在盯着这个太久了,这是一个简单的解决方案。 MSDN说LibraryBars已经准备好处理拖放了,所以我很困惑为什么这个事件会冒泡。如何让事件触发,以便我可以添加到列表中?

感谢您的帮助!

编辑:添加了一些更多信息 - 当“OnDropCompleted”附加到其他任何东西(例如DragEnter事件)时,会添加和删除ObservableCollections,但我需要在Drop事件本身上使用它。

0 个答案:

没有答案