Drag Drop Sample with WPF

5 posts, 1 answers
  1. Robert
    Robert  avatar
    68 posts
    Member since:
    Feb 2009

    Posted 06 Jan 2012 Link to this post

    I'm working with the getting started article to demonstrate a basic implementation of the DragDropManager by dragging between two ListBoxes - http://www.telerik.com/help/wpf/dragdropmanager-getting-started.html ;

    The following code produces an ArgumentException error - The value "System.Windows.DataObject" is not of type "ManageDragDrop.ApplicationInfo" and cannot be used in this generic collection.

    private void OnDrop(object sender, Telerik.Windows.DragDrop.DragEventArgs args)
            {
                ((IList)(sender as ListBox).ItemsSource).Add(args.Data);
            }


  2. Answer
    Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 09 Jan 2012 Link to this post

    Hi Robert,

     Indeed you are right. 
    You will need to change the OnDragInitialize and the OnDrop events like so:

    private void OnDragInitialize(object sender, DragInitializeEventArgs args)
    {
        args.AllowedEffects = DragDropEffects.All;
        args.Data = ((FrameworkElement)args.OriginalSource).DataContext;
        args.DragVisual = new ContentControl { Content = args.Data, ContentTemplate = LayoutRoot.Resources["ApplicationTemplate"] as DataTemplate };
    }
     
    private void OnDrop(object sender, Telerik.Windows.DragDrop.DragEventArgs args)
    {
        ((IList)(sender as ListBox).ItemsSource).Add(((DataObject)args.Data).GetData(typeof(ApplicationInfo)));
    }

    Thank you for this remark. The help article will be updated and uploaded to live until the end of the week.

    Regards,
    Didie
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

  3. UI for WPF is Visual Studio 2017 Ready
  4. Ahmet
    Ahmet avatar
    12 posts
    Member since:
    Jan 2012

    Posted 18 Jan 2012 Link to this post

    I know this is a fairly simple example, and I have followed the demo, but still cannot get it working.

    Can someone please, please, please post a working solution of this example? (in VB, if possible)

    Thanks.
  5. James
    James avatar
    1 posts
    Member since:
    Mar 2012

    Posted 08 Aug 2013 Link to this post

    I have the same problem. The VB.Net code for the getting started article is all jacked up. I was able to fix the typos but still can't get the demo to run. When I try to drag from the list nothing happens and OnDragInitialized never fires. I assume I'm missing some key piece of information. 
  6. Nick
    Admin
    Nick avatar
    593 posts

    Posted 09 Aug 2013 Link to this post

    Hi James,

    You need to do a couple of things to ensure the firing of the events. The draggable element, in that case, the ListBoxItem, has to have the DragDropManager.AllowDrag/AllowCapturedDrag property set to true. 
    If anything else is handling the DragInitialize event, such as a DragDropBehavior, you need to subscribe to it with HandledEventsToo set to true.

    Let me know if this helps! 

    Regards,
    Nik
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
Back to Top
UI for WPF is Visual Studio 2017 Ready