ListBoxItem Содержимое Cast Невозможно
У меня есть проблема в C# с использованием.Net 4.5.
Когда я использовал.Net 3.5, у меня не было никаких проблем, но с тех пор, как я изменил свой проект на.Net 4.5, когда я выполняю перетаскивание на listBoxItem между двумя listBox, у меня возникает исключение:
"Невозможно привести объект типа MS.Internal.Named.Object к типу..."
Есть идеи по поводу проблемы?
(Извините за мой английский, я французский ^^)
РЕДАКТИРОВАТЬ: Да, и я теряю некоторые данные, когда я использую "как...". Наконец, я переопределил свои функции для Drag&Frop, и проблема была решена.
Вот код для Drag&Drop, если кому-то интересно:):
Регион 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