ListBox中的VSIX扩展下降事件未触发

时间:2019-01-10 12:39:36

标签: c# visual-studio vsix vs-extensibility

我试图在Visual Studio扩展中的两个或多个ListBox(在这里是TaskList和Doing框)之间拖放元素,但是由于某种原因,不会触发Drop事件。

当前代码如下:

private void TaskListBox_MouseMove(object sender, System.Windows.Input.MouseEventArgs e)
    {
        if (TaskListBox.Items.Count == 0)
            return;

        if (TaskListBox.SelectedItem == null)
            return;

        if (e.LeftButton == System.Windows.Input.MouseButtonState.Pressed)
        {
            string s = TaskListBox.SelectedItem.ToString();

            DragDrop.DoDragDrop(TaskListBox, s, DragDropEffects.All);
        }

    }

private void DoingBox_DragEnter(object sender, DragEventArgs e)
    {
        if (e.Data.GetDataPresent(DataFormats.StringFormat))
            e.Effects = DragDropEffects.All;
        else
            e.Effects = DragDropEffects.None;

    }

private void DoingBox_DragOver(object sender, DragEventArgs e)
    {
        if (e.Data.GetDataPresent(DataFormats.StringFormat))
            e.Effects = DragDropEffects.All;
        else
            e.Effects = DragDropEffects.None;
    }

private void DoingBox_Drop(object sender, DragEventArgs e)
    {

        if (e.Data.GetDataPresent(DataFormats.StringFormat))
        {
            string dataString = (string)e.Data.GetData(DataFormats.StringFormat);
            DoingBox.Items.Add(dataString);
        }
    }

private void DoingBox_DragLeave(object sender, DragEventArgs e)
    {
        MessageBox.Show("Left or cancelled");
    }

每个事件都可以正常工作,除了Drop和部分离开。我可以将ListBox项目拖放到TextBoxes中,但不能放入其他ListBoxes中。当我释放一个项目时,甚至当我试图将鼠标悬停在第二个ListBox上时,都会立即触发请假事件。

我在这里想念什么?解决方案或至少一种解决方法将不胜感激。

0 个答案:

没有答案