0

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

当我使用 .Net 3.5 时,我没有任何问题,但由于我将项目更改为 .Net 4.5,所以当我在两个 listBox 之间的 listBoxItem 上进行拖放时,我有一个例外:

“不可能在类型中投射 MS.Internal.Named.Object 类型的对象......”

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

(对不起我的英语,我是法国人^^)

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

如果有人感兴趣,这是拖放的代码:):

区域拖放

    /// <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
4

1 回答 1

0

你试过了吗

 _dragged.Content AS Retro.Model.core.Shape
于 2014-04-17T12:28:51.770 回答