Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
380
DragSource and Scrolling in XamGrid
posted

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>
Parents
  • 8831
    posted

    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.

     

     

     

Reply Children