List box with data template

77 views
Skip to first unread message

charles

unread,
Jan 13, 2011, 2:26:43 PM1/13/11
to gong-wpf-dragdrop
Great looking control, look to be the perfect solution to what I am
trying to do. I have had some difficulty setting it up though.

I would like to drag and drop inside the same list box to reorder
items. The itemssource is set to my viewmodels source, but I am using
a datatemplate to display the item inside the listbox.

When I try to drap the item, I get the disable icon for the cursor,
and effectively cannot do it. Any help with this situation? Here is
some of my xaml:

<ListBox dd:DragDrop.DropHandler="{Binding}"
dd:DragDrop.DragHandler="{Binding}" dd:DragDrop.IsDragSource="True"
dd:DragDrop.IsDropTarget="True"
DataContext="{Binding Path=MessageData}"
HorizontalAlignment="Stretch" MinWidth="300" Name="listBox1"
VerticalAlignment="Stretch"
ItemsSource="{Binding Path=WordData}">
<ListBox.ItemTemplate>
<DataTemplate DataType="{x:Type local:IWordData}">
<controls:PgWord
dd:DragDrop.IsDropTarget="True"/>
</DataTemplate>
</ListBox.ItemTemplate>


void IDragSource.StartDrag(DragInfo dragInfo)
{
dragInfo.Effects = System.Windows.DragDropEffects.Copy |
System.Windows.DragDropEffects.Move;
dragInfo.Data = dragInfo.SourceItem as WordData;

}
void IDropTarget.DragOver(DropInfo dropInfo)
{
IWordData data = dropInfo.Data as IWordData;

dropInfo.DropTargetAdorner = DropTargetAdorners.Highlight;
dropInfo.Effects = System.Windows.DragDropEffects.Copy;
}

void IDropTarget.Drop(DropInfo dropInfo)
{

}

Drag start gets called, but as I said, I get the disable icon and
cannot drag or drop. Any help would be much appreciated!

Thanks again

charles

unread,
Jan 14, 2011, 9:29:32 AM1/14/11
to gong-wpf-dragdrop
Fixed this, i didnt show this in the code up top, but I had and
<ItemsControl.Template> with a scrollviewer inside of it for the
listbox's itemscontrol template. Apparently this broke the gong
dragdrop. Anyways, I just wrapped my listbox in the scrollviewer and
everything seems to be working. If you need the complete code, let me
know! Thanks again
Reply all
Reply to author
Forward
0 new messages