Implmenting dragdrop on Datagrid Column Header

Sep 23, 2009 at 5:45 PM

Hi,

I was attemting to use your software to implement drag drop on a datagrid column header. When I add the DropTarget and DragSource within a HeaderTemplate, it does not work.

		<data:DataGridTemplateColumn.HeaderStyle>
                            <Style TargetType="datap:DataGridColumnHeader">
                                <Setter Property="ContentTemplate">
                                    <Setter.Value>
                                        <DataTemplate>
                                                <dragdrop:DropTarget ShowHover="False">
                                                    <dragdrop:DropTarget.Content>
                                                        <dragdrop:DragSource AllDropTargetsValid="True"
                                                             ShowReturnToOriginalPositionAnimation="False"
                                                             DropMode="ReturnDragSource" DragHandleMode="FullDragSource"
                                                             Tag="Name">
                                                                <TextBlock VerticalAlignment="Top"
                                                                   TextAlignment="Center"
                                                                   Text="Name"
                                                                   TextWrapping="NoWrap" />
                                                         </dragdrop:DragSource>
                                                    </dragdrop:DropTarget.Content>
                                                    <dragdrop:DropTarget.Ghost>
                                                        <TextBlock VerticalAlignment="Top"
                                                       TextAlignment="Center"
                                                       Text="Name"
                                                       TextWrapping="NoWrap" />
                                                    </dragdrop:DropTarget.Ghost>
                                                </dragdrop:DropTarget>
                                        </DataTemplate>
                                    </Setter.Value>
                                </Setter>
                            </Style>
                        </data:DataGridTemplateColumn.HeaderStyle>
Is this the right approach ?
Will appreciate help.
Thanks
Vinay
Coordinator
Oct 14, 2009 at 9:18 AM

Hello,

 

this does look like the right way, but tbh, I haven't tested the drag drop manager on grid columns.  Why are you trying to do this?  If you're looking for a way to drag the headers around to change the position in the grid, that's supported out of the box by the SL datagrid.  If you're trying to implement the kind of behaviour where a user can drag an object to a column header, a DropTarget should be enough - you can then handle the DragSourceDropped-event on the DropTarget in the column header.

For your information, this post: http://pendsevikram.blogspot.com/2009/09/silverlight-3-datagrid-beyond.html explains a lot of the things you can do with the DataGrid :-)  Hope this helps!

 

Regards,

Kevin.