Hello,
I am using the DragDropManager in the XamGrid in your newest Silverlight controls. I have the DragSource and DropTargets working like I want with one exception.
My problem is that when I move the scroll bar in the grid, the DragStart event fires and causes the drag visual over the scroll thumb. How can I stop this from happenning?
Also, before I added the custom drag source template (from which I populate in the DragStart event), the drag visual was the entire XamGrid rather than just the selected rows...maybe these are related.
My code is below,
Thanks!
-Mark
<ig:XamGrid x:Name="_endPoints" ItemsSource="{Binding EndPoints}" AutoGenerateColumns="False"> <ig:DragDropManager.DragSource> <ig:DragSource IsDraggable="True" DragChannels="EndPoint" DragStart="DragSource_DragStart" DragEnd="DragSource_DragEnd" Drop="DragSource_Drop"> <ig:DragSource.DragTemplate> <DataTemplate x:Name="dragTemplate"> <ListBox Visibility="Visible" x:Name="dtStackPanel" ItemsSource="{Binding Path=Data}" Opacity=".5"> <ListBox.ItemTemplate> <DataTemplate> <StackPanel Orientation="Horizontal" Background="{StaticResource GreenGradientBrush}" Margin="-5"> <TextBlock Width="150" FontSize="11" Style="{StaticResource NormalText}" Margin="5" Text="{Binding Name}" /> <TextBlock Width="100" FontSize="11" Style="{StaticResource NormalText}" Margin="5" Text="{Binding IpAddress}"/> </StackPanel> </DataTemplate> </ListBox.ItemTemplate> </ListBox> </DataTemplate> </ig:DragSource.DragTemplate> </ig:DragSource> </ig:DragDropManager.DragSource> <ig:XamGrid.Columns> <ig:TextColumn Key="Name"/> <ig:TextColumn Key="Status"/> <ig:TextColumn Key="OperatingSystem"/> <ig:TextColumn Key="IpAddress"/>
</ig:XamGrid.Columns> </ig:XamGrid>
</ig:XamGrid.Columns>
Hi Mark,
In order to avoid this I suggest you to re-style the XamGrid and attach the drag source to rows panel – it is a part of XamGrid control template:
…
<igPrim:RowsPanel x:Name="RowsPanel"/>
So it goes:
<igPrim:RowsPanel x:Name="RowsPanel">
<ig:DragDropManager.DragSource>
<ig:DragSource IsDraggable="True"
DragStart="DragSource_DragStart">
</ig:DragSource>
</ig:DragDropManager.DragSource>
</igPrim:RowsPanel>
You need to set this style inline in order to be able to use the event handlers of DragSource.
Another approach is within DragStart event handler to examine the visual tree of the original drag source and cancel the operation if needed:
private void DragSource_DragStart(object sender, DragDropStartEventArgs e)
{
DependencyObject visualParent = e.OriginalDragSource;
while (visualParent != null)
ScrollBar scrollBar = visualParent as ScrollBar;
if (scrollBar != null)
e.Cancel = true;
return;
}
visualParent = VisualTreeHelper.GetParent(visualParent);
Best regards.
Plamen.
Plamen, Thanks for your reply.
Option 1 is not really viable for me, since we have many many views with a XamGrid supporting drag and drop. I cannot have that XamGrid control template repeated in so many places in order to get at the rows panel and attach my event handlers. Additionally it caused style issues with simple mouse overs selecting rows.
Option 2 sort of works, at least I can return from the routine that populates my drag template listbox for my custom visual. But when I include e.Cancel, it cancels the scroll event rendering it useless. I'm still suck with the default no drop allowed cursor when I scroll in any grid with DrabSource enabled.
It seems triggering drag start on scrolling in the grid would never be desired . Do you know of any other solution?
Thanks for your assistance, -Mark