0

我有 2 个列表视图,我正在尝试将一个项目从一个拖到另一个。typeof 项目是一个存储文件。

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

    }

我已经尝试了所有我能想到的将存储文件放入另一个列表视图并显示显示名称的方法......我能够显示的只是类型和内容。

谁能帮我?

4

1 回答 1

0

我在几个小时或尝试后解决了它。

        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");
        }
于 2017-01-25T23:52:56.647 回答