拖放多个选择

时间:2015-11-04 11:09:16

标签: c# .net wpf listview drag-and-drop

我的Drag& amp;掉落功能。拖曳与Drop函数只适用于一个Item ..然后我试着让它适用于多个itemSelection,但是我没有得到它。

我的xaml包含2个ListViews,首先我显示我的List,其中将显示Items以将其拖动到另一个ListView:

<ListView Name="lvVaCodes" PreviewMouseLeftButtonDown="lvVaCodes_PreviewMouseLeftButtonDown" MouseMove="lvVaCodes_MouseMove" SelectionMode="Multiple"  >
                                <ItemsControl.ItemTemplate>
                                    <DataTemplate>
                                        <TextBlock Text="{Binding Title}" />
                                    </DataTemplate>
                                </ItemsControl.ItemTemplate>
                            </ListView>

这是我的ListView,应该显示已删除的项目:

<ListView Name="lvDebitor" Drop="lvDebitor_Drop" MinHeight="100" AllowDrop="True">
                            <ItemsControl.ItemTemplate>
                                <DataTemplate>
                                    <TextBlock Text="{Binding Title}" />
                                </DataTemplate>
                            </ItemsControl.ItemTemplate>
                        </ListView>

以下是我的活动:

    private void lvVaCodes_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
    {
        dragAction = true;
    }

    private void lvVaCodes_MouseMove(object sender, MouseEventArgs e)
    {
        if (dragAction == true && Mouse.LeftButton == MouseButtonState.Pressed)
        {
            _lastListView = sender as ListView;

            if (_lastListView != null && _lastListView.SelectedItems != null && _lastListView.SelectedItems.Count > 0)
            {
                DragDrop.DoDragDrop(_lastListView, new DataObject("ObservableCollectionViewItemData", _lastListView.SelectedItems), DragDropEffects.Move);
            }
        }
    }

    private void lvDebitor_Drop(object sender, DragEventArgs e)
    {
        IList items = e.Data.GetData("ObservableCollectionViewItemData") as IList;

        if (items == null || _lastListView == null)
        {
            return;
        }

        for(int i=0; i < items.Count; i++)
        {
            _vaCodesDeb.Add((TodoItem)items[i]);
            _vaCodes.Remove((TodoItem)items[i]);
        }
        dragAction = false;            
    }

    private void lvVess_Drop(object sender, DragEventArgs e)
    {
        IList items = e.Data.GetData("ObservableCollectionViewItemData") as IList;

        if (items == null || _lastListView == null)
        {
            return;
        }

        for (int i = 0; i < items.Count; i++)
        {
            _vaCodesVess.Add((TodoItem)items[i]);
            _vaCodes.Remove((TodoItem)items[i]);
        }
        dragAction = false;
    }

任何人都可以告诉我,为什么它不起作用?只会拖动一个项目&amp;丢弃。

0 个答案:

没有答案