ListBoxItem内容投射不可能

时间:2014-04-17 12:25:12

标签: c# listboxitem oledragdrop

我在c#using.Net 4.5中遇到了问题。

当我使用.Net 3.5时我没有任何问题,但是因为我将我的项目更改为.Net 4.5,当我在两个listBox之间执行我的拖放和listBox时,我有一个例外:

  

“无法在类型......中投射MS.Internal.Named.Object类型的对象”

关于这个问题的任何想法?

(抱歉我的英文,我是法国人^^)

编辑: 是的,当我使用“as ...”时,我丢失了一些数据。 最后我重新定义了Drag& Frop的功能,问题得到了解决。

如果有人感兴趣的话,这是Drag& Drop的代码:):

区域拖放

    /// <summary>
    /// Define the action when the left mouse button is pressed while the mouse pointer is over this element. Permit to get the shape selected by the clic
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void ListBoxShapeCluster_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
    {
        System.Windows.Controls.ListBox parent = (System.Windows.Controls.ListBox)sender;
        dragSource = parent;
        object data = GetDataFromListBox(dragSource, e.GetPosition(parent));

        if (data != null)
        {
            DragDrop.DoDragDrop(parent, data, System.Windows.DragDropEffects.Move);
        }

    }
    /// <summary>
    /// Define the action of the drag enter
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void ListBoxShapeCluster_DragEnter(object sender, System.Windows.DragEventArgs e)
    {
        object data = e.Data.GetData(typeof(Retro.Model.core.Shape));
        if (data != null)
        {
            AllShapesOfCurrentCluster.Remove((Retro.Model.core.Shape)data);
        }

    }
    /// <summary>
    /// Define the action for drop a shape in a new cluster
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void ListBoxShapeCluster_Drop(object sender, System.Windows.DragEventArgs e)
    {

        System.Windows.Controls.ListBox parent = (System.Windows.Controls.ListBox)sender;
        object data = e.Data.GetData(typeof(Retro.Model.core.Shape));
        if (data != null)
        {
            AllShapesOfCurrentCluster.Add((Retro.Model.core.Shape)data);
        }

    }



    #endregion

1 个答案:

答案 0 :(得分:0)

你试过吗

 _dragged.Content AS Retro.Model.core.Shape