【问题标题】:Drag and Drop Storagefile from one listview to another将 Storagefile 从一个列表视图拖放到另一个
【发布时间】:2017-06-11 02:37:18
【问题描述】:

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

    }

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

谁能帮帮我?

【问题讨论】:

    标签: c# listview drag-and-drop uwp storagefile


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-09-18
      • 1970-01-01
      • 1970-01-01
      • 2011-07-23
      • 2021-04-05
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多