0
votes

I'm scruiggling with Windows Phone behavior. And maybe you could help me out somehow.

I want to have a listview from which I can drag items to another Gridview.

So far I got dragging enabled by setting ReorderMode = "Enabled". Doing this has some drawbacks.

1. I'm not able to scroll in my listview anymore
2. I can't select items anymore
3. I don't want the items to be reordered

What I want to have:

1. When holding an item, I want to drag this to another gridview
2. I want still be able to scroll in the listview
3. I still want to be able to select items

Is that somehow possible to do in Windows Phone 8.1?! Can I do my own dragging? Is yes, how should I start?!

Many thanks for any advise

1

1 Answers

1
votes

ReorderMode isn't want you want in this case. Here's some basic functionality to do this between two ListViews:

<StackPanel Orientation="Horizontal" Width="800">
    <ListView x:Name="ListView1" HorizontalAlignment="Left" DragItemsStarting="ListView_DragItemsStarting" AllowDrop="True" CanDragItems="True" CanReorderItems="True" Drop="ListView_Drop"/>
    <ListView x:Name="ListView2" HorizontalAlignment="Right" DragItemsStarting="ListView_DragItemsStarting"    AllowDrop="True" CanDragItems="True" CanReorderItems="True"  Drop="ListView_Drop"/>
</StackPanel>
 ObservableCollection<string> AlphabetList;
 ObservableCollection<string> NumberList;
 protected override void OnNavigatedTo(NavigationEventArgs e)
 {
    AlphabetList = new ObservableCollection<string>();
    AlphabetList.Add("A");
    AlphabetList.Add("B");
    AlphabetList.Add("C");
    AlphabetList.Add("D");
    AlphabetList.Add("E");
    AlphabetList.Add("F");
    AlphabetList.Add("G");
    AlphabetList.Add("H");
    AlphabetList.Add("I");
    AlphabetList.Add("J");
    ListView1.ItemsSource = AlphabetList;

    NumberList = new ObservableCollection<string>();
    NumberList.Add("0");
    NumberList.Add("1");
    NumberList.Add("2");
    NumberList.Add("3");
    NumberList.Add("4");
    NumberList.Add("5");
    NumberList.Add("6");
    NumberList.Add("7");
    NumberList.Add("8");
    NumberList.Add("9");
    ListView2.ItemsSource = NumberList;
}

IList<object> DraggedItems;

private void ListView_DragItemsStarting(object sender, DragItemsStartingEventArgs e)
{
    DraggedItems = e.Items;
}

private void ListView_Drop(object sender, DragEventArgs e)
{
    ListView ThisListView = sender as ListView;
    ObservableCollection<string> AddingOC = (ThisListView.Name == "ListView1" ? AlphabetList :NumberList);
    ObservableCollection<string> RemovingOC = (ThisListView.Name == "ListView1" ? NumberList : AlphabetList);

    if (AddingOC.Contains(DraggedItems[0])) return;
    foreach (string O in DraggedItems)
    {
        RemovingOC.Remove(O);
        AddingOC.Add(O);
    }
}