Problem Dragging from RadTreeView to image/ItemsControls

2 posts, 0 answers
  1. Shayne
    Shayne avatar
    5 posts
    Member since:
    May 2012

    Posted 31 Jul 2012 Link to this post

    Hello,

    In the scenario that we have, we need to drag items from a TreeView onto an image.  The image is a map and has a couple of collections items added to display on top of the map.  I am using the RadDragAndDropManager to drop items onto the map.

    Here is the XAML for defining the target:

    ....
    <Grid x:Name="mapGrid"
                      Visibility="{Binding Text, ElementName=mapFilenameTextBox, Converter={StaticResource StringEmptyToVisibilityConverter}}"
                      HorizontalAlignment="Center" VerticalAlignment="Center"
                      Margin="2">
                    <Image x:Name="mapImage"
                           Source="{Binding MapFilename, Mode=OneWay}"
                           Stretch="Uniform" StretchDirection="Both" SizeChanged="mapImage_SizeChanged" Loaded="mapImage_Loaded"/>


                    <ItemsControl x:Name="mapSymbolLabelsItemsControl"
                                  ItemsSource="{Binding MapSymbolLabels}">
                        <ItemsControl.ItemsPanel>
                            <ItemsPanelTemplate>
                                <Canvas>
                                    <Canvas.Background>
                                        <SolidColorBrush Opacity="0"/>
                                    </Canvas.Background>
                                </Canvas>
                            </ItemsPanelTemplate>
                        </ItemsControl.ItemsPanel>
                        <ItemsControl.ItemContainerStyle>
                            <Style>
                                <Setter Property="Canvas.Top" Value="{Binding RelativeSource={x:Static RelativeSource.Self}, Path=Top}" />
                                <Setter Property="Canvas.Left" Value="{Binding RelativeSource={x:Static RelativeSource.Self}, Path=Left}" />
                                <Setter Property="Label.ToolTip" Value="{Binding RelativeSource={x:Static RelativeSource.Self}, Path=LabelName}" />
                            </Style>
                        </ItemsControl.ItemContainerStyle>
                    </ItemsControl>


                    <ItemsControl x:Name="mapAreaItemsControl"
                                  AllowDrop="True"
                                  Drop="mapAreaItemsControl_Drop"
                                  MouseLeftButtonDown="mapAreaItemsControl_MouseButtonDown"
                                  MouseRightButtonDown="mapAreaItemsControl_MouseButtonDown"
                                  MouseMove="mapAreaItemsControl_MouseMove"
                                  GiveFeedback="mapAreaItemsControl_GiveFeedback"
                                  ItemsSource="{Binding MapSymbols}">
                        <ItemsControl.ItemsPanel>
                            <ItemsPanelTemplate>
                                <Canvas x:Name="mapCanvas">
                                    <Canvas.Background>
                                        <SolidColorBrush Opacity="0"/>
                                    </Canvas.Background>
                                </Canvas>
                            </ItemsPanelTemplate>
                        </ItemsControl.ItemsPanel>
                        <ItemsControl.ItemContainerStyle>
                            <Style>
                                <Setter Property="Canvas.Top" Value="{Binding RelativeSource={x:Static RelativeSource.Self}, Path=Top}" />
                                <Setter Property="Canvas.Left" Value="{Binding RelativeSource={x:Static RelativeSource.Self}, Path=Left}" />
                                <Setter Property="Image.ToolTip" Value="{Binding RelativeSource={x:Static RelativeSource.Self}, Path=SymbolName}" />
                            </Style>
                        </ItemsControl.ItemContainerStyle>
                        <ItemsControl.ContextMenu>
                            <ContextMenu>
                                <MenuItem Header="{l:Translate DeleteContextMenuItem}" Command="{Binding DeleteSelectedMapSymbolsCommand}"/>
                            </ContextMenu>
                        </ItemsControl.ContextMenu>
                    </ItemsControl>
                </Grid>
    ...

    In the Constructor of the view, I set up the DragAndDropEvents:
    RadDragAndDropManager.SetAllowDrop(mapAreaItemsControl , true);
    RadDragAndDropManager.AddDropQueryHandler(mapAreaItemsControl, new EventHandler<DragDropQueryEventArgs>( OnDropQuery ) );
    RadDragAndDropManager.AddDropInfoHandler(mapAreaItemsControl, new EventHandler<DragDropEventArgs>( OnDropInfo ) );

    What I am seeing with this is that OnDropQuery fires once and I set the query result to true to enable the drop.
    private void OnDropQuery( object sender, DragDropQueryEventArgs e )
    {    
        e.QueryResult = true;
        e.Handled = true;
    }

    I expect that the drag status should be allowed at this point, but its being set to DropImpossible.

    I did notice that the OnDropInfo event is being fired twice - the first time, the drag status is DropPossible, but the second time, the drag status is DropImpossible.  The sender both times is the items control and this happens weather the items control is empty or not.  I have tried several combinations of allowing drop to the containing grid, the image, the item control and all of them, but the result is the same.  

    Here is the call stack when drop status is DropPossible:
    > XXXXXXXXX.OnDropInfo(object sender, Telerik.Windows.Controls.DragDrop.DragDropEventArgs e) Line 57 C#
      Telerik.Windows.Controls.dll!Telerik.Windows.Controls.DragDrop.DragDropEventArgs.InvokeEventHandler(System.Delegate genericHandler, object genericTarget) Line 46 C#
      [External Code]
      Telerik.Windows.Controls.dll!Telerik.Windows.Controls.DragDrop.RadDragAndDropManager.DragDropProvider_DropInfo(object sender, Telerik.Windows.Controls.DragDrop.DragDropEventArgs e) Line 311 C#
      Telerik.Windows.Controls.dll!Telerik.Windows.Controls.DragDrop.DragDropProviderBase.RaiseDropInfo() Line 215 C#
      Telerik.Windows.Controls.dll!Telerik.Windows.Controls.DragDrop.DragDropProvider.OnElementDragOver(object sender, Telerik.Windows.DragDrop.DragEventArgs e) Line 247 C#
      Telerik.Windows.Controls.dll!Telerik.Windows.DragDrop.DragEventArgs.InvokeEventHandler(System.Delegate genericHandler, object genericTarget) Line 182 C#
      [External Code]
      Telerik.Windows.Controls.dll!Telerik.Windows.DragDrop.IInputElementExtensions.RaiseEvent(System.Windows.DependencyObject d, System.Windows.RoutedEventArgs routedEventArgs) Line 83 C#
      Telerik.Windows.Controls.dll!Telerik.Windows.DragDrop.DragDropManager.DelegateHelper.OnDragEventHandler(object sender, System.Windows.DragEventArgs e) Line 1731 C#
      Telerik.Windows.Controls.dll!Telerik.Windows.DragDrop.DragDropManager.DelegateHelper.OnOver(object sender, System.Windows.DragEventArgs e) Line 1807 C#
      [External Code]
      Telerik.Windows.Controls.dll!Telerik.Windows.DragDrop.DragDropManager.DoDragDrop(System.Windows.DependencyObject dragSource, object data, System.Windows.DragDropEffects allowedEffects, System.Windows.DragDropKeyStates initialKeyState, object dragVisual, System.Windows.Point relativeStartPoint, System.Windows.Point dragVisualOffset) Line 1018 + 0xe bytes C#
      Telerik.Windows.Controls.dll!Telerik.Windows.DragDrop.DragInitializer.StartDrag() Line 238 C#
      Telerik.Windows.Controls.dll!Telerik.Windows.DragDrop.DragInitializer.StartDragPrivate(System.Windows.UIElement sender) Line 191 C#
      Telerik.Windows.Controls.dll!Telerik.Windows.DragDrop.DragInitializer.DragSourceOnMouseMove(object sender, System.Windows.Input.MouseEventArgs e) Line 163 + 0x1e bytes C#
      [External Code]



    Here is the call stack when drop status is DropImpossible:
    > XXXXXXX.OnDropInfo(object sender, Telerik.Windows.Controls.DragDrop.DragDropEventArgs e) Line 56 C#
      Telerik.Windows.Controls.dll!Telerik.Windows.Controls.DragDrop.DragDropEventArgs.InvokeEventHandler(System.Delegate genericHandler, object genericTarget) Line 46 C#
      [External Code]
      Telerik.Windows.Controls.dll!Telerik.Windows.Controls.DragDrop.RadDragAndDropManager.DragDropProvider_DropInfo(object sender, Telerik.Windows.Controls.DragDrop.DragDropEventArgs e) Line 311 C#
      Telerik.Windows.Controls.dll!Telerik.Windows.Controls.DragDrop.DragDropProviderBase.RaiseDropInfo() Line 215 C#
      Telerik.Windows.Controls.dll!Telerik.Windows.Controls.DragDrop.DragDropProviderBase.NotifyPreviousApprovedDestination() Line 372 C#
      Telerik.Windows.Controls.dll!Telerik.Windows.Controls.DragDrop.DragDropProviderBase.OnDropImpossible() Line 403 + 0xb bytes C#
      Telerik.Windows.Controls.dll!Telerik.Windows.Controls.DragDrop.DragDropProvider.OnElementDragLeave(object sender, Telerik.Windows.DragDrop.DragEventArgs args) Line 295 C#
      Telerik.Windows.Controls.dll!Telerik.Windows.DragDrop.DragEventArgs.InvokeEventHandler(System.Delegate genericHandler, object genericTarget) Line 182 C#
      [External Code]
      Telerik.Windows.Controls.dll!Telerik.Windows.DragDrop.IInputElementExtensions.RaiseEvent(System.Windows.DependencyObject d, System.Windows.RoutedEventArgs routedEventArgs) Line 83 C#
      Telerik.Windows.Controls.dll!Telerik.Windows.DragDrop.DragDropManager.DelegateHelper.OnDragEventHandler(object sender, System.Windows.DragEventArgs e) Line 1731 C#
      Telerik.Windows.Controls.dll!Telerik.Windows.DragDrop.DragDropManager.DelegateHelper.OnLeave(object sender, System.Windows.DragEventArgs e) Line 1797 C#
      [External Code]
      Telerik.Windows.Controls.dll!Telerik.Windows.DragDrop.DragDropManager.DoDragDrop(System.Windows.DependencyObject dragSource, object data, System.Windows.DragDropEffects allowedEffects, System.Windows.DragDropKeyStates initialKeyState, object dragVisual, System.Windows.Point relativeStartPoint, System.Windows.Point dragVisualOffset) Line 1018 + 0xe bytes C#
      Telerik.Windows.Controls.dll!Telerik.Windows.DragDrop.DragInitializer.StartDrag() Line 238 C#
      Telerik.Windows.Controls.dll!Telerik.Windows.DragDrop.DragInitializer.StartDragPrivate(System.Windows.UIElement sender) Line 191 C#
      Telerik.Windows.Controls.dll!Telerik.Windows.DragDrop.DragInitializer.DragSourceOnMouseMove(object sender, System.Windows.Input.MouseEventArgs e) Line 163 + 0x1e bytes C#
      [External Code]


    As noted, Ive tried several combinations of allowing and handling the drag drop events for all of the elements in the view, I cannot get the result to remain DragPossible so that I can actually perform the drop.


  2. Petar Mladenov
    Admin
    Petar Mladenov avatar
    2891 posts

    Posted 03 Aug 2012 Link to this post

    Hello Shayne,

     The RadDragAndDropManager has some known bugs and limitations and that is why in 2011 we created a new DragDropManager providing more friendly API. We highly encourage you to use the DragDropManager, you can start with its documentation articles and examples.

    Greetings,
    Petar Mladenov
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  3. UI for WPF is Visual Studio 2017 Ready
Back to Top