简体   繁体   中英

Drag and Drop Storagefile from one listview to another

I have 2 list views and I'm trying to drag an item from one to the other. The typeof item is a storagefile.

private async void ListA_DragItemsStarting(object sender, DragItemsStartingEventArgs e)
    {
        List<IStorageItem> files = new List<IStorageItem>();
        StorageFile file = e.Items;
        files.Add(file);

        e.Data.SetStorageItems(files);
    }
    private void ListC_DragEnter(object sender, DragEventArgs e)
    {
        e.AcceptedOperation = DataPackageOperation.Copy;

    }
    private async void ListC_Drop(object sender, DragEventArgs e)
    {


        //if (e.DataView.Contains(StandardDataFormats.StorageItems))
        //{

        //    var items = await e.DataView.GetStorageItemsAsync();
        //    if (items.Count > 0)
        //    {
        //        var storageFile = items[0] as StorageFile;
        //        ListC.Items.Add(storageFile);
        //    }
        // }

    }

I've tried everything I can think of to drop the storage file into the other listview and show the display name... All I've been able to display are types and stuff.

Can anyone help me?

I've solved it after hours or trying.

        private async void ListA_DragItemsStarting(object sender, DragItemsStartingEventArgs e)
    {
        //f.MessageBox(e.Items.First().GetType().ToString());
        try
        {
            List<IStorageItem> files = new List<IStorageItem>();
            StorageFile file = e.Items.First() as StorageFile;
            files.Add(file);
            e.Data.SetStorageItems(files);
            //e.Data.SetData(StandardDataFormats.Text, e.Items.);


        }catch(Exception ex)
        {
            f.MessageBox(ex.Message);
        }

    }
    private async void ListC_DragEnter(object sender, DragEventArgs e)
    {
        e.AcceptedOperation = DataPackageOperation.Copy;
        //IReadOnlyList<IStorageItem> files = await e.DataView.GetStorageItemsAsync();


    }
    private async void ListC_Drop(object sender, DragEventArgs e)
    {
        try
        {
            if (e.DataView.Contains(StandardDataFormats.StorageItems))
            {


                var items = await e.DataView.GetStorageItemsAsync();
                if (items.Count > 0)
                {
                    var storageFile = items[0] as StorageFile;
                    ListC.Items.Add(storageFile.Name);
                }
            }
        }catch
        {
            f.MessageBox("nope");
        }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM